2

这就是我到目前为止所拥有的。如果我在函数中对它进行硬编码,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>
4

1 回答 1

3

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

只需更改此行

file: " + filename + ",

file: filename,

它会正常工作!

于 2013-06-10T13:47:23.293 回答