admin管理员组文章数量:1122846
I use the following code to play multiple videos in series
import React, { useState ,useEffect,useRef} from 'react'
export function VideoPlayer({playlist}) {
const [currentlyPlaying, setCurrentlyPlaying] = useState(playlist[0]);
const player=useRef(null);
const playNext=()=>{
let currentIndex=playlist.indexOf(currentlyPlaying);
if(currentIndex<playlist.length-1){
setCurrentlyPlaying(playlist[currentIndex+1]);
}
else{
setCurrentlyPlaying(playlist[0]);
}
//reset the player
player.current.load();
}
return (
<div>
<video width="320" height="240" controls ref={player} autoPlay onEnded={playNext} ref={player}>
<source src={currentlyPlaying} type="video/mp4"/>
Your browser does not support the video tag.
</video>
</div>
)
}
It works decent on desktop but on mobile it refreshes the controls each time, making it look awkawrd (the videos are only a few seconds long)
Is there a more seamless way to play video in series?
本文标签: htmlHow can I seemlessly play multiple videos in loop with reactStack Overflow
版权声明:本文标题:html - How can I seemlessly play multiple videos in loop with react? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736305348a1932559.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论