更改JWPlayer视频onClick

时间:2013-06-10 13:16:41

标签: javascript onclick jwplayer

这是我到目前为止的情况。如果我在函数中对file: media/video2.mp4进行硬编码,但是当我将它变成一个变量时,它没有正确地传递它,因为我一直得到这个错误:

Error loading player: No playable sources found

代码

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>My JWPlayer</title>
    <script type="text/javascript" src="jwplayer/jwplayer.js" ></script>

    <script type="text/javascript">
     function changeVideo(filename) {
     jwplayer("video").setup({
       file: " + filename + ",
        height: 360,
        width: 640,
    });
    jwplayer('video').load();
}
     </script>
    </head>

    <body>
    <div id="video">Loading the player ...</div>

    <script type="text/javascript">
        jwplayer("video").setup({
            file: "media/video1.mp4",
            height: 360,
            width: 640
        });
    </script>

    <p><a href="javascript:void();" onclick="javascript:changeVideo('media/video2.mp4');">Play Video 2</a></p>
    </body>
    </html>

1 个答案:

答案 0 :(得分:3)

这是因为您将变量filename作为字符串文字放在脚本中。

只需更改此行

file: " + filename + ",

file: filename,

它会正常工作!