0

我正在使用 Cocos2d 模板为多个 iOS 设备开发会说话的汤姆风格的应用程序。

我遇到的问题是,在第一次播放应用程序,然后关闭并重新启动应用程序时,麦克风会自动开始连续播放上一个会话的音频。

当应用程序关闭时,我也在相关功能中清除 AVAudioSession 的 audioRecorder、audioPlayer、输入和输出文件 URL 以及 SimpleAudioEngine。

任何人都可以请建议这里可能发生什么,或者如何解决这个问题?

我真的很感激任何帮助。

下面是我的代码:

if(isVideoAnimationPlaying == NO){
    CCLOG(@"In 'update', as Video Animations are NOT playing, listen to Microphone & start the Idle State animations...");
    enable_idle_state = YES;


    // Listen if recording is not playing.
    double peakPowerForChannel = 0;
    if(appDel.isPlaying == NO && appDel.soundPlayer.isPlaying == NO){
        CCLOG(@"---------------------> In 'update', when appDel.isPlaying == NO && appDel.soundPlayer.isPlaying == NO....");

        // Constantly update audio levels picked up by Microphone.
        [appDel.soundRecorder updateMeters];

        // Get values for the audio levels.
        const double alpha = 0.05;
        peakPowerForChannel = pow(10, (0.05 * [appDel.soundRecorder peakPowerForChannel:0]));
        appDel.lowPassResults = alpha * peakPowerForChannel + (1.0 - alpha) * appDel.lowPassResults;


        // Check if audio has been picked up or not.
        low_pass_result_value = 0.500;


        // Check the values with the standard.
        if(appDel.lowPassResults > low_pass_result_value){
            CCLOG(@"---------------------> Microphone has detected voices....hence stop the Idle State animations !!!");

            // Start audio recording.
            [self startRecordingNow];

        } else if(appDel.lowPassResults <= low_pass_result_value) {
            CCLOG(@"---------------------> No voices found....so resume the Idle State animations !!! :(");

            // Stop audio recording.
            [appDel stopRecording:recordLabel];


            // Play the Recording now.
            [appDel playRecording:recordLabel];



            // Enable Idle State animations, only if user is not touching any Body Part button.
            if(/* button.isSelected */)
            {
                CCLOG(@"enable_idle_state = YES");
                enable_idle_state = YES;
            }
        }
    }
4

0 回答 0