我已经在这里查看了很多解决方案,似乎归结为这两种播放远程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()
但似乎都不起作用。我错过了什么吗?
答案 0 :(得分:-1)
播放要在NSData中转换的文件。
NSData *audioData = [NSData dataWithContentsOfFile:filename];
AVAudioPlayer *audio= [[AVAudioPlayer alloc] initWithData:audioData error:nil];
self.player = audio;
[[self player] play];