Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/110.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
react native sound不适用于iOS的生产构建,但适用于emulator和android的生产构建_Android_Ios_React Native_React Native Sound - Fatal编程技术网

react native sound不适用于iOS的生产构建,但适用于emulator和android的生产构建

react native sound不适用于iOS的生产构建,但适用于emulator和android的生产构建,android,ios,react-native,react-native-sound,Android,Ios,React Native,React Native Sound,我正在开发一个React本地应用程序,它可以播放语音邮件。我的生产应用程序遇到了问题。它不会在生产iOS或testflight版本上播放语音邮件,但会在android生产版本以及iOS和android模拟器上播放。我对本机应用程序的反应相对较新,所以我试图弄清楚为什么会发生这种情况 应用程序不会崩溃,它会在UI中显示播放,但不会播放音频 对于无法播放声音的产品构建,需要检查哪些具体事项 我使用的是react native sound的当前版本,当前版本为0.10.9 这里是我的togglePla

我正在开发一个React本地应用程序,它可以播放语音邮件。我的生产应用程序遇到了问题。它不会在生产iOS或testflight版本上播放语音邮件,但会在android生产版本以及iOS和android模拟器上播放。我对本机应用程序的反应相对较新,所以我试图弄清楚为什么会发生这种情况

应用程序不会崩溃,它会在UI中显示播放,但不会播放音频

对于无法播放声音的产品构建,需要检查哪些具体事项

我使用的是react native sound的当前版本,当前版本为0.10.9

这里是我的togglePlay函数,它使用来自本地声音的声音。我已经进口了

切换播放(){

请让我知道其他信息是否有助于调试此文件


谢谢

这个问题与iPhone上的手动静音开关有关。声音是通过扬声器播放的。我添加了'Sound.setCategory(“播放”)声音被初始化后,即使铃声被静音,声音仍然可以播放。

我最近遇到了这个问题,网上的响应对我都不起作用。最后,我意识到我使用的
.mp3
声音没有被mac/Xcode检测到。因此,当你在Xcode或Finder中看到文件详细信息时,它会由于无法识别足够的信息,如持续时间。在花费数小时寻找解决方案后,我发现了此问题

我做错了什么-手动将
*.wav
*.avi
文件重命名为
.mp3

溶液- 1.使用iTunes将文件转换为特定格式。手动转换文件格式会损坏文件,尽管它们在android上工作,但iOS在存档构建后无法检测到它们。
2.对于iOS,将您的声音添加到Xcode项目的资源中

更新:当删除并重建应用程序时,声音不会在iOS上播放,而是在应用程序的任何后续版本中播放(不删除它)将允许声音播放。您为什么提供package.json?您的问题不是关于
react native sound
?您使用/在package-lock.json中解析了它的确切版本吗?您能在使用它的地方提供Javascript代码吗?我们使用react native sound,到目前为止没有问题(除了android上的codepush版本…@Vinzzz,我用你要求的更新信息更新了我的问题。我调用togglePlay()在ToughableHighlight组件中。这同样适用于Android版本,但不适用于iOS。感谢您的帮助,您没有提供react本机声音部分,这只是一些react组件。您是否使用require作为声音文件路径?如何将声音嵌入应用程序包?我发现了这个问题。声音来自spe手机上的aker取代了耳机,铃声被静音。我添加了'Sound.setCategory(“播放”),以便即使铃声被静音,声音仍能播放。感谢您主动提出帮助解决此问题@Vinzzz
  if (this.state.vmLoaded == false) {

        if (this.state.vmLoading == true) {
            return;
        }

        if (this.state.vmLoading == false) {

            this.setState({ vmLoading: true });

            Requester.getVoicemail(this.props.vmData, this.props.token, 'stream')
            .then((res) => {

                this.setState({
                    vmPath: res,
                    vmLoaded: true,
                });

                const vm = new Sound(res, '', (error) => {

                    if (error) {

                        // Show toast if voicemail did not load
                        Toast({ message: 'Failed to load voicemail' });
                    } else {

                        if (!this.state.vmStarted) {

                            this.setState({ vmStarted: true });
                        }

                        vm.play((success) => {

                            if (success) {

                                this.setState({
                                    vmPlaying: false,
                                    currentTime: this.state.vmLength / 1000,
                                });

                                // Clears the interval timer to keep thread
                                // from keeping track of timing
                                timer.clearInterval(this, 'playingInt');
                            } else {

                                // if call recording fails to play, show toast to user
                                Toast({ message: 'Failed to play recording' });
                            }
                        });

                        this.setState({ vmPlaying: true });

                        // if loaded successfully, set the instance of Sound as STATE vm
                        // allowing calls to the instance via this.state.vm
                        // ie: this.state.vm.play() will initiate playing the sound
                        this.setState({
                            // set instance of Sound to state
                            vm,
                            // set full length of recording to state
                            vmLength: vm.getDuration(),
                            // set current playing time of recording to state (new, so zero)
                            currentTime: 0,
                            // interval is still null until sound is played
                            interval: null,
                            // sound starts off paused (no audio)
                            vmPlaying: true,
                            // Finally, the recording has been loaded, setting
                            // this so another instance is not created on
                            // rerender (see above IF statements)
                            vmLoaded: true,
                            vmLoading: false,
                        });
                    }
                });
            }).then(() => {

                timer.clearInterval(this, 'playingInt');

                interval: timer.setInterval(this, 'playingInt', () => {

                    this.state.vm.getCurrentTime((seconds) => {

                        this.setState({ currentTime: seconds });
                    });
                }, 1000);
            });
        }
    } else if (this.state.vmLoaded == true) {

        if (this.state.vmPlaying == true) {

            this.state.vm.pause();

            this.setState({ vmPlaying: false });

            timer.clearInterval(this, 'playingInt');
        } else {

            this.state.vm.play();

            this.setState({ vmPlaying: true });

            timer.clearInterval(this, 'playingInt');

            interval: timer.setInterval(this, 'playingInt', () => {

                this.state.vm.getCurrentTime((seconds) => {

                    this.setState({ currentTime: seconds });
                });
            }, 1000);
        }
    }
}