音乐播放

2019PHP高薪工程师学习路线图....>>>

- (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{
        
        
    }
}