I'm trying to use the standardized "iPod" audio player to play some MP3 tracks in an iPhone app I'm building. The tracks are downloaded from the internet and stored in the app's "Documents" directory. I thought of using a MPMusicPlayerController to do this, but I don't seem to be able to get it to work. Also, I've seen the AVAudioPlayer, but that just plays the audio without an interface. Any suggestions?
The MPMusicPlayerController is for playing items out of the iPod library (songs sync'd via iTunes) so you won't be able to use it for this.
You can get the NSData for your audio using...
NSData* data = [NSMutableData dataWithContentsOfFile:resourcePath options:0 error:&err];
Then use an AVAudioPlayer created from that data and call play.
AVAudioPlayer* player = [[AVAudioPlayer alloc] initWithData:data error:&err];
[player play];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With