作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我很难停止 AVPlayers 时间观察器。
我有一个像这样运行的 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 单步执行代码时,它起作用了。我可以看到该 block 停止打印出“观察者代码”
但是当我在没有断点的情况下正常运行代码时,我可以看到在调用 [player removeTimeObserver] 之后观察者仍在以相同的时间间隔运行。
有什么想法吗?
最佳答案
很高兴看到 weakSelf 为你工作......
在上面我没有看到你分配
的结果 [player addPeriodicTimeObserverForInterval ...
对于 self.timeObserver 来说,这可能是一个错字,但它应该是;
self.timeObserver = [player addPeriodicTimeObserverForInterval ...
如果你打算打电话
[player removeTimeObserver:self.timeObserver];
你也错过了“;”以上。
关于ios - 删除 periodicTimeObserver 的 AVPlayer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26068025/
我很难停止 AVPlayers 时间观察器。 我有一个像这样运行的 AVPlayer 播放器: player = [[AVPlayer alloc] initWithURL:[NSURL fileUR
我有一个 AVPlayer 的时间观察器,效果很好。我试图让它从音频 0 的持续时间开始倒计时。 它可以工作并且倒计时了,我只是在格式化方面遇到了一些问题。 如果你看到下面的图片,你就会明白我的意思。
我是一名优秀的程序员,十分优秀!