问题描述
我有一些结构。他们获取 mp3 文件的 URL,并以秒为单位计算文件的持续时间。
struct Track: Decodable {
var previewUrl: String?
var durationInSeconds: Double? {
if let previewUrl = previewUrl {
guard let url = URL(string: previewUrl) else { return nil }
let asset = AVURLAsset(url: url,options: nil)
let audioDuration = asset.duration
let audioDurationSeconds = CMTimeGetSeconds(audioDuration)
return audioDurationSeconds
}
return nil
}
}
这很好用,但是如果我将此计算属性粘贴到 UITableView“cellForRowAt”方法中,例如:
func tableView(_ tableView: UITableView,cellForRowAt indexPath: IndexPath) {
// create cell and Track instance
...
print(trackInstance.durationInSeconds ?? 0)
...
}
我在滚动 tableView 时冻结了 UI。我正在尝试使用 dispathQueue.main.async 进行打印,但它不起作用。
在这种情况下如何避免冻结?谢谢
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)