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
它会关闭所有的播放 –