如何预加载来自网络链接的mp3流

时间:2015-08-22 20:47:56

标签: ios swift web mp3

我的歌曲是从mp3网站播放的,但是我需要预先加载歌曲,这样当我运行player.play()时,歌曲会立即开始,没有缓冲,也希望不会在整首歌曲中缓冲。有没有办法实现这一点,还是文件必须存储在本地?

override func viewDidLoad() {
    super.viewDidLoad()
    appDelegate = UIApplication.sharedApplication().delegate as? AppDelegate
    println(test_)
    timer = NSTimer.scheduledTimerWithTimeInterval(0.02, target: self, selector: "saveTime", userInfo: nil, repeats: true)
    appDelegate.mpcHandler.sendSongInfo()

    NPMusicClient.sharedClient().urlForSongWithQuery("\(artistName_) \(title_)", success: { (url) -> Void in
        AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, error: nil)
        AVAudioSession.sharedInstance().setActive(true, error: nil)

        self.player = AVPlayer(URL: url)

        self.player.play()

        }) { (message) -> Void in
            println(message)
    }

    startplaying()
    // Do any additional setup after loading the view.
    println(boolValue)
    functionLevel()




}

1 个答案:

答案 0 :(得分:0)

嘿伙计们,所以我自己找到了一个问题的答案,如果其他人正在考虑完成此操作,只需将播放器静音,因为歌曲会在播放时缓冲,然后回到0:00