【问题标题】:Start video from there where we left从我们离开的地方开始视频
【发布时间】:2019-09-30 13:00:27
【问题描述】:

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

我正在使用 React-native-video

【问题讨论】:

  • 看起来你可以使用seek()
  • 如果应用程序完全终止,最好的解决方案是将值存储在本地存储中,并在您打开应用程序时再次检索

标签: react-native react-native-video


【解决方案1】:

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

然后您可以将其存储在本地存储中

【讨论】:

  • 请尝试添加特定代码作为解决方案。它可能对特定或其他代码有所帮助
【解决方案2】:

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

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
     }}
 />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-23
    • 1970-01-01
    相关资源
    最近更新 更多