gpt4 book ai didi

ios - AVURLAsset URLAssetWithURL :options: blocks main thread with remote URL?

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:58:36 51 4
gpt4 key购买 nike

我没有找到关于这个的文档,但是根据我的实践经验

AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil];

(其中 url 是 HLS 直播流的远程 URL),如果网络中断或由于某种原因无法读取文件,将阻塞主线程。

有没有其他人注意到这一点?我可能最终会更改我的设置以使用 GCD 在后台线程上构建。因为一旦无法加载视频,用户界面就会锁定。

AVPlayerItem 异步加载东西,但 AVURLAsset 似乎没有这样做。

最佳答案

也有这个问题。用以下方法解决:

let asset = AVURLAsset(url: url)

// I'm using a resource loader for my custom urls...
let loaderQueue = DispatchQueue(label: "loader-queue", qos: .userInteractive)
asset.resourceLoader.setDelegate(self, queue: self.loaderQueue)

// load values asynchronously and once complete, create the player item
let keys = ["duration", "tracks"]
asset.loadValuesAsynchronously(forKeys: keys, completionHandler: {
let item = AVPlayerItem(asset: asset)
self.player.insert(item, after: nil)
})

关于ios - AVURLAsset URLAssetWithURL :options: blocks main thread with remote URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38777384/

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