AVAudioPlayer only initializes with some files
Posted
by Brendan
on Stack Overflow
See other posts from Stack Overflow
or by Brendan
Published on 2010-04-12T20:17:34Z
Indexed on
2010/04/12
21:43 UTC
Read the original article
Hit count: 495
Hi everyone,
I'm having trouble playing some files with AVAudioPlayer. When I try to play a certain m4a, it works fine. It also works with an mp3 that I try. However it fails on one particular mp3 every time (15 Step, by Radiohead), regardless of the order in which I try to play them. The audio just does not play, though the view loading and everything that happens concurrently happens correctly. The code is below. I get the "Player loaded." log output on the other two songs, but not on 15 Step. I know the file path is correct (I have it log outputted earlier in the app, and it is correct). Any ideas?
NSData *musicData = [NSData dataWithContentsOfURL:[[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:[song filename] ofType:nil]]];
NSLog([[NSBundle mainBundle] pathForResource:[song filename] ofType:nil]);
if(musicData) {
NSLog(@"File found.");
}
self.songView.player = [[AVAudioPlayer alloc] initWithData:musicData error:nil];
if(self.songView.player) {
NSLog(@"Player loaded.");
}
[self.songView.player play];
NSLog(@"You should be hearing something now.");
Thanks, Brendan
© Stack Overflow or respective owner