无法在反应原生视频中暂停 [英] Can't pause in react native video

查看:50
本文介绍了无法在反应原生视频中暂停的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想播放一个音频文件,但它正在自动播放,我无法暂停.

我该如何解决?
必须在开始时暂停
我的代码:

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>
    );
  }
}

推荐答案

当前 react-native-video 中存在一个错误,其中 pause 标志在组件时被忽略首先加载.您必须在组件加载后更改 pause.

There's currently a bug in react-native-video where the pause flag is ignored when the component is first loaded. You have to change pause AFTER the component has loaded.

首先,确保您的this.state.pause = false.然后:

First, make sure your this.state.pause = false. Then:

<Video
  paused={this.state.paused}
  onLoad={() => {
    this.setState({
      paused: true
    });
  }}
</Video>

上下文:https://github.com/react-native-community/react-native-video/issues/494#issuecomment-281853423

这篇关于无法在反应原生视频中暂停的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆