我有一个html模板,在发布时会列出该故事的变量,如果为故事制作了字幕,其中一个是隐藏式字幕文件:
var file_cc = "../xml/cc/example.vtt";
在外部js文件中我设置了我的播放器(其他可选内容来自故事页面):
jwplayer("vplayer").setup({
icons: false,
sources: [
{file: origurl},
{file: origurlsd}
],
image: origimg,
width: "70%",
aspectratio: "16:9",
abouttext: "...",
aboutlink: "...",
skin: "/res/libraries/jwplayer/skins/target-v6-11/glow.xml"
});
在那个外部js中我然后使用.get()
检测file_cc var是否存在$.get(file_cc, function() {
console.log("found file")
})
但是现在,在the .get() function的.done()和fail()部分中,我想要使用tracks:
数组更新jwplayer("vplayer)
。
我该怎么做?
答案 0 :(得分:3)
不知道您正在使用的完整代码,因此我会采取有根据的猜测:
var jw = jwplayer("vplayer");
jw.setup({
icons: false,
sources: [
{file: origurl},
{file: origurlsd}
],
tracks: [{
file: "cc_file",
kind: "captions",
'default': true,
label: 'English'
}],
image: origimg,
width: "70%",
aspectratio: "16:9",
abouttext: "...",
aboutlink: "...",
skin: "/res/libraries/jwplayer/skins/target-v6-11/glow.xml"
});
$.get(file_cc, function() {
console.log("found file");
var ccList = jw.getCaptionsList();
var ccList[1] = file_cc;
ccList.setCurrentCaptions(1);
jw.on('complete', done);
jw.on('error', fail);
function done() {...}
function fail() {...}
});
要更加了解这种混乱,请参阅:http://support.jwplayer.com/customer/en/portal/articles/1413089-javascript-api-reference#captions
<强>更新强>
由于字幕列表完全取决于JW Player的单一设置(如Ethan所述),也许您可以通过JW Player的事件调用$ .get()。
var jw = jwplayer("vplayer");
jw.setup({
icons: false,
sources: [
{file: origurl},
{file: origurlsd}
],
tracks: [{
file: "cc_file",
kind: "captions",
'default': true,
label: 'English'
}],
image: origimg,
width: "70%",
aspectratio: "16:9",
abouttext: "...",
aboutlink: "...",
skin: "/res/libraries/jwplayer/skins/target-v6-11/glow.xml"
});
jw.on('captionsList', function(event){
$.get('cc_file', function() {...}
});
jw.on('captionsChanged', function(event){...});