Swift - 作为UISlider的MPMusicPlayer播放进度

时间:2015-05-26 11:13:44

标签: ios iphone swift uislider mpmusicplayercontroller

我有问题将UISlider动画化为MPMusicPlayer播放进度。我见过许多帖子在obj-c和AVAudioPlayer上完成了这个。

我试过这个:

func startTimer(){
    if timer == nil {
        timer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: Selector("update:"), userInfo: nil,repeats: true)
        timer.fire()
    }
}

func stopTimer(){
    timer.invalidate()

}


func update(timer: NSTimer){
     if myMusicPlayer?.playbackState == MPMusicPlaybackState.Playing{
        return
    }

    var minute_ = abs(Int((myMusicPlayer!.currentPlaybackTime / 60) % 60))
    var second_ = abs(Int(myMusicPlayer!.currentPlaybackTime  % 60))

    var minute = minute_ > 9 ? "\(minute_)" : "0\(minute_)"
    var second = second_ > 9 ? "\(second_)" : "0\(second_)"

    progressTimerLabel.text  = "\(minute):\(second)"
    progressBar.value = CFloat(myMusicPlayer!.currentPlaybackTime)

}

ProgressBar是我的UISlider。

我播放音频时调用了startTimer(),但它仍然没有动画效果。我能做什么让它为UISlider设置动画?

0 个答案:

没有答案