静音开关和无线电流(背景也)

时间:2012-07-17 09:23:05

标签: iphone objective-c ios

我创建简单的应用来流式传输音频。它与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

0 个答案:

没有答案