Ios 从nsbundle播放mp3

Ios 从nsbundle播放mp3,ios,ios4,mp3,nsbundle,mpmusicplayercontroller,Ios,Ios4,Mp3,Nsbundle,Mpmusicplayercontroller,设置 我把一个mp3放进包里只是为了测试,我会把它们下载到文档目录中。但现在我要把这捆东西处理掉 我找到了一些教程,但没有找到我需要的任何东西。下面肯定是几种解决方案的混合,可能不是最好的方法 问题 如何从捆绑包中取出歌曲并在应用程序中播放 //Create an instance of MPMusicPlayerController MPMusicPlayerController* myPlayer = [MPMusicPlayerController applicationMusicPlay

设置

我把一个mp3放进包里只是为了测试,我会把它们下载到文档目录中。但现在我要把这捆东西处理掉

我找到了一些教程,但没有找到我需要的任何东西。下面肯定是几种解决方案的混合,可能不是最好的方法

问题

如何从捆绑包中取出歌曲并在应用程序中播放

//Create an instance of MPMusicPlayerController
MPMusicPlayerController* myPlayer = [MPMusicPlayerController applicationMusicPlayer];

//Read the song off the bundle.
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"LittleMoments" ofType:@"mp3"];  
 NSData *myData = [NSData dataWithContentsOfFile:filePath];

if (myData) { 

    //This wont work for me because i don't want to query songs from the iPod, 
    i want to play songs out of the Bundle.

    //Create a query that will return all songs by The Beatles grouped by album
    MPMediaQuery* query = [MPMediaQuery songsQuery];
    [query addFilterPredicate:[MPMediaPropertyPredicate predicateWithValue:@"The Beatles" forProperty:MPMediaItemPropertyArtist comparisonType:MPMediaPredicateComparisonEqualTo]];
    [query setGroupingType:MPMediaGroupingAlbum];

    //Pass the query to the player
    [myPlayer setQueueWithQuery:query];
 /////**** how can i get nsdata into MyPlayer?*****////// 

    //Start playing and set a label text to the name and image to the cover art of the song that is playing
    [myPlayer play];

}

尝试使用AVAudioPlayer播放该文件

AVAudioPlayer *audioPlayer = [(AVAudioPlayer*)[AVAudioPlayer alloc] initWithData:myData error:nil];

audioPlayer.delegate = self;
[audioPlayer play];

尝试使用AVAudioPlayer播放该文件

AVAudioPlayer *audioPlayer = [(AVAudioPlayer*)[AVAudioPlayer alloc] initWithData:myData error:nil];

audioPlayer.delegate = self;
[audioPlayer play];

我得到这个警告:将viewcontroller*const_strong传递给不可比较的类型id的参数。它也会在[audioPlayer play]上给出错误的执行;卸下audioPlayer.delegate=self;将AVAudioPlayerDelegate作为协议添加到ViewController中。感谢您的帮助。我刚在谷歌上搜索了AVAudioPlayer,找到了这个教程,效果非常好。感谢您再次收到此警告:将viewcontroller*const_strong传递给不可比较类型id的参数。这也会在[audioPlayer play]上产生错误的执行;卸下audioPlayer.delegate=self;将AVAudioPlayerDelegate作为协议添加到ViewController中。感谢您的帮助。我刚在谷歌上搜索了AVAudioPlayer,找到了这个教程,效果非常好。再次感谢