您如何获取 videojs-markers 插件上的现有标记列表?
How do you get the list of existing markers on the videojs-markers plugin?
我觉得这是一个愚蠢的问题,所以我深表歉意,但我对 JavaScript 的总体经验很少。
我有一个允许用户注释(标记)视频的应用程序,所以我使用 https://github.com/spchuang/videojs-markers 作为 videojs 的插件,它看起来正是我需要的。
但是在允许用户添加标记之后,我想将它们记录在我的数据库中,所以我需要能够获得原始标记结构(即每个标记的时间和文本)。
下面的代码显示了我所拥有的。我遇到问题的是 recordMarks
函数。那就是我想要获得标记的地方,以便我通过 Ajax
在我的数据库中 post 它们
//load the marker plugin
myPlayer.markers({
...
markers: [
]
});
function markTime() {
currentTime = getTime('Mark');
myPlayer.markers.add([{
time: currentTime,
text: currentTime,
overlayText: 'Tag',
class: 'special-blue'
}]);
console.log('marked: ' + currentTime)
}
function recordMarks() {
console.log(myPlayer.markers.markers); // shows as Undefined
// Try another way
for(var i =0; i < myPlayer.markers.length; i++){
console.log('mark ' + i + ' is ' + myPlayer.markers[i].text);
}
}
鉴于缺乏解决方案,我最终声明了一个全局标记数组,这样每次添加标记时,我都会将其添加到全局数组和播放器中。
我觉得这是一个愚蠢的问题,所以我深表歉意,但我对 JavaScript 的总体经验很少。
我有一个允许用户注释(标记)视频的应用程序,所以我使用 https://github.com/spchuang/videojs-markers 作为 videojs 的插件,它看起来正是我需要的。
但是在允许用户添加标记之后,我想将它们记录在我的数据库中,所以我需要能够获得原始标记结构(即每个标记的时间和文本)。
下面的代码显示了我所拥有的。我遇到问题的是 recordMarks
函数。那就是我想要获得标记的地方,以便我通过 Ajax
//load the marker plugin
myPlayer.markers({
...
markers: [
]
});
function markTime() {
currentTime = getTime('Mark');
myPlayer.markers.add([{
time: currentTime,
text: currentTime,
overlayText: 'Tag',
class: 'special-blue'
}]);
console.log('marked: ' + currentTime)
}
function recordMarks() {
console.log(myPlayer.markers.markers); // shows as Undefined
// Try another way
for(var i =0; i < myPlayer.markers.length; i++){
console.log('mark ' + i + ' is ' + myPlayer.markers[i].text);
}
}
鉴于缺乏解决方案,我最终声明了一个全局标记数组,这样每次添加标记时,我都会将其添加到全局数组和播放器中。