gpt4 book ai didi

iphone - 即使离开 View ,音频文件也会继续播放

转载 作者:行者123 更新时间:2023-12-03 20:56:40 25 4
gpt4 key购买 nike

我正在做的是

-(void)viewWillAppear:(BOOL)animated{

[NSTimer scheduledTimerWithTimeInterval:0.3 target:self selector:@selector(clickEvent:) userInfo:nil repeats:YES];
}

-(void)clickEvent:(NSTimer *)aTimer{

NSDate* finishDate = [NSDate date];

if([finishDate timeIntervalSinceDate: self.startDate] > 11 && touched == NO){

NSString *mp3Path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"test.mp3"];
[self playMusicFile:mp3Path];
NSLog(@"Timer from First Page");
[aTimer invalidate];
//[touchCheckTimer release];
aTimer = nil;

}

else{


}

-(void)playMusicFile:(NSString *)mp3Path{

NSURL *mp3Url = [NSURL fileURLWithPath:mp3Path];
NSError *err;
AVAudioPlayer *audPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:mp3Url error:&err];
[self setAudioPlayer1:audPlayer];
if(audioPlayer1)
[audioPlayer1 play];

[audPlayer release];

}

现在,在推送另一个 View 时,该音频文件将继续在后台播放。请帮忙!

最佳答案

这是一个很常见的错误

当您离开 View 时,在用于播放音频的 AVAudioPlayer 变量指针上调用 stop 方法

关于iphone - 即使离开 View ,音频文件也会继续播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4676599/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com