更改JWPlayer视频onClick [英] Changing JWPlayer video onClick
本文介绍了更改JWPlayer视频onClick的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我到目前为止的内容.如果我在函数中硬编码file: media/video2.mp4
,它可以工作,但是当我将其设置为变量时,由于我不断收到此错误,因此无法正确传递它:
This is what I have so far below. If I hard code the file: media/video2.mp4
in the function it works but when I make it a variable its not passing it through correctly because I keep get this error:
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>
推荐答案
这是因为您要在脚本中将变量文件名作为字符串文字放置.
It is because you are placing variable filename in the script as a string literal.
只需更改此行
file: " + filename + ",
到
file: filename,
它将正常工作!
这篇关于更改JWPlayer视频onClick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文