html5视频在MouseOut时重新显示海报图像
如何“停止” html5 视频播放并恢复为海报图像?在调用 this.play()
之前,海报图像会正常显示。
我的代码:
<video loop="loop" onMouseOver="this.play();" onMouseOut="this.pause();" poster="/oceans-clip.thumb.jpg">
<source src="/oceans-clip.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"' />
<source src="/oceans-clip.webm" type='video/webm; codecs="vp8, vorbis"' />
</video>
这按预期工作,但是我想在MouseOut 上恢复到海报图像,而不是仅仅暂停视频。有什么好的方法可以做到这一点?
How can I 'stop' a html5 video playback, and revert to poster image? Until this.play()
is called, the poster image is showing properly.
My code:
<video loop="loop" onMouseOver="this.play();" onMouseOut="this.pause();" poster="/oceans-clip.thumb.jpg">
<source src="/oceans-clip.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"' />
<source src="/oceans-clip.webm" type='video/webm; codecs="vp8, vorbis"' />
</video>
This is working as expected, however I want to revert to poster image onMouseOut instead of just pausing the video. What's a good way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
规范排除了这种情况:
即如果您想要与规范不同的行为,您需要自己实现它,也许可以使用覆盖包含所需图像的视频的元素,然后隐藏/显示它。
The spec rules this out:
I.e. if you want behaviour different to the spec you'll need to implement it yourself, maybe by using an element that overlays the video which contains the desired image and then hide/show it.
我一直在谷歌搜索这个问题的解决方案,显然,
史蒂夫·莱西的解决方案:
似乎可以在我的 OSX 10.9 上运行,浏览器包括:Safari 7.0、Firefox 26.0 和 Chrome 31。不过我还没有在移动设备上测试过它。
我已经使用 JS 创建的视频对象对其进行了测试:
现在,当我想停止视频并再次显示海报时,我只需这样做:
但是,这还不够,因为视频将无法再次播放。为了使其在此之后可以播放,我删除了“src”属性(同时保留“源”子对象不变):
此后它可以工作:
I've been googling for solution for this problem and apparently,
Steve Lacey's solution:
appears to work on my OSX 10.9, in browsers: Safari 7.0, Firefox 26.0 and Chrome 31. I haven't tested it on mobile devices though.
I've tested it using video object created with JS:
Now when I want to stop video and show poster again, I just do:
But, that's not enough since video will not be able to play again. To make it playable after this point, I removed 'src' attribute (while leaving 'source' sub-objects as is):
After this it works:
这篇文章很旧,但我遇到了同样的问题并像这样解决了。
This post is old but I had the same problema and solve it like this.
我用过它,对我来说很好
i used it and it is good with me
这对我有用:
This works for me:
您可以使用:
这不会真正停止您的视频,它会重新加载整个文档。
将显示“海报框架”。
里奇
You can use:
That will not really stop your video, it will reload the whole document.
The "Poster Frame" will be shown.
Richie