调用videoContext.play()不会播放
-
代码如下:
<Video id='myVideo' className='img2' src='http://huya-w10.huya.com/1919/154920589/1300/cd2a187b606e13f722cf5e4638614313.mp4' initialTime='0' > { this.state.poster && <CoverView class='controls'> <CoverView class='play' style={style} onClick={this.play}> </CoverView> </CoverView> } </Video>
componentDidMount () { const videoContext = Taro.createVideoContext('myVideo') this.setState({ videoContext: videoContext }) } play = () => { this.state.videoContext.play() this.setState({ poster: false }) }
-
@15529609697_p 哥哥,我按你这个写的可以的呀。
constructor() { super(...arguments) this.state = { poster: true, videoContext: null } componentDidMount () { const videoContext = Taro.createVideoContext('myVideo') this.setState({ videoContext: videoContext }) } play = () => { console.log('done') this.state.videoContext.play() this.setState({ poster: false }) } <Video id='myVideo' className='img2' src='http://huya-w10.huya.com/1919/154920589/1300/cd2a187b606e13f722cf5e4638614313.mp4' initialTime='0' > { this.state.poster && <CoverView class='controls'> <CoverView class='play' onClick={this.play} style="width: 100%; height: 100%; background: rbga(0,0,0,0.5);" > </CoverView> </CoverView> } </Video>
-
@15529609697_p 我的也是不行
-
@jd_68e5fb7e4cace 试试二楼都代码
-
@15529609697_p 我的用二楼的也可以的
-
@jd_68e5fb7e4cace 神奇,之前我跑了一遍才贴出来的
-
@Taro-小助手-honly 在 调用videoContext.play()不会播放 中说:
constructor() {
super(...arguments)
this.state = {
poster: true,
videoContext: null
}componentDidMount () {
const videoContext = Taro.createVideoContext('myVideo')
this.setState({
videoContext: videoContext
})
}
play = () => {
console.log('done')
this.state.videoContext.play()
this.setState({
poster: false
})
}
<Video
id='myVideo'
className='img2'
src='http://huya-w10.huya.com/1919/154920589/1300/cd2a187b606e13f722cf5e4638614313.mp4'
initialTime='0'
>
{
this.state.poster &&
<CoverView class='controls'>
<CoverView
class='play'
onClick={this.play}
style="width: 100%; height: 100%; background: rbga(0,0,0,0.5);"
>
</CoverView>
</CoverView>
}
</Video>是在小程序里面 还是在h5