我想播放音频文件,但是它正在自动播放,我不能暂停播放。
我该如何解决?我的代码
开始时必须暂停
:
import Video from 'react-native-video';
export default class Android extends Component {
constructor(props) {
super(props)
this.state = {
paused: true,
}
}
video: Video;
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<Text style={styles.instructions}>
To get started, edit index.ios.js
</Text>
<Text style={styles.instructions}>
Press Cmd+R to reload,{'\n'}
Cmd+D or shake for dev menu
</Text>
<Video
ref={(ref: Video) => { this.video = ref }}
source={{ uri: "http://s3.picofile.com/d/7376893331/8b7bc5b4-4b5e-47c4-96dd-b0c13fd18157/Sara_Diba_Delbare_Man.mp3", mainVer: 1, patchVer: 0 }}
paused={this.state.paused}
/>
</View>
);
}
}
Run Code Online (Sandbox Code Playgroud)
当前存在一个错误react-native-video,该错误pause是在首次加载组件时忽略该标志。您必须pause在组件加载后进行更改。
首先,请确保您的this.state.pause = false。然后:
<Video
paused={this.state.paused}
onLoad={() => {
this.setState({
paused: true
});
}}
</Video>
Run Code Online (Sandbox Code Playgroud)
内容:https://github.com/react-native-community/react-native-video/issues/494#issuecomment-281853423