解决方案 »

  1.   

    我的方法源码是:(比较混乱,请见谅)
    - (void)startPlayer:(NSInteger)songNumber
    {
      //创建音乐播放器
        playerController = [MPMusicPlayerController applicationMusicPlayer];
        
        //MPMediaQuery *myPlaylistsQuery = [MPMediaQuery playlistsQuery];
        MPMediaQuery *mdbb = [MPMediaQuery songsQuery];
       // musicLists = [mdbb collections];
        if (musicLists != nil)
        {
            NSLog(@"%@",[musicLists objectAtIndex:1]);
            NSLog(@"音乐列表不为空");
        }    MPMediaItemCollection *mediaCollection = [MPMediaItemCollection collectionWithItems:[mdbb collections]];
        [playerController setQueueWithItemCollection:mediaCollection];
        
        [playerController setRepeatMode:MPMusicRepeatModeAll];
        //播放特定的音乐
        if (musicNumber < musicLists.count)
        {
            //程序crash了
            playerController.nowPlayingItem = [mediaCollection.items objectAtIndex:songNumber];
            [playerController prepareToPlay];
            [playerController play];
            songNameLabel.text = [playerController.nowPlayingItem valueForProperty:MPMediaItemPropertyTitle];
        }
        else
        {
            NSLog(@"音乐无法播放!");
        }
        //播放控制器不能为空
        
    }
    达不到预期的效果,可以在这个代码基础上改一下或者另给办法,感激不尽!