AVPlayerを使用してアプリでビデオを再生していますが、ビデオをバックグラウンドモードで再生させたいと考えています。
これは私が入れたもの- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
です:
[[AVAudioSession sharedInstance] setDelegate: self];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
そして私もplistに追加します:必要なバックグラウンドモード->アプリはオーディオを再生します
私もこれを追加します:
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
}
- (BOOL)canBecomeFirstResponder {
return YES;
}
- (void)remoteControlReceivedWithEvent:(UIEvent *)event {
switch (event.subtype) {
case UIEventSubtypeRemoteControlTogglePlayPause:
NSLog(@"4");
break;
case UIEventSubtypeRemoteControlPlay:
break;
case UIEventSubtypeRemoteControlPause:
NSLog(@"3");
break;
case UIEventSubtypeRemoteControlNextTrack:
NSLog(@"2");
break;
case UIEventSubtypeRemoteControlPreviousTrack:
NSLog(@"1");
break;
default:
break;
}
}
そして、アプリをバックグラウンドに移動してボタンを押すと、nslogがコンソールに出力します
他に何か追加する必要がありましたか?