javascript jwplayer 6:如何使用javascript api 动态加载文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13999712/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 20:27:12  来源:igfitidea点击:

jwplayer 6: how to dynamically load file, using javascript api?

javascriptjwplayer

提问by moondog

I am trying to migrate from jw5 to jw6.

我正在尝试从 jw5 迁移到 jw6。

In jw5, I was able to dynamically load a video:

在 jw5 中,我能够动态加载视频:

myplayer.load({file: 'myfile.mov', image: 'mysplash.jpg'});

This does not work in jw6. I have spent a lot of time looking through the online documentation, and have not found any references to .load. I am beginning to fear this is no longer supported. The document 'migrating from jw5 to jw6' has this cryptic comment:

这在 jw6 中不起作用。我花了很多时间浏览在线文档,但没有找到任何对.load. 我开始担心这不再受支持。文档“从 jw5 迁移到 jw6”有以下隐晦的评论:

The jwplayer().setup() call is now the only valid method to embed media

jwplayer().setup() 调用现在是嵌入媒体的唯一有效方法

Does this mean it is no longer possible to dynamically load the player with a new file, for example in response to a click event, using the javascript api? Must all files be specified in a playlist, during the initial player setup?

这是否意味着不再可能使用 javascript api 使用新文件动态加载播放器,例如响应点击事件?在初始播放器设置期间,是否必须在播放列表中指定所有文件?

Thank you.

谢谢你。

回答by Igor

I got this problem too and I found what is the issue.

我也遇到了这个问题,我找到了问题所在。

Instead of JWP5, JWP6 does not work with the load()function if no media is specified upon setup.

load()如果在设置时未指定媒体,JWP6 将不使用该功能,而不是 JWP5 。

If I used this code:

如果我使用此代码:

jwplayer("container").setup({
    width: 640,
    height: 480
});

after that, the load()function is not working.

之后,该load()功能不起作用。

The workaround is to specify initial some existing dummy media file:

解决方法是指定初始一些现有的虚拟媒体文件:

jwplayer("container").setup({
    width: 640,
    height: 480,
    file: '/some/summy/file.mp4'
});

after that JavaScript function load()can load new media.

之后 JavaScript 函数load()可以加载新媒体。

This is the BUG !!!

这是BUG!!!

回答by emaxsaun

You should still be able to use the load() call in JW6. http://www.longtailvideo.com/support/jw-player/28851/javascript-api-reference

您应该仍然可以在 JW6 中使用 load() 调用。http://www.longtailvideo.com/support/jw-player/28851/javascript-api-reference

load(playlist) Loads a new playlist into the player. The playlist parameter is required and can be either an array with playlist items or a string that points to the location of an RSS feed.

load(playlist) 将新的播放列表加载到播放器中。playlist 参数是必需的,可以是包含播放列表项的数组,也可以是指向 RSS 提要位置的字符串。

If you are having issues getting load() to work in JW6, please provide an example for debugging, thanks.

如果您在 JW6 中使用 load() 时遇到问题,请提供调试示例,谢谢。

回答by Andrew Riznyk

This is an old post however i would like to give an example of what i would do (JWplayer6)

这是一篇旧帖子,但我想举例说明我会做什么(JWplayer6)

var playerInstance = undefined;
button.onclick = function(newData){
    if (playerInstance === undefined){
        playerInstance = jwplayer("myElement");
        playerInstance.setup({
            width: 640,
            height: 480,
            file: newData
        });
    } else {
        playerInstance.load(newData);
    }
};

Dummy content loads the player with data the user may not want, and the bonus of pre-loading the player on the page offers only a slight advantage to loading on a request. (waiting for the player js to execute)

虚拟内容将用户可能不想要的数据加载到播放器中,并且在页面上预加载播放器的好处仅比按请求加载略有优势。(等待播放器js执行)