playlist: [{
"sources": [{"type": "video/mp4", "label": "SD", "file": "src.mp4"}]
}],
如何使用js变量来分配视频文件src,如
playlist: [{
"sources": [{"type": "video/mp4", "label": "SD", "file": myvariable }]
}],
答案 0 :(得分:3)
file
的值是表示文件位置的字符串。它通常是绝对的网址。由于某种原因,该演示在SO上不起作用,但它起PLUNKER
注意:我使用了ES6 Template Literal而不是通常的String Literal。如果您打算迎合IE用户,您必须使用String Literal
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="http://p.jwpcdn.com/6/12/jwplayer.js"></script>
</head>
<body>
<div id="x">...</div>
<script>
var file = '023642.mp4';
var jwp = jwplayer('x');
jwp.setup({
playlist: [{
file: `http://media6000.dropshots.com/photos/1381926/20170326/${file}`
}],
width: 320,
height: 180
});
</script>
</body>
</html>
&#13;
✎与OP无关,但就此Stack的功能而言,请参阅@TinyGiant detailed answer