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