我現(xiàn)在在用AVAduioPlayer在后臺(tái)播放音效(白噪音軟件),然后應(yīng)用是允許用戶設(shè)置播放時(shí)間的,但是當(dāng)應(yīng)用在后臺(tái)時(shí),NSTimer的回調(diào)函數(shù)是不會(huì)被調(diào)用的,這個(gè)時(shí)候我該如何停止音效呢?代碼:-(void)play:(NSString*)soundNamewithTime:(NSNumber*)time{NSURL*soundUrl=[NSURLfileURLWithPath:[NSStringstringWithFormat:@"%@/sounds/%@.m4a",[[NSBundlemainBundle]resourcePath],soundName]];_audioPlayer=[[AVAudioPlayeralloc]initWithContentsOfURL:soundUrlerror:nil];_audioPlayer.numberOfLoops=-1;[_audioPlayerplay];[[AVAudioSessionsharedInstance]setCategory:AVAudioSessionCategoryPlaybackerror:nil];[[AVAudioSessionsharedInstance]setActive:YESerror:nil];[selfscheduleStopSound:time];//howtoimplementit.}
如何讓音效在應(yīng)用處于后臺(tái)狀態(tài)時(shí)自動(dòng)停止
DIEA
2019-04-21 20:40:05