音乐播放

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

- (void)prepareMusic:(NSUInteger)index{
 
    if (self.currentIndex != index) {
        self.currentIndex = index;
        // 获取当前音乐信息
        MusicInfo *musicInfo = [self getmusicInfoWithIndext:index];
        
        // 实例化一个PlayerItem作为Player的"CD"
        AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:[NSURL URLWithString:musicInfo.mp3Url]];
        
        // 替换当前的PlayerItem
        [self.player replaceCurrentItemWithPlayerItem:playerItem];
        
        // 安全判断
        if ([self.delegate respondsToSelector:@selector(didMusicCutWithMusicInfo:)]) {
            [self.delegate didMusicCutWithMusicInfo:musicInfo];
        }
    }else{
        
        
    }
}