//
//  videoURL.swift
//  wallpaper_project
//
//  Created by 忆海16 on 2024/3/12.
//

//import Foundation
//import EZPlayer
//import AVFoundation
//
//
//struct MediaItem {
//    var url: URL?
//    var title: String?
//}
//
//class MediaManager {
//     var player: EZPlayer?
//     var mediaItem: MediaItem?
//     var embeddedContentView: UIView?
//
//    static let sharedInstance = MediaManager()
//    private init(){
//
//        NotificationCenter.default.addObserver(self, selector: #selector(self.playerDidPlayToEnd(_:)), name: .EZPlayerPlaybackDidFinish, object: nil)
//
//    }
//
//    func playEmbeddedVideo(url: URL, embeddedContentView contentView: UIView? = nil, userinfo: [AnyHashable : Any]? = nil) {
//        var mediaItem = MediaItem()
//        mediaItem.url = url
//        self.playEmbeddedVideo(mediaItem: mediaItem, embeddedContentView: contentView, userinfo: userinfo )
//
//    }
//
//    func playEmbeddedVideo(mediaItem: MediaItem, embeddedContentView contentView: UIView? = nil , userinfo: [AnyHashable : Any]? = nil ) {
//        //stop
//        self.releasePlayer()
//
//        if let skinView = userinfo?["skin"] as? UIView{
//         self.player =  EZPlayer(controlView: skinView)
//        }else{
//          self.player = EZPlayer()
//        }
//        
//
//        self.player!.slideTrigger = (left:EZPlayerSlideTrigger.none,right:EZPlayerSlideTrigger.none)
//
//        if let autoPlay = userinfo?["autoPlay"] as? Bool{
//            self.player!.autoPlay = autoPlay
//        }
//
//        if let floatMode = userinfo?["floatMode"] as? EZPlayerFloatMode{
//            self.player!.floatMode = floatMode
//        }
//
//        if let fullScreenMode = userinfo?["fullScreenMode"] as? EZPlayerFullScreenMode{
//            self.player!.fullScreenMode = fullScreenMode
//        }
//
//        self.player!.backButtonBlock = { fromDisplayMode in
//            if fromDisplayMode == .embedded {
//                self.releasePlayer()
//            }else if fromDisplayMode == .fullscreen {
//                if self.embeddedContentView == nil && self.player!.lastDisplayMode != .float{
//                    self.releasePlayer()
//                }
//
//            }else if fromDisplayMode == .float {
//                if self.player!.lastDisplayMode == .none{
//                    self.releasePlayer()
//                }
//            }
//
//        }
//
//        self.embeddedContentView = contentView
//
//        self.player!.playWithURL(mediaItem.url! , embeddedContentView: self.embeddedContentView)
//    }
//
//
//
//
//    func releasePlayer(){
//        self.player?.stop()
////        self.player?.view.removeFromSuperview()
//
//        self.player = nil
////        self.embeddedContentView = nil
////        self.mediaItem = nil
//
//    }
//
//    @objc  func playerDidPlayToEnd(_ notifiaction: Notification) {
//       //结束播放关闭播放器
////       self.releasePlayer()
////        self.player.resetPlayer()
//    }
//
//
//
//
//}
//
//func convertMP4ToMOV(inputURL: URL, outputURL: URL, completion: @escaping (URL?, Error?) -> Void) {
//    let asset = AVAsset(url: inputURL)
//    
//    guard let exportSession = AVAssetExportSession(asset: asset, presetName: AVAssetExportPresetPassthrough) else {
//        completion(nil, NSError(domain: "com.example", code: 0, userInfo: [NSLocalizedDescriptionKey: "Failed to create export session"]))
//        return
//    }
//    
//    exportSession.outputURL = outputURL
//    exportSession.outputFileType = .mov
//    
//    exportSession.exportAsynchronously {
//        switch exportSession.status {
//        case .completed:
//            completion(outputURL, nil)
//        case .failed:
//            completion(nil, exportSession.error)
//        case .cancelled:
//            completion(nil, NSError(domain: "com.example", code: 0, userInfo: [NSLocalizedDescriptionKey: "Export session cancelled"]))
//        default:
//            break
//        }
//    }
//}
//






//    func loadLivePhoto() {
//        // 从相册加载Live Photo
//        let fetchOptions = PHFetchOptions()
//        fetchOptions.predicate = NSPredicate(format: "mediaType = %d", PHAssetMediaType.image.rawValue)
//        let fetchResult = PHAsset.fetchAssets(with: fetchOptions)
//
//        if let asset = fetchResult.firstObject {
//            PHImageManager.default().requestLivePhoto(for: asset, targetSize: CGSize(width: 300, height: 300), contentMode: .aspectFit, options: nil) { (livePhoto, info) in
//                DispatchQueue.main.async {
//                    // 展示Live Photo
//                    // Assuming you have IBOutlet connection to a PHLivePhotoView named livePhotoView
//                    let livePhotoView = PHLivePhotoView(frame: self.view.bounds)
//                    livePhotoView.livePhoto = livePhoto
//                    self.view.addSubview(livePhotoView)
//                }
//            }
//        }
//    }
