2

我正在尝试在 React-native 中制作视频播放器应用程序。我想要一个功能,比如在关闭应用程序之前从用户离开的地方开始播放视频。有什么线索吗?

我正在使用 React-native-video

4

2 回答 2

1

video您可以通过简单地运行从组件中获取当前时间videoRef.currentTime

然后,您可以将其存储在 localStorage

于 2019-09-30T13:10:56.283 回答
0

更具体地说,如果您想使用存储/本地存储来实现这一点。请检查一下。

import Video from "react-native-video"

constructor(props) {
    super(props)
    this.progress = 0
    this.onProgress = this.onProgress.bind(this)

    //Here you can store this progress time to async storage or store.So that 
     when you navigate back to this screen you can either get the progress 
     from storage or from initial state = 0
  }

onProgress = (data) => {
    this.progress = data.currentTime
  }

<Video
     ref={(ref) => { this.player = ref }}
     source={{ uri: '.....' }}
     onProgress={this.onProgress}
     onLoad={() => {
     if (menuVideoProgress > 0)
       this.player.seek(menuVideoProgress)  //here recent progress times comes 
                                              from storage
     }}
 />
于 2019-10-08T07:50:44.813 回答