我正在使用基于react-native-video(https://www.npmjs.com/package/react-native-video-controls)的react-native-video-controls组件(https://www.npmjs.com/package/react-native-video),我正在尝试播放序列中的下一个视频让视频寻求0(所以从一开始就播放)。但我收到错误:“未定义不是一个函数(评估'this.refs.myVideo.seek(0)')React-Native”
这是我的代码:
import Video from 'react-native-video';
import VideoPlayer from 'react-native-video-controls';
export default class Player extends Component {
constructor(props){
this.state = {
playlist: [require(file1.mp4),require(file2.mp4)]
}
}
playNext() {
this.refs.myVideo.seek(0);
let playlist = this.state.playlist;
playlist.shift();
this.setState({playlist,})
}
render() {
return (
<View>
<VideoPlayer
ref='myVideo'
muted={false}
seekColor={ 'red' }
source={this.state.playlist[0]}
navigator={ this.props.navigator }
style={styles.player}
onEnd={()=>this.playNext()}
/>
</View>
);
}
}
我做错了什么
编辑:这是用于android btw
答案 0 :(得分:0)
首先,裁判应该看起来像:ref={this.myVideo}
使用VideoPlayer时,视频方法更深入,因此应编写:this.myVideo.player.ref.seek(0)
(VideoPlayer是视频的容器)