gpt4 book ai didi

ios - AVPlayer removeTimeObserver 使应用程序崩溃(swift 3)

转载 作者:搜寻专家 更新时间:2023-11-01 05:50:15 25 4
gpt4 key购买 nike

我将全局变量时间观察器设置为:

self.timeObserver = self.avPlayer?.addPeriodicTimeObserver(forInterval: CMTime(seconds: 0.5, preferredTimescale: CMTimeScale(NSEC_PER_SEC)), queue: DispatchQueue.main) { [weak self] time in
guard let weakSelf = self else {
return
}
// updating label with time
}

当 View 关闭时,我调用:

if self.avPlayer != nil {
self.avPlayer!.removeTimeObserver(self.timeObserver)
}

但这会使应用程序崩溃并提示:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'You did not supply a reference to an object returned by either -addPeriodicTimeObserverForInterval:queue:usingBlock: or -addBoundaryTimeObserverForTimes:queue:usingBlock:'

请告诉我我做错了什么?谢谢你

最佳答案

你必须打开self.timeObserver

removeTimeObserver() 接收 Any 对象,但您传入的是 Any?,这会导致崩溃。

关于ios - AVPlayer removeTimeObserver 使应用程序崩溃(swift 3),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40243119/

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