NSError *err;
// Initialize audio player
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&err];
audioPlayer.delegate = self;
[audioPlayer
Apparently AVAudioPlayer
does not support streaming via. HTTP as I was trying to do, so by using AVPlayer
instead, I got it working.
Did you initialize a AVAudioSession?
The following works fine for me. Might give you a hint of whats not working for you.
Initializing:
AVAudioSession* session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryAmbient error:nil];
[session setActive:TRUE error:nil];
Loading:
AVAudioPlayer* audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileUrl error:nil];
audioPlayer.numberOfLoops = 0;
[audioPlayer prepareToPlay];
audioPlayer.volume = 1.0;
Playing:
[audioPlayer play];
Update
To find the right NSRUL for fileUrl
, I used this code:
NSURL* fileUrl = [NSURL fileURLWithPath:
[[NSBundle mainBundle] pathForResource:@"MySound" ofType:@"wav"] isDirectory:NO];
And then I added MySound.wav
to the project (bundle).