作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我没有找到关于这个的文档,但是根据我的实践经验
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/
我有一个 iOS 应用程序,它使用应用程序中录制并保存的许多不同的音频文件。我已经导入了 AVFoundation 框架,但是我仍然收到错误: No known class method for se
我没有找到关于这个的文档,但是根据我的实践经验 AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil]; (其中 url 是
我是一名优秀的程序员,十分优秀!