在我的React应用程序中,我想要一个按钮来导航到视频上显示的下一课,就在当前视频播放完之后。我正在使用react-player显示视频。我想知道我怎么才能做到这一点是react-player。任何有用的建议都是非常感谢的。
<ReactPlayer
url={videoPath}
width="100%"
height='100%'
controls={true}
className="player"
onEnded={markLessonAsCompleted}
config={{
file: {
attributes: {
controlsList: "nodownload"
}
}
}}
volume={1}
/>发布于 2020-04-08 20:08:26
您可以在视频结束(onEnded)时设置一个布尔状态值,并有条件地显示“下一步”按钮。按钮需要绝对定位才能覆盖视频。而居中按钮弹性框是众多选项之一。
以下代码也可作为代码沙箱使用here。
function App() {
const urls = [
'https://www.youtube.com/watch?v=oPZXk4ESdng?t=50',
'https://www.youtube.com/watch?v=bcWZ6C-kn_Y'
]
const [currentUrlIndex, setCurrentUrlIndex] = React.useState(0)
const [showNextButton, setShowNextButton] = React.useState(false)
return (
<div
style={{
display: 'flex',
justifyContent: 'center',
alignItems: 'center'
}}
>
<ReactPlayer
url={urls[currentUrlIndex]}
playing
controls
onEnded={() => setShowNextButton(true)}
style={{
width: '100%',
height: '100%'
}}
/>
{showNextButton && (
<button
onClick={() => {
setCurrentUrlIndex(
prevUrlIndex => (prevUrlIndex + 1) % urls.length
)
setShowNextButton(false)
}}
style={{
position: 'absolute',
zIndex: 10,
fontSize: '2em'
}}
>
next
</button>
)}
</div>
)
}https://stackoverflow.com/questions/60973531
复制相似问题