Cocos2d テンプレートを使用して、複数の iOS デバイス用の Talking Tom スタイルのアプリを開発しています。
私が抱えている問題は、アプリを初めて再生し、アプリを閉じて再起動すると、マイクが自動的に前のセッションのオーディオを連続して再生し始めることです。
アプリを閉じたときに、関連する関数で AVAudioSession の audioRecorder、audioPlayer、input & output fileURL、および 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;
}
}
}