【问题标题】:How to get thumbnail image from .m3u8 formate video url in Swift?如何从 Swift 中的 .m3u8 格式视频 url 获取缩略图?
【发布时间】:2019-06-19 06:07:27
【问题描述】:
func getThumbnailFrom(path: URL?, withCompletionHandler completion:@escaping ((UIImage)-> Void)){
        var thumbnail = UIImage(named: "name of Dummy Image")

        if let url = path{
            DispatchQueue.global(qos: .background).async {
                do{
                    let asset = AVURLAsset(url: url , options: nil)
                    let imgGenerator = AVAssetImageGenerator(asset: asset)
                    imgGenerator.appliesPreferredTrackTransform = true
                    let cgImage = try imgGenerator.copyCGImage(at: CMTimeMake(value: 500,timescale: 30), actualTime: nil)
                    thumbnail = UIImage(cgImage: cgImage)
                    completion(thumbnail!)
                }catch let error{
                      print(error.localizedDescription)
                }
            }
        }
    completion(thumbnail!)
    }

Used it as 

    getThumbnailFrom(path: URL(string: "https://p-events-delivery.akamaized.net/18oijbasfvuhbfsdvoijhbsdfvljkb6/m3u8/hls_vod_mvp.m3u8")!, withCompletionHandler: { (image) in DispatchQueue.main.async(execute: { self.imagePreview.image = image }) })

也可以试试https://github.com/acotilla91/ACThumbnailGenerator-Swift 但是在这个唯一的演示链接中是有效的

有什么解决办法吗?

提前致谢。

【问题讨论】:

    标签: ios swift tvos avplayeritem


    【解决方案1】:

    如果你打算使用ACThumbnailGenerator-Swift而不是在Info.plist中添加NSAppTransportSecurity

    【讨论】:

      猜你喜欢
      • 2020-05-16
      • 2011-05-25
      • 2018-03-25
      • 2011-06-18
      • 2012-02-02
      • 2023-03-22
      • 1970-01-01
      • 2020-10-18
      • 2016-09-17
      相关资源
      最近更新 更多