gpt4 book ai didi

objective-c - 如何手动中断 AVPlayer 来电

转载 作者:搜寻专家 更新时间:2023-10-30 20:18:43 29 4
gpt4 key购买 nike

我用过这个方法How do I get my AVPlayer to play while app is in background?让 AVPlayer 在后台播放,以便用户可以在浏览 safari 等时收听。现在唯一的问题是 AVPlayer 在有来电时继续播放,并在通话期间保持播放。有没有办法捕获来电和结束通话事件,以便可以手动停止和启动 AVPlayer?

最佳答案

通过coreTelephony 框架,我们必须找到或检测来电。从那里你必须启动你的本地通知来停止你的 AVPlayer。导入后这样做

     CTCallCenter * _callCenter = [[CTCallCenter alloc] init];
_callCenter.callEventHandler = ^(CTCall* call)
{

if ([call.callState isEqualToString:CTCallStateDisconnected])
{
NSLog(@"Call has been disconnected");
}
else if([call.callState isEqualToString:CTCallStateDialing])
{
NSLog(@"Call start");
}
else if ([call.callState isEqualToString:CTCallStateConnected])
{

NSLog(@"Call has just been connected");
}
else if([call.callState isEqualToString:CTCallStateIncoming])
{
NSLog(@"Call is incoming");
// You have to initiate/post your local notification through NSNotification center like this
[[NSNotificationCenter defaultCenter] postNotificationName:@"stopAVPlayer" object:nil];
} else
{
NSLog(@"None of the conditions");
}


};

引用这个:https://developer.apple.com/library/ios/navigation/#section=Frameworks&topic=CoreTelephony

关于objective-c - 如何手动中断 AVPlayer 来电,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19287080/

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