调用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>
    

登录后回复