0

Hi I have a setup that records audio (with AVAudioSessionCategoryPlayAndRecord category), now I want to playback and MP3 file as usual with AVAudioPlayer instance, but no any sound can be hear.

AVAudioPlayer do not throw any error, nor in its delegate callbacks.

Has anybody similar experience? How to overcome this?

Geri Borbás
  • 15,810
  • 18
  • 109
  • 172

1 Answers1

0

Please use this -

 NSString *docDirPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
            filePath = [NSString stringWithFormat:@"%@/%@.mp3", docDirPath , @"Welcome"];
     NSError *error;
            NSURL *fileURL = [NSURL fileURLWithPath:filePath];
            avPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:&error];

            if (avPlayer == nil) 
            {
                NSLog(@"AudioPlayer did not load properly: %@", [error description]);
            }
            else
              {
                [avPlayer play];
           avPlayer.delegate=self;
               } 

And tell me if it is working or not.

iEinstein
  • 2,100
  • 1
  • 21
  • 32