Ios AVPlayerPeriodicCaller崩溃
我要崩溃了,我不知道是什么原因造成的。以下是我从坠机报告中得到的信息:Ios AVPlayerPeriodicCaller崩溃,ios,avfoundation,Ios,Avfoundation,我要崩溃了,我不知道是什么原因造成的。以下是我从坠机报告中得到的信息: Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000c Triggered by Thread: 0 Thread 0 Crashed: 0 AVFoundation 0x2f271946 -[AVPlayerPeriodicCaller _ef
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000c
Triggered by Thread: 0
Thread 0 Crashed:
0 AVFoundation 0x2f271946 -[AVPlayerPeriodicCaller _effectiveRateChanged] + 418
1 AVFoundation 0x2f270fc8 __43-[AVPlayerTimelyCaller _timebaseDidChange:]_block_invoke + 232
2 libdispatch.dylib 0x3b04ed50 _dispatch_call_block_and_release + 8
3 libdispatch.dylib 0x3b04ed3c _dispatch_client_callout + 20
4 libdispatch.dylib 0x3b0516be _dispatch_main_queue_callback_4CF + 274
5 CoreFoundation 0x3039b674 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 4
6 CoreFoundation 0x30399f40 __CFRunLoopRun + 1304
7 CoreFoundation 0x303047a4 CFRunLoopRunSpecific + 520
8 CoreFoundation 0x30304586 CFRunLoopRunInMode + 102
9 GraphicsServices 0x352716ce GSEventRunModal + 134
10 UIKit 0x32c6388c UIApplicationMain + 1132
11 my-app 0x00029dd4 main (main.m:16)
12 libdyld.dylib 0x3b063ab4 start + 0
据我所知,它来自addPeriodicTimeObserverForInterval:queue:usingBlock:
,所以我总是检查block和queue是否正确。还有什么会导致这种情况
提前谢谢
更新:
下面是调用addPeriodicTimeObserverForInterval:queue:usingBlock:
- (void)addPeriodicTimeObserverForInterval:(CMTime)interval queue:(dispatch_queue_t)queue usingBlock:(void (^)(CMTime time))block
{
[block copy];
dispatch_async(self.operationQueue, ^{
//This method just makes sure, that self.player not nil
[self someMethodcompletionHandler:^{
if (self.observer) {
[self.player removeTimeObserver:self.observer];
self.observer = nil;
}
if (block && queue) {
self.observer = [self.player addPeriodicTimeObserverForInterval:interval
queue:queue
usingBlock:block];
}
}];
});
}
更新2:
我想出来了。但我不知道,为什么会这样。那么我的问题是,为什么它会起作用?为什么self.operationQueue
比仅仅queue
更好
self.observer = [self.player addPeriodicTimeObserverForInterval:interval
queue:self.operationQueue
usingBlock:^(CMTime time){
dispatch_async(queue, ^{
block(time);
});
}];
官方
AVPlayer
文档说明:
在不调用removeTimeObserver:的情况下释放observer对象将导致未定义的行为
这意味着您应该保留从addPeriodicTimeObserverForInterval:queue:usingBlock:
返回的值,并且在释放观察者块之前,确保调用removeTimeObserver:
还请注意,默认情况下,块对象是在堆栈上分配的(而不是在堆上),因此为了确保在帧结束时块不会被释放,您应该通过调用copy来保留块。
要了解有关块内存管理的更多信息,请参阅 我试着检查了所有这些。我用方法更新了我的问题,该方法调用addPeriodicTimeObserverForInterval:queue:usingBlock:,您能看一下吗?保留对复制的块的引用,并在注册块时使用它:
void(^myBlock)(CMTime)=^void(CMTime){…}代码>如果这不起作用,请同时发布创建队列的代码。我知道了,但我不明白为什么它现在起作用。无论如何,谢谢你的帮助。你能详细说明一下什么是self.operationQueue
?什么是自我?