如何使用AVPlayer在资产网址中播放mp3

时间:2014-03-27 11:34:49

标签: ios7 avfoundation avaudioplayer

我在ipod-library中有网址://item/item.mp3?id = 8788117795090152241 如何在这个网址中播放mp3

   AVPlayerItem *playerItem = [[AVPlayerItem alloc] initWithURL:url_selectedSong];
AVPlayer *player = [[AVPlayer alloc] initWithPlayerItem:playerItem];
[player play];

但不是播放歌曲

1 个答案:

答案 0 :(得分:1)

使用此:

NSError * error;
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];

if(player) {
    [player play];
}