gpt4 book ai didi

iphone - AVPlayer 在后台播放视频

转载 作者:行者123 更新时间:2023-12-03 21:17:15 27 4
gpt4 key购买 nike

我正在使用 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 会打印到控制台

我还需要添加其他内容吗?

最佳答案

只需添加 [[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; 和一些其他调整。都是here .

关于iphone - AVPlayer 在后台播放视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10478622/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com