AVPlayer无法播放远程MP3(iOS 8 beta 4)

时间:2014-08-02 07:17:11

标签: ios swift avplayer ios8

我已经在这里查看了很多解决方案,似乎归结为这两种播放远程MP3的方式:

用Swift编写(因为所有答案都在Objective-C中):

    let url = "http://megdadhashem.wapego.ru/files/56727/tubidy_mp3_e2afc5.mp3"
    let playerItem = AVPlayerItem(URL:NSURL(string:url))
    let player = AVPlayer(playerItem:playerItem)
    player.play()

    let fileData = NSData(contentsOfURL:NSURL(string:"http://megdadhashem.wapego.ru/files/56727/tubidy_mp3_e2afc5.mp3"))    
    let audioPlayer = AVAudioPlayer(data:fileData, error:nil)       
    audioPlayer.play()

但似乎都不起作用。我错过了什么吗?

1 个答案:

答案 0 :(得分:-1)

播放要在NSData中转换的文件。

 NSData  *audioData = [NSData dataWithContentsOfFile:filename];
 AVAudioPlayer *audio= [[AVAudioPlayer alloc] initWithData:audioData error:nil];
 self.player = audio;
 [[self player] play];