1

In my application I am using an AVAudioRecorder object to allow the user to record a sound file, and when the user is done recording they can play the sound via the AVAudioPlayer. The issue I'm having is when the user tries to play the audio file it only plays for one second. What is even more odd is that this code worked perfect on iOS 5, but since upgrading to iOS 6 this issue has started to happen.

I have checked the file that is being created via iTunes file sharing, and I'm able to play the entire sound file on my desktop.

Below I have pasted the code from my manipulation file that loads the audio player. From what I can tell the

- (void)playRecordingBtnClk:(id)sender
{
    NSLog(@"Play btn clk");

    if (!isRecording) {

        // disable all buttons
        [_recordButton disableButton];
        [_stopButton disableButton];
        [_playButton disableButton];
        [_saveButton disableButton];

        // create the player and play the file from the beginning
        if (audioPlayer) {
            [audioPlayer release];
            audioPlayer = nil;
        }

        audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:audioRecorder.url error:&error];
        audioPlayer.delegate = self;
        audioPlayer.currentTime = 0.0;
        [audioPlayer prepareToPlay];

        if (error) {
            NSLog(@"Error Playing Audio File: %@", [error debugDescription]);
            return;
        }

        [audioPlayer play];
        [self startTicker];
    }
}

It appears that the

-(void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag 

method is being called after one second which is why the audio player stops. Anyone have any ideas what is going on here?

Janak Nirmal
  • 22,706
  • 18
  • 63
  • 99
miken.mkndev
  • 1,821
  • 3
  • 25
  • 39
  • Hmm...I didn't even realize that was something that people needed todo. I read the article you linked to and have accepted the answer. Thanks – miken.mkndev Oct 08 '12 at 12:41

1 Answers1

3

For iOS 6.0, add two more lines:

soundPlayer.currentTime = soundPlayer.duration + soundPlayer.duration;
soundPlayer.numberOfLoops = 1;

Not a perfect solution. We may need to wait for iOS 6.0.1/6.1 update.

For more, please visit this, someone commented there, saying it might be a problem of CDAudioManager.

Janak Nirmal
  • 22,706
  • 18
  • 63
  • 99
  • Ok, I'll give this a try and will reply if it works. I figured it had to be something todo with a possible bug in iOS 6. Thanks for the help! – miken.mkndev Oct 08 '12 at 12:40