damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

AVPlayer+Additions.swift (938B)


      1 //
      2 //  AVPlayer+Additions.swift
      3 //  damus
      4 //
      5 //  Created by Bryan Montz on 9/6/23.
      6 //
      7 
      8 import AVFoundation
      9 import Foundation
     10 import UIKit
     11 
     12 extension AVPlayer {
     13 #if !os(macOS)
     14     var currentImage: UIImage? {
     15         guard
     16             let playerItem = currentItem,
     17             let cgImage = try? AVAssetImageGenerator(asset: playerItem.asset).copyCGImage(at: currentTime(), actualTime: nil)
     18         else { return nil }
     19         
     20         return UIImage(cgImage: cgImage)
     21     }
     22 #else
     23     var currentImage: NSImage? {
     24         guard
     25             let playerItem = currentItem,
     26             let cgImage = try? AVAssetImageGenerator(asset: playerItem.asset).copyCGImage(at: currentTime(), actualTime: nil)
     27         else {
     28             return nil
     29         }
     30         let width: CGFloat = CGFloat(cgImage.width)
     31         let height: CGFloat = CGFloat(cgImage.height)
     32         return NSImage(cgImage: cgImage, size: NSMakeSize(width, height))
     33     }
     34 #endif
     35 }