How to hide poster flashing when switching between two videos in ReactJS

自闭症网瘾萝莉.ら 提交于 2020-04-30 07:48:05

问题


I have a video with two versions, SD and HD, which is used to compare different qualities of a certain video file.

Here is the snippet:

<div className={`video__switch ${isObscured ? "" : "is-obscured"}`}>
    <button className={`video__switch__value u-type--sans u-type--delta u-slant ${isHD ? "" : "active"}`} onClick={this.handleIsSD.bind(this)}>
                      <span className="u-unslant u-type--bold">SD</span>
                    </button>
    <button className={`video__switch__value u-type--sans u-type--delta u-slant ${isHD ? "active" : ""}`} onClick={this.handleIsHD.bind(this)}>
                      <span className="u-unslant u-type--bold">HD</span>
                    </button>
</div>

<div className={`video__media ${isObscured ? "" : "is-obscured"}`}>
    <video loop ref="vidRef" poster="images/poster.jpg" className="header__video js-headerVideo" src={videoUrl} />
</div>

handleIsSD and handleIsHD just calls functions that set the other video to play, it's not important for this question.

isObscured is used as an overlay before first play of the video, and is invisible later on.

video__switch__value button is used for changing between SD and HD quality.

The problem is that I have also poster image on the videos which is a first frame from a video, and it always flashes for a few ms on each HD/SD switch in the video. And the first frame poster in the middle of a video looks really odd. Is there some way to fix this?

I've tried removing the poster, but then I only get black screen flashes.

Main idea is to grab the screen from the exact moment of switching quality and placing it as a poster until the other quality video loads, but I'm not sure that is doable. Thanks all.


回答1:


Hope that can be easily achieved using combination of technique.

When the user changes between SD and HD, then capture a image of the current frame using techniques described here. Then from the canvas, get the image as dataURI, set it as a poster of the video element and switch the source and then do your stuff.



来源:https://stackoverflow.com/questions/46115529/how-to-hide-poster-flashing-when-switching-between-two-videos-in-reactjs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!