我現(xiàn)在在用AVAduioPlayer在后臺播放音效(白噪音軟件),然后應用是允許用戶設置播放時間的,但是當應用在后臺時,NSTimer的回調(diào)函數(shù)是不會被調(diào)用的,這個時候我該如何停止音效呢?代碼:-(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.}
如何讓音效在應用處于后臺狀態(tài)時自動停止
開滿天機
2019-04-23 15:12:49