完成后如何再次播放相同的音频?现在我将这段代码与 AVPlayer 一起使用:
fileprivate func play () {
guard let url = URL(string: record.recordUrl) else { return }
let playItem = AVPlayerItem(url: url)
player.replaceCurrentItem(with: playItem)
NotificationCenter.default.addObserver(self, selector: #selector(playerDidFinishPlaying), name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: playItem)
player.play()
}
@objc func playerDidFinishPlaying(note: NSNotification) {
print("Player finished")
currentTimeSlider.setValue(0, animated: true)
currentTimeLabel.text = "00:00"
}
Run Code Online (Sandbox Code Playgroud)