ios - 如何预加载来自 Web 链接的 mp3 流

标签 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()




}

最佳答案

嘿,大家好,我自己找到了问题的答案,简单地说,如果其他人正在考虑实现此目的,只需将播放器静音,因为歌曲在播放时会缓冲,然后返回 0:00

关于ios - 如何预加载来自 Web 链接的 mp3 流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32160627/

相关文章:

ios - 为什么我的 Tab Bar 没有出现在模拟器中?

java - 无法在 Eclipse 工作区中配置 Web 应用程序项目的运行路径

css - 单击播放时如何使网站上的嵌入式 youtube 视频帧膨胀?

ios - Swift - 只能打印对象的内存地址

ios - Xcode 10服务器:React Native RCTWebSocket libfishook.a删除并再次添加

ios - Apple 是否在 Swift 中弃用了 iPhone 3D touch?

ios - 具有多种字体颜色的 UILabel 文本

ios - 如何显示不带0的字符串

javascript - google.com 如何将选项卡焦点放在不可聚焦的元素上

ios - 在 iOS7 中 "main" View 下的元素存储(弱或强)