我创建简单的应用来流式传输音频。它与Volume Buttons完美配合。以后台模式播放。但当我切换“静音开关”音乐仍然播放。为什么呢?
- (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