简体   繁体   English

html5 视频重新显示海报图像 onMouseOut

[英]html5 video redisplay poster image onMouseOut

How can I 'stop' a html5 video playback, and revert to poster image?如何“停止”html5 视频播放并恢复为海报图像? Until this.play() is called, the poster image is showing properly.this.play()之前,海报图像显示正常。

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.这是按预期工作的,但是我想在MouseOut 上恢复到海报图像,而不仅仅是暂停视频。 What's a good way to do this?有什么好方法可以做到这一点?

I've been googling for solution for this problem and apparently,我一直在搜索这个问题的解决方案,显然,

Steve Lacey's solution:史蒂夫莱西的解决方案:

Sure.当然。 You could do the equivalent of 'video.src = "";你可以做相当于 'video.src = "";

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.似乎适用于我的 OSX 10.9,在浏览器中:Safari 7.0、Firefox 26.0 和 Chrome 31。不过我还没有在移动设备上测试过。

I've tested it using video object created with JS:我已经使用用 JS 创建的视频对象对其进行了测试:

var object = document.createElement("video");
/// ... some setup like poster image, size, position etc. goes here...
/// now, add sources:
var sourceMP4 = document.createElement("source"); 
sourceMP4.type = "video/mp4";
sourceMP4.src = "path-to-video-file.mp4";
object.appendChild(sourceMP4);
//// same approach add ogg/ogv and webm sources

Now when I want to stop video and show poster again, I just do:现在当我想停止视频并再次显示海报时,我只是这样做:

object.pause();
object.src = "";

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):为了让它在这一点之后可玩,我删除了“src”属性(同时保留“源”子对象原样):

object.removeAttribute("src");

After this it works:在此之后它的工作原理:

  1. play video播放视频
  2. on stopping video, poster will re-appear停止视频时,海报将重新出现
  3. can play same video again可以再次播放相同的视频

The spec rules this out:规范排除了这一点:

the poster frame should not be shown again after a frame of video has been shown显示一帧视频后不应再次显示海报帧

Ie 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.即,如果您想要与规范不同的行为,您需要自己实现它,也许通过使用一个元素来覆盖包含所需图像的视频,然后隐藏/显示它。

这篇文章很旧,但我遇到了同样的问题并像这样解决了它。

onmouseout="this.load();"

i used it and it is good with me我用过它,对我很好

$('container video').hover(function () {$(this).get(0).play();}
   ,function () {$(this).get(0).load();});});

This works for me:这对我有用:

<div class="rollover">
  <video class="thevideo" loop poster="" height="100" width="250">
    <source src="" type="video/mp4" >
          Your browser does not support the video tag.
  </video>
</div>

<script>
    var figure = $(".rollover").hover( hoverVideo, hideVideo );

    function hoverVideo(e) {  
        $('video', this).get(0).play(); 
    }

    function hideVideo(e) {
        $('video', this).get(0).pause(); 
        v=$('video', this).get(0).currentSrc;
        $('video', this).get(0).src = "";
        $('video', this).get(0).src = v;   
    }
</script>

You can use:您可以使用:

    <script type="text/javascript">
    function videostop() {
      window.location.reload()
    }
    </script>

That will not really stop your video, it will reload the whole document.这不会真正停止您的视频,它会重新加载整个文档。 The "Poster Frame" will be shown.将显示“海报框架”。

Richie里奇

PS I'm from Germany. PS我来自德国。 Sorry if my English is bad.对不起,如果我的英语不好。 But I think, my JavaScript is OK :-)但我认为,我的 JavaScript 没问题 :-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM