AVPlayer在后台播放视频

编程入门 行业动态 更新时间:2024-10-23 08:38:16
本文介绍了AVPlayer在后台播放视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用AVPlayer在我的应用中播放视频,现在我想让该视频在后台模式下播放.

I am using AVPlayer to play a video in my app,now i want to let the video play in background mode.

这就是我放入的- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions:

[[AVAudioSession sharedInstance] setDelegate: self]; [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];

,我也添加到plist中: 所需的背景模式->应用播放音频

and i also add to the plist: Required background modes -> App plays audio

我也添加了它:

-(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将打印到控制台

And when i move the app to the background and press the buttons the nslog print to the console

我需要添加其他内容吗?

Did i need to add something else?

推荐答案

只需添加[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];和其他一些调整即可.都是此处.

Just add [[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; and some other tweaks. It's all here.

更多推荐

AVPlayer在后台播放视频

本文发布于:2023-11-27 03:18:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636349.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:后台   视频   AVPlayer

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!