gpt4 book ai didi

swift - iOS 8,AVPlayer背景音乐播放,remoteControlReceivedWithEvent未调用

转载 作者:行者123 更新时间:2023-11-30 10:14:02 24 4
gpt4 key购买 nike

我想在我的应用程序中播放声音(使用 swift),在 didFinishLaunchingWithOptions 函数中我写了这个

AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, error: nil)
AVAudioSession.sharedInstance().setActive(true, error: nil)

我有一个包含 AVPlayerUIView

我用过:

UIApplication.sharedApplication().beginReceivingRemoteControlEvents()
self.becomeFirstResponder()

remoteControlReceivedWithEvent函数。当应用程序进入后台时,声音继续播放,但是当我单击暂停按钮(我们用它来播放和暂停应用程序外部的声音)时,remoteControlReceivedWithEvent永远不会被调用!

怎么了?

最佳答案

在我的项目中:我在 UITabbarViewController

中调用它
-(BOOL)canBecomeFirstResponder{
return YES;
}
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
}

确保它可以成为第一响应者。 remoteControlReceivedWithEvent in AVAudio is not being called

关于swift - iOS 8,AVPlayer背景音乐播放,remoteControlReceivedWithEvent未调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31227861/

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