我使用AVPlayer在我的應用中播放視頻,現在我想讓視頻在後臺模式下播放。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打印到控制檯時
我需要添加其他東西嗎?
請點擊此鏈接: http://stackoverflow.com/questions/4771105/how-do-i-get-my-avplayer-to-play-while-app-is-in-background – iMash