如何判断视频是否刚刚使用expo.video? ReactNative / Expo.io

时间:2017-08-26 17:01:33

标签: react-native expo

例如,如果我有组件:

import React, { Component } from 'react';
import { Video } from 'expo';
let styles = require('../stylesheet.js');
export default class Player extends Component {
  render(){
    return(
     <Video
      ref={this._handleVideoRef}
      source={require(//file)}
      rate={1.0}
      volume={1.0}
      muted={false}
      useNativeControls
      resizeMode="cover"
      shouldPlay
      style={styles.player} />
      )
  }
}

我在文档(https://docs.expo.io/versions/latest/sdk/av.html)中看到使用&#34; playbackstatus.didJustFinish&#34;和onPlaybackStatusUpdate,但他们的例子对我来说没有多大意义。任何人都可以告诉我如何使用我的代码确定视频是否已结束?

2 个答案:

答案 0 :(得分:1)

如果有其他人来寻找答案,以下是OP和docs(https://docs.expo.io/versions/latest/sdk/av.html)的组合:

import React, { Component } from 'react';
import { Video } from 'expo';

export default class Player extends Component {
  _onPlaybackStatusUpdate = playbackStatus => {
    if (playbackStatus.didJustFinish)
      // The player has just finished playing and will stop.
  };

  render(){
    return(
      <Video
        ref={this._handleVideoRef}
        source={require(//file)}
        onPlaybackStatusUpdate=
          {(playbackStatus) => this._onPlaybackStatusUpdate(playbackStatus)}/>
        resizeMode="cover"
        style={styles.player}
    );
  }
}

答案 1 :(得分:1)

mauriii的答案从不对我有用,因为当playingStatus.didJustFinish变为true时没有调用onPlaybackStatusUpdate,但是在console.logging之后,我注意到另外两个字段durationMillis和positionMillis,所以当这些值相等时,我们就知道视频是完整的

所以要及时更新答案

03:15:pm and 03/07/2018