开发者

IOS iPhone use MPMusicPlayerController to play external music file, and display iPod interface

I'm trying to use the standardized "iPod" audio player to play some MP3 tracks in an iPhone app I'm building. The tr开发者_C百科acks 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];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜