如何使用 MPMusicPlayerController 播放与应用程序捆绑的歌曲文件?
我尝试过的代码,
NSString *url = [[NSBundle mainBundle] pathForResource:@"song1" ofType:@"mp3"];
MPMusicPlayerController *myMusicPlayer=[[MPMusicPlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url]];
[myMusicPlayer play];
最佳答案
MPMusicPlayer
Controller 仅用于播放用户 iPod 库中的项目。 AVAudioPlayer
将从应用程序的沙箱中播放编码文件,您应该能够轻松地转换此代码以使用 AVAudioPlayer
...看起来像:
NSString *url = [[NSBundle mainBundle] pathForResource:@"song1" ofType:@"mp3"];
AVAudioPlayer *myMusicPlayer=[[AVAudioPlayer alloc]
initWithContentsOfURL:[NSURL fileURLWithPath:url]
error:nil];
[myMusicPlayer play];
关于iphone - MPMusicPlayerController 并播放捆绑的歌曲,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1636141/