【问题标题】:jwplayer append file to playlistjwplayer 将文件附加到播放列表
【发布时间】:2023-03-07 03:21:01
【问题描述】:

查看 jwplayer 的文档,我找不到任何关于如何将文件附加到现有播放列表的参考。

该规范是为了让用户能够在浏览网站时将媒体文件添加到播放列表中而不会中断当前文件的播放

player.getPlaylist().push({file:'test.mp3', 'title':"test"}) 不起作用(不希望它真的根据方法的名称起作用),唯一的方法似乎是按照此处所述重新加载播放列表:How to load playlist without restart the current playing video

但感觉不对,可能会阻止无缝媒体添加。

另一种选择是编写一些自定义播放列表逻辑,但我宁愿避免这种情况并使用 jwplayers 自己的播放列表控件

有没有人有更好的方法来做到这一点? 感谢您的帮助!

【问题讨论】:

  • 使用当前的jwplayer api(6xx版)似乎没有简单的方法(除了编写一些自定义逻辑)

标签: jwplayer playlists


【解决方案1】:

下面是一些示例代码,可以执行以下操作:

<!DOCTYPE html>
<html>
<head>
<title>Add to Playlist</title>
<script type="text/javascript" src="http://www.longtailvideo.com/jwplayer/jwplayer.js"></script>
</head>
<body>
<div id="container"></div>
<script type="text/javascript">
    jwplayer("container").setup({
        height: 254,
        width: 720,
        file: "http://content.bitsontherun.com/videos/nPripu9l-60830.mp4",
        image: "http://content.bitsontherun.com/thumbs/nPripu9l-320.jpg",
        title: "Big Buck Bunny trailer",
        listbar: {
        position: "right",
        size: 280,
        },
        primary: 'flash'
    }); 
    function addVideo(videoUrl, videoThumb, videoTitle) {
        var playlist = jwplayer().getPlaylist();
        var newItem = {
            file: videoUrl,
            image: videoThumb,
            title: videoTitle
        };
        playlist.push(newItem);
        jwplayer().load(playlist);
    }
</script>
<p>Click on one of the links below to add an item to the player:</p>
<ul>
<li><a href="http://www.longtailvideo.com/support/jw-player/jw-player-for-flash-v5/16026/loading-a-playlist-into-the-player#" onclick="addVideo('http://content.bitsontherun.com/videos/yj1shGJB-60830.mp4', 'http://content.bitsontherun.com/thumbs/yj1shGJB-320.jpg', 'Sintel trailer'); return false;">Add the Sintel trailer to the playlist</a></li>
<li><a href="http://www.longtailvideo.com/support/jw-player/jw-player-for-flash-v5/16026/loading-a-playlist-into-the-player#" onclick="addVideo('http://content.bitsontherun.com/videos/i8oQD9zd-kNspJqnJ.mp4', 'http://content.bitsontherun.com/thumbs/i8oQD9zd-640.jpg', 'Tears of Steel'); return false;">Add the Tears of Steel trailer to the playlist</a></li>
</ul>
</body>
</html>

【讨论】:

  • 嗨,Ethan,感谢您的回答,但这就像我在 SO 上找到的其他解决方案一样
  • 嗯,当它加载新项目到播放列表时,恐怕加载总是会停止播放。
  • 只需使用 jwplayer().getPlaylist().push() 用于在 6.2 版本中工作。您无需致电load()。播放不受影响,它只是在播放结束时播放附加的视频。但是在最近的几个版本中它被破坏了。你能把这个功能加回来吗?
  • 如果我有时间,我会尝试做一个例子。但我很确定它与this issue 有关。我不太清楚来源可以肯定地说,但在那个线程中,JeroenW 提到清理了一堆未记录的方法。由于我从未见过push() 的任何实际文档,因此它可能也被吹走了。这绝对适用于 v6.2。我有使用它的生产代码。我尝试升级,但这两个问题阻止了我。
猜你喜欢
  • 2013-10-25
  • 1970-01-01
  • 1970-01-01
  • 2023-04-09
  • 1970-01-01
  • 2012-02-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多