【问题标题】:How to trigger stop method for react-player to stop and end video?如何触发react-player停止和结束视频的停止方法?
【发布时间】:2022-01-02 21:03:14
【问题描述】:

react-player如何触发停止方法停止和结束视频?这是我的代码:

<ReactPlayer
  className="react-player mw-100 w-100 "
  id="myPlayer"
  ref={(player) => {
    this.player = player;
  }}
  url={VIMEO_URL}
  onStart={() => {
    this.player.seekTo(this.getProgress());
  }}
  onPlay={() => this.play(this)}
  onPause={() => this.pause()}
  onDuration={this.handleDuration}
  onProgress={this._recordProgress}
  onReady={() => this.player.seekTo(this.getProgress())}
/>;

【问题讨论】:

  • 您想停止以编程方式播放视频吗?
  • 是的,虽然我想停止视频的外部功能

标签: javascript reactjs react-player


【解决方案1】:

尝试使用播放属性:

const [isPlaying, setIsPlaying] = useState(true);

<ReactPlayer
  playing={isPlaying}
  className="react-player mw-100 w-100 "
  id="myPlayer"
  ref={(player) => {
    this.player = player;
  }}
  url={VIMEO_URL}
  onStart={() => {
    this.player.seekTo(this.getProgress());
  }}
  onPlay={() => this.play(this)}
  onPause={() => this.pause()}
  onDuration={this.handleDuration}
  onProgress={this._recordProgress}
  onReady={() => this.player.seekTo(this.getProgress())}
/>;

【讨论】:

  • 是的,这个解决方案会暂停视频,但我的要求是停止视频
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-12
  • 2016-04-19
  • 1970-01-01
  • 2019-12-04
  • 1970-01-01
  • 2013-12-23
相关资源
最近更新 更多