我正在尝试使用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
}