问题
First time I am working with AVPlayer and I want to play a mp3 file using HTTP request with live streaming. I use AVPlayer
that is working fine to play mp3 files, but the problem is AVPlayer
needs to download the mp3 first then play it. I don't know why AVPlayer
downloads the file and then play it instead of live playing. My Xcode 8.2.1 and I am using Swift 3.
Here is my code snippet.
var audioPlayer = AVPlayer()
var avplayerItem : AVPlayerItem?
override func viewDidLoad() {
super.viewDidLoad()
let fileurl:URL = URL(string : "http://www.noiseaddicts.com/samples_1w72b820/2514.mp3")!
avplayerItem = AVPlayerItem(url : fileurl)
audioPlayer = AVPlayer(playerItem : avplayerItem)
audioPlayer.rate = 1.0
audioPlayer.play()
}
In case of AVPlayer
requires to download the whole file before playing it, what should I do for audio live streaming?
Thanks.
来源:https://stackoverflow.com/questions/41542841/why-avplayer-downloading-first-instead-live-streaming