3
我很難停止AVPlayers時間觀察者。AVPlayer刪除periodicTimeObserver
我有一個AVPlayer播放器中運行是這樣的:
player = [[AVPlayer alloc] initWithURL:[NSURL fileURLWithPath:path]];
然後我添加一個觀察者
[player addPeriodicTimeObserverForInterval:CMTimeMake(3, 10) queue:NULL usingBlock:^(CMTime time){
NSTimeInterval seconds = CMTimeGetSeconds(time);
NSLog(@"observer called");
for (NSDictionary *item in robotR33) {
NSNumber *time = item[@"time"];
if (seconds > [time doubleValue] && [time doubleValue] >= [lastTime doubleValue]) {
// NSLog(@"LastTime: %qi", [lastTime longLongValue]);
lastTime = @(seconds);
NSString *str = item[@"line"];
[weakSelf nextLine:str];
// NSLog(@"item: %qi", [time longLongValue]);
// NSLog(@"Seconds: %f", seconds)
};
}
}];
[player play];
一次,我與球員完成了我這樣做:
[player pause];
[player removeTimeObserver:self.timeObserver]
player = nil;
奇怪的是,當我在代碼中放置一個斷點並使用XCode執行代碼時,它會起作用。我可以看到塊停止打印「觀察員代碼」
但是,當我正常運行代碼而沒有斷點時,我可以看到觀察者仍在以相同的間隔運行[player removeTimeObserver]後被調用。
任何想法?
嗨是兩個計數感謝。這不是一個錯字,但已經發現我的錯誤。很高興有記錄在這裏,但。再次感謝。 – 2014-09-29 13:38:47