我有1个控制器。首先我开始播放audio1。我使用此代码:暂停并使用AVAudioSession播放音频
- (void)viewDidLoad
{
//code to not turn off audio with using mute switch
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive: NO error: nil];
//code to play audio
NSString *soundFilePath = [NSString stringWithFormat:@"%@/%@.mp3",[[NSBundle mainBundle] resourcePath], @"sound"];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
_player = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:nil];
_player.numberOfLoops = -1;
[_player play];
}
但是,当我隐藏我的应用程序音频没有暂停。当我隐藏我的应用程序并在应用程序到达前台时暂停点播放时,我想暂停音频。怎么做?
的可能的复制[播放/用相同的按钮\暂停[AVAudioPlayer \]](https://stackoverflow.com/questions/6635604/play-pause-with-the-same-button-avaudioplayer) – kb920