5

I am trying to save a video with this code on an Apple TV:

func playerItemDidReachEnd(_ notification: Notification) {

    if notification.object as? AVPlayerItem  == player.currentItem {
        player.seek(to: kCMTimeZero)
        let exporter = AVAssetExportSession(asset: asset, presetName: AVAssetExportPresetHighestQuality)
        let filename = "video.mp4"
        let documentsDirectory = FileManager.default.urls(for: FileManager.SearchPathDirectory.documentDirectory, in: FileManager.SearchPathDomainMask.userDomainMask).last!

        let outputURL = documentsDirectory.appendingPathComponent(filename)
        exporter?.outputURL = NSURL.fileURL(withPath: outputURL.path)
        exporter?.outputFileType = AVFileTypeMPEG4
        let path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as String
        let url = NSURL(fileURLWithPath: path)
        let filePath = url.appendingPathComponent(filename)?.path
        let fileManager = FileManager.default

        if fileManager.fileExists(atPath: filePath!) {

        } else {
            exporter?.exportAsynchronously(completionHandler: {

                print(exporter?.status.rawValue)
                print(exporter?.error)
            })
        }
    }
}

I am also using this as the asset and do not want to change the asset:

lazy var asset: AVURLAsset = {

         var asset: AVURLAsset = AVURLAsset(url: self.url)

         asset.resourceLoader.setDelegate(self as? AVAssetResourceLoaderDelegate, queue: DispatchQueue.main)

         return asset
         }()

But I am getting this error. What does it mean, and how can I fix it? Thanks :)

Optional(Error Domain=AVFoundationErrorDomain Code=-11838 "Operation Stopped" UserInfo={NSUnderlyingError=0x608000443300 {Error Domain=NSOSStatusErrorDomain Code=-12109 "(null)"}, NSLocalizedFailureReason=The operation is not supported for this media., NSLocalizedDescription=Operation Stopped})

FrankFabregat
  • 81
  • 2
  • 11

0 Answers0