如何使用MPMusicPlayerController播放与应用程序捆绑在一起的歌曲文件?
我试过的代码,
NSString *url = [[NSBundle mainBundle] pathForResource:@"song1" ofType:@"mp3"];
MPMusicPlayerController *myMusicPlayer=[[MPMusicPlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url]];
[myMusicPlayer play];发布于 2009-10-28 22:40:08
MPMusicPlayer控制器仅用于播放用户iPod库中的项目。AVAudioPlayer将播放应用程序沙箱中的编码文件,您应该能够将此代码转换为足够轻松地使用AVAudioPlayer ...看起来应该是:
NSString *url = [[NSBundle mainBundle] pathForResource:@"song1" ofType:@"mp3"];
AVAudioPlayer *myMusicPlayer=[[AVAudioPlayer alloc]
initWithContentsOfURL:[NSURL fileURLWithPath:url]
error:nil];
[myMusicPlayer play];发布于 2009-10-29 02:36:18
最好使用AVAudioPlayer来播放捆绑包中的mp3。即使是苹果公司也坚持这一点,为AVAudioPlayer设置音频会话很容易。(如果你想在iPhone睡眠时播放音频) MPMusicPlayerController通常是用来播放iPod音乐的。但是你可以根据你的需要选择任何一种。
https://stackoverflow.com/questions/1636141
复制相似问题