带有视频时间的链接按钮

Link button with video time

本文关键字:链接 按钮 时间 视频      更新时间:2023-09-26

我试图只在用户在视频的特定时间到达时显示按钮,类似的按钮只有在用户观看了20分钟的视频时才会出现。对此一无所知,非常感谢您的投入。感谢

如果视频是通过html5(一个视频标签)播放的,而不是嵌入的,那么下面的代码是你可以采取的一种方法。

// the video element
var video = document.getElementsByTagName('video')[0];
// add an event listener for 'timeupdate' 
video.addEventListener('timeupdate', function() {
    // 20 mins in seconds
    if ( this.currentTime == 1200) {
    // code to add the button here...
    }
}, false);

你真的应该看看html5音频/视频api

不确定您是否想知道如何显示按钮或如何检查视频剪辑的当前时间。

我希望是前者。要检查视频播放时间,您可以使用javascript调用视频的currentTime属性,例如:

// set your video element to a variable
var video = document.getElementById("my-video");
// get the current playback time of the video (returned in seconds) and set to variable
current_playback_time = video.currentTime;