Iphone AVPlayer在后台播放视频
我正在使用AVPlayer在我的应用程序中播放视频,现在我想让视频在后台模式下播放 这是我在Iphone AVPlayer在后台播放视频,iphone,objective-c,Iphone,Objective C,我正在使用AVPlayer在我的应用程序中播放视频,现在我想让视频在后台模式下播放 这是我在-(BOOL)应用程序中输入的内容:(UIApplication*)应用程序使用选项完成启动:(NSDictionary*)启动选项: [[AVAudioSession sharedInstance] setDelegate: self]; [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback err
-(BOOL)应用程序中输入的内容:(UIApplication*)应用程序使用选项完成启动:(NSDictionary*)启动选项
:
[[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将打印到控制台
是否需要添加其他内容?只需添加
[[UIApplication sharedApplication]开始接收RemoteControlEvents]代码>和其他一些调整。就这些。点击这个链接:等等。这有效吗?视频在后台工作?从互联网上的嘈杂声中,我认为在iOS上不可能有背景视频@MTA,如果可能,请确认。@dev我可以确认它工作正常。您需要锁定设备,而不是按home(主页)按钮。您还可以支持注册UIApplicationIdentinterBackgroundNotification
的主页按钮,并使用计时器重新启动视频,您会有一点延迟(褪色),但这总比什么都没有好。我已经回答了有关如何实现所需结果的完整详细问题。指向解释的链接已断开