アプリケーションがバックグラウンドに移行した後、SoloAmbient を設定したい (iPhone のすべての音楽を無音にしたい)。
こんなコード書いたけど動かない
MyAppDelegate.h
@interface MyAppDelegate : UIResponder <UIApplicationDelegate> {
AVAudioSession *audioSession;
}
@property (strong, nonatomic) AVAudioSession *audioSession;
MyAppDelegate.m
- (void)applicationDidEnterBackground:(UIApplication *)application {
NSLog(@"Application entered background state.");
//[self.DelcloseSession setCategory:AVAudioSessionCategorySoloAmbient error:nil];
//[self.DelcloseSession setActive:YES error:nil];
audioSession = [AVAudioSession sharedInstance];
[audioSession setDelegate:self];
NSError *averr = nil;
[audioSession setCategory:AVAudioSessionCategoryPlayback error:&averr];
if(averr)
{
NSLog(@"audioSession: %@ %d %@", [averr domain], [averr code], [[averr userInfo] description]);
}
averr = nil;
[audioSession setActive:YES error:&averr];
if(averr)
{
NSLog(@"audioSession: %@ %d %@", [averr domain], [averr code], [[averr userInfo] description]);
}
averr = nil;
[audioSession setCategory:AVAudioSessionCategorySoloAmbient error:&averr];
if(averr)
{
NSLog(@"audioSession: %@ %d %@", [averr domain], [averr code], [[averr userInfo] description]);
}
実際には、アプリはログ「audioSession: NSOSStatusErrorDomain 560161140 (null)」を送信し、iPhone の音楽 (iPod または他のアプリから) はまだ再生されています。
修正方法は?アプリがバックグラウンドに移動したときに、SoloAmbient を開いてすべてを無音にする方法を教えてください。たぶん、音楽を眠らせる機会は他にありますか?