我有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