如何使用AVPlayer NOT AVAudioPlayer在swift中创建的mp3播放器中添加进度条

时间:2016-07-16 08:32:55

标签: swift

这里是我的代码,如何从现场网址播放我的mp3我只是找不到任何更新的信息,快速使用avplayer而不是avaudioplayer ..提前感谢所有评论和帮助

var playerItem:AVPlayerItem?
var player = AVPlayer()

  var error : NSError?
    var sucess : Bool?
    do{
       try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback,withOptions: .DefaultToSpeaker)
        _ =  try AVAudioSession.sharedInstance().setActive(true)

        sucess = true

    } catch let NotSucessError as NSError{error = NotSucessError
        sucess = false}

    if !sucess! {
        NSLog("Fail to set audio session. Error:\(error)")
    }

    let url = NSURL(string: trackURL)
    playerItem = AVPlayerItem(URL: url!)
    player = AVPlayer(playerItem: playerItem!)
    player.play()

0 个答案:

没有答案