I want to play song using AVAudioPlayer. But this is does not work some time. I did not get what is the issue. I'm using this below code to play mp3 file from local.
NSString *soundFile;
soundFile = [[NSBundle mainBundle] pathForResource:@"notification_sound" ofType:@"mp3"];
NSURL *fileURL = [NSURL fileURLWithPath:soundFile];
self.playerAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
self.playerAudio.numberOfLoops = -1;
self.playerAudio.volume=1;
if([self.playerAudio prepareToPlay])
{
NSLog(@"Prepare to play successfully");
[self.playerAudio play];
}
if([self.playerAudio prepareToPlay]) this condition never be satisfied why this is happened please help me to solved this issue.
Thanks in advance
