我创建了简单的应用程序来流式传输音频。它与音量按钮完美配合。在后台模式下播放。但是当我切换“静音开关”时,音乐仍然播放。为什么?
- (void)viewDidLoad
{
[super viewDidLoad];
self.player = [AVPlayer playerWithURL:[NSURL URLWithString:@"http://87.98.235.103:9768/"]];
}
- (void)viewDidUnload
{
[self setPlayBtn:nil];
[self setStopBtn:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (IBAction)pressedPlay:(id)sender {
[self.player play];
}
- (IBAction)pressedStop:(id)sender {
[self.player pause];
}
在应用程序 didFinishLaunching 中:
NSError *sessionError = nil;
[[AVAudioSession sharedInstance] setDelegate:self];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:&sessionError];
UInt32 doChangeDefaultRoute = 1;
AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryDefaultToSpeaker, sizeof(doChangeDefaultRoute), &doChangeDefaultRoute);
在 plist 我有:
Required background modes: App plays audio