如何在Swift中设置MediaPlayer播放速率?

时间:2018-07-14 01:22:21

标签: ios swift media-player

我正在尝试使用MediaPlayer降低/加快音乐的播放速度。更改.currentPlaybackRate实际上不会更改播放速率。我将如何正确执行此操作?

@IBAction func minusTempoButtonTapped(_ sender: Any) {
    mediaPlayer.currentPlaybackRate - 0.05
    songSpeedPercentage -= 5
    speedPercentageLabel.text = "\(songSpeedPercentage)%"

    if mediaPlayer.currentPlaybackRate == 0.25 || songSpeedPercentage == 25 {
        decreaseSpeedButton.isEnabled = false
    }

    increaseSpeedButton.isEnabled = true
}

@IBAction func increaseTempoButtonTapped(_ sender: Any) {
    mediaPlayer.currentPlaybackRate + 0.05
    songSpeedPercentage += 5
    speedPercentageLabel.text = "\(songSpeedPercentage)%"

    if mediaPlayer.currentPlaybackRate == 2.0 || songSpeedPercentage == 200 {
        increaseSpeedButton.isEnabled = false
    }

    decreaseSpeedButton.isEnabled = true
}

0 个答案:

没有答案