小编Fra*_*gat的帖子

错误:此媒体不支持该操作 - Swift

我正在尝试在 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)
            }) …
Run Code Online (Sandbox Code Playgroud)

nsfilemanager avassetexportsession avasset swift

5
推荐指数
0
解决办法
4103
查看次数