Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios AudioPlayerDifinishPlaying的使用_Ios_Swift_Xcode - Fatal编程技术网

Ios AudioPlayerDifinishPlaying的使用

Ios AudioPlayerDifinishPlaying的使用,ios,swift,xcode,Ios,Swift,Xcode,就在我点击播放按钮的那一刻,我看到了结束,而不是声音播放完毕。我肯定我做错了什么。如何修复它?从play方法中删除以下语句 让hastheplayerdrended=audioplayerddinishplaying_u:player,successfully:true在这里调用函数audioplayerddinishplaying并成功传递:true作为参数,该参数在播放器播放时立即停止播放。 class ViewController: UIViewController, AVAudioPl

就在我点击播放按钮的那一刻,我看到了结束,而不是声音播放完毕。我肯定我做错了什么。如何修复它?

从play方法中删除以下语句

让hastheplayerdrended=audioplayerddinishplaying_u:player,successfully:true在这里调用函数audioplayerddinishplaying并成功传递:true作为参数,该参数在播放器播放时立即停止播放。
 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)