Why AVPlayer downloading first instead live streaming?

有些话、适合烂在心里 提交于 2019-12-21 09:26:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!