我使用AVAudioPlayer,在我viewDidLoad中方法中,首先它的运行良好,但是当我再次来到同一个视图控制器的那首歌开始运行与最初的歌曲打成一片。如何检查AVAudioPlayer仍在运行?
,所以我试图找出是宋在后台运行?
这是我的职责,我调用这个函数在视图中做负载
func prepareAudio()
{
if audioPlayer.playing
{
audioPlayer.stop()
}
do
{
audioPlayer=try AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("Kids", ofType: ".mp3")!), fileTypeHint: AVFileTypeMPEGLayer3)
audioPlayer.delegate=self;
self.audioPlayer.play()
}
catch
{
print(error)
}
}
帮我找到解决方案这..
第二次尝试
第三尝试
第四尝试
您可以在此行设置断点。我猜你audioPlayer =零 –
是我audioplayer =零@CongTran –
所以你必须检查它是否=零&& .playing =真! - >调用stop()方法 –