Ios AudioPlayerDifinishPlaying的使用
就在我点击播放按钮的那一刻,我看到了结束,而不是声音播放完毕。我肯定我做错了什么。如何修复它?从play方法中删除以下语句 让hastheplayerdrended=audioplayerddinishplaying_u:player,successfully:true在这里调用函数audioplayerddinishplaying并成功传递:true作为参数,该参数在播放器播放时立即停止播放。Ios AudioPlayerDifinishPlaying的使用,ios,swift,xcode,Ios,Swift,Xcode,就在我点击播放按钮的那一刻,我看到了结束,而不是声音播放完毕。我肯定我做错了什么。如何修复它?从play方法中删除以下语句 让hastheplayerdrended=audioplayerddinishplaying_u:player,successfully:true在这里调用函数audioplayerddinishplaying并成功传递:true作为参数,该参数在播放器播放时立即停止播放。 class ViewController: UIViewController, AVAudioPl
class ViewController: UIViewController, AVAudioPlayerDelegate {
func audioPlayerDidFinishPlaying (_ player:AVAudioPlayer, successfully flag: Bool) {
endcheck.text = "end"
}
@IBAction func play(_ sender: Any) {
do
{
let url = Bundle.main.path (forResource: String(myIndex), ofType: "mp3")
try player = AVAudioPlayer (contentsOf: NSURL(fileURLWithPath: url!) as URL)
}
catch{
}
player.play()
let hasThePlayerEnded = audioPlayerDidFinishPlaying(_:player, successfully:true)
}
super.viewDidLoad()
self.player.delegate = self
}
let hasThePlayerEnded = audioPlayerDidFinishPlaying(_:player, successfully:true)