使用AVAssetKeys下的tracks作为键并调用loadValuesAsynchronously完成处理程序。
示例代码:
guard let url = URL(string: "YOUR_M3U8_URL_HERE") else { return } let asset = AVAsset(url: url) let keys = ["tracks"]
asset.loadValuesAsynchronously(forKeys: keys) { var error: NSError? = nil let status = asset.statusOfValue(forKey: "tracks", error: &error)
// Continue with tracks when loaded successfully
if status == .loaded {
// Access tracks here
if let tracks = asset.tracks {
// Do something with tracks
}
}
}