英文:
video on ended plays again from start instead of stop/pause
问题
<video class='vsingle' id='vsingle' src='ph/video.mp4' poster='ph/vposter.jpg' controls></video>
JavaScript:
$('#vsingle').on('ended', function(){
$(this)[0].load();
});
这段代码会导致视频重新从头开始播放。
我只想重新加载它,这样起始海报会可见,而不播放。
怎么做到这一点?
我还尝试了下面这个,但没有成功。
$(this)[0].load();
$(this)[0].pause();
英文:
<video class='vsingle' id='vsingle' src='ph/video.mp4' poster='ph/vposter.jpg' controls></video>
js
$('#vsingle').on('ended',function(){
$(this)[0].load();
});
This code results in playing video again from start
I want just to reload it, so starting poster to be visible and not to play
How can I to this ?
I also tried this, vithout success
$(this)[0].load();
$(this)[0].pause();
答案1
得分: 2
根据MDN文档 @https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/load:
HTMLMediaElement方法load()将媒体元素重置为其初始状态,并开始选择媒体源并加载媒体,以准备开始播放。
尝试使用 currentTime,像这样:
$(this)[0].pause();
$(this)[0].currentTime = 0;
编辑:
检查是否有其他事件侦听器(导致播放开始)吗?
我刚刚尝试在这里重现您的代码,并且简单地添加:
video.addEventListener('ended', () => { video.load(); })
得到了预期的结果,视频没有自动播放。
英文:
According to MDN Docs @<https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/load>:
> The HTMLMediaElement method load() resets the media element to its initial state and begins the process of selecting a media source and loading the media in preparation for playback to begin at the beginning.
Try using currentTime, like this:
$(this)[0].pause();
$(this)[0].currentTime = 0;
Edit:<br>
Check if maybe there other event listeners (causing play to begin)?
I just tried to reproduce your code here and simply adding:
video.addEventListener('ended', () => { video.load(); })
gave the expected result, and the video did not start auto-playing.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论