微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用RN Camera在React Native中录制来自第三方链接的带有音乐的视频几秒钟后视频开始录制

如何解决使用RN Camera在React Native中录制来自第三方链接的带有音乐的视频几秒钟后视频开始录制

我正在尝试使用RN Camera录制视频,并且当用户单击“录制”按钮时,我也在使用react-native-sound lib来播放音乐。我面临的问题是,当我单击“录制”按钮时,视频会在几秒钟后开始录制,但不是立即开始。 这是我的代码

async startRecording() {
    this.sound = new Sound(
      'https://www.bensound.com/bensound-music/bensound-dubstep.mp3','',(error) => {
        if (error) {
          console.log('Failed to load the sound',error);
          Alert.alert('Notice','audio file error. (Error code : 1)');
          // this.setState({playState: 'paused'});
        } else {
          if (this.sound.isLoaded) {
            // this.setState({loading: false});
          }
          // this.setState({
          //   playState: 'playing',//   duration: this.sound.getDuration(),// });
          this.sound.play();
          this.setState({recording: true},() => {
            this.videoRec();
          });
        }
      },);
  }

这里是vid录制代码

async videoRec() {
    const {uri,codec = 'mp4',size} = await this.camera.recordAsync();
    this.setState({recording: false,processing: true});
    const type = `video/${codec}`;

    this.setState({processing: false,uri: uri,type: type},() => {
      this.sound.pause();
      this.props.navigation.navigate('Preview',{video: uri});
    });
  }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。