<!DOCTYPE html><htmllang="en"><head><metacharset="UTF-8"><metaname="viewport"content="width=device-width, initial-scale=1.0"><title>VideoTexture Example</title></head><body><videoid="myVideo"width="320"height="240"controlsautoplayloop><sourcesrc="your-video-file.mp4"type="video/mp4">
Your browser does not support the video tag.
</video><script>const video = document.getElementById('myVideo');
// 设置视频不循环播放
video.loop = false;
// 监听视频播放结束事件
video.addEventListener('ended', function() {
console.log('Video playback has ended.');
// 在这里可以执行你想要的逻辑,比如暂停视频(虽然视频播放结束后通常会自动暂停)
video.pause();
});
// 监听视频暂停事件
video.addEventListener('pause', function() {
console.log('Video playback has been paused.');
// 在这里可以执行你想要的逻辑
});
</script></body></html>
已解决,在文档中找到了方法
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>VideoTexture Example</title> </head> <body> <video id="myVideo" width="320" height="240" controls autoplay loop> <source src="your-video-file.mp4" type="video/mp4"> Your browser does not support the video tag. </video> <script> const video = document.getElementById('myVideo'); // 设置视频不循环播放 video.loop = false; // 监听视频播放结束事件 video.addEventListener('ended', function() { console.log('Video playback has ended.'); // 在这里可以执行你想要的逻辑,比如暂停视频(虽然视频播放结束后通常会自动暂停) video.pause(); }); // 监听视频暂停事件 video.addEventListener('pause', function() { console.log('Video playback has been paused.'); // 在这里可以执行你想要的逻辑 }); </script> </body> </html>