我使用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