我正在尝试这段代码,但是progressView的移动速度并不慢,并不会根据文件的持续时间来
请告诉我如何根据音频文件的持续时间移动progressView。我正在updateProgress函数中更新progressView。我已经尝试了所有解决方案,但没有根据需要获得输出。
func updateProgress(){
progressView.setProgress(duration, animated: true)
}
var path : String?
path = Bundle.main.path(forResource: "cartoon001", ofType: "wav")
let url = URL(fileURLWithPath: path!)
//Audios/number\(fileNumber)
do {
player = try AVAudioPlayer(contentsOf: url)
if player != nil {
player!.delegate = self
player!.pan = channelValue
player!.volume = 1
if micLocation == .front {
player!.numberOfLoops = 5
duration = Float((player?.duration)! * 5)
}
else {
player!.numberOfLoops = 3
duration = Float((player?.duration)! * 3)
}
player!.prepareToPlay()
player!.play()
//progressView.progress = Float(player?.duration)
}
}