我有一个带有 JW Player 字幕的 VTT 文件,我正在尝试创建交互式文字记录。为此,我需要将 VTT 文件读入数组,然后与数据进行交互。
以下是 VTT 文件的片段:
1
00:00:00 --> 00:00:05
65 MEP we have twitter handles for both of us on screen as well so if you want
2
00:00:05 --> 00:00:08
to interact with those afterwards that's the best way to do so now been going to
3
00:00:08,051 --> 00:00:12,310
be talking about a topic that's extremely important topic in my mind and
到目前为止,这是我的 Javascript:
$.get('http://dev.sharepoint-videos.com/test.vtt', function(data) {
// Read all captions into an array
var items = data.split('\n\r');
console.log(items);
//Loop through all captions
$.each(items, function( index, value ) {
var item = items[index].split('\n');
console.log(item);
});
});
这是我的 Console.log 返回的内容
0: "1
↵00:00:00 --> 00:00:05
↵65 MEP we have twitter handles for both of us on screen as well so if you want
"
1: "↵2
↵00:00:05 --> 00:00:08
↵to interact with those afterwards that's the best way to do so now been going to
"
2: "↵3
↵00:00:08,051 --> 00:00:12,310
↵be talking about a topic that's extremely important topic in my mind and
"
这不是想要的结果。我对 Javascript 仍然很陌生,我想做的是将每个标题读入数组,然后循环获取开始时间和结束时间以及标题,以便我可以在 JW Player JS API 中使用它们。
最佳答案
这最终对我有用。
$.get('http://dev.sharepoint-videos.com/test.vtt', function(data) {
// Read all captions into an array
var items = data.split('\n\r\n');
console.log(items);
//Loop through all captions
$.each(items, function( index, value ) {
var item = items[index].split('\n');
console.log(item);
});
});
关于javascript - 如何使用 Javascript 将 VTT 文件读入数组和循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32662080/