0
我想在應用程序處於後臺時播放空的音頻文件來停止所有播放我嘗試了以下代碼,但未播放。如何在應用程序處於後臺模式時啓動歌曲
-(void)stop{
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
if(_viewController.checkIpod==0){
AVAudioPlayer *playerA = [[AVAudioPlayer alloc]
initWithContentsOfURL:[NSURL fileURLWithPath:
[[NSBundle mainBundle] pathForResource:@"2sec" ofType:@"mp3"]]
error:nil];
[playerA play];
//[player close];
_viewController.onceClosed=1;
NSLog(@"Oneclosed=1");
}
else{
//[self.musicPlayer play];
[_viewController.musicPlayer pause];
[_viewController.playerA play];
NSLog(@"closing and playing the sound");
}
}
我把這個代碼在beginBackgroundTaskWithExpirationHandler 請幫
作爲一個用戶,這會讓我瘋狂。我不想在後臺播放任何空的音頻文件。 – dasdom
它會關閉所有的播放 –