AVAssetExportSession无法导出从iCloud下载的视频。
创始人
2024-11-12 20:00:35
0

如果您的视频从iCloud下载并保存到本地,则需要先将其导出到应用程序沙盒内的临时文件夹中,然后再使用AVAssetExportSession导出。下面是一个示例代码:

let documentsDirectoryUrl = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
let temporaryFileName = "tempVideo.mp4"
let temporaryFileUrl = documentsDirectoryUrl.appendingPathComponent(temporaryFileName)

if let urlAsset = AVURLAsset(url: videoUrl), let exportSession = AVAssetExportSession(asset: urlAsset, presetName: AVAssetExportPresetHighestQuality) {
    exportSession.outputFileType = AVFileType.mp4
    exportSession.outputURL = temporaryFileUrl

    exportSession.exportAsynchronously(completionHandler: {
        switch exportSession.status {
        case .completed:
            //导出完成后,可以将临时文件转移到另一个位置,并删除临时文件。
            //然后您可以使用导出的文件路径来进行进一步的操作。
        case .failed, .cancelled:
            print("Export failed: \(String(describing: exportSession.error))")
        default:
            break
        }
    })
}

在上面的代码中,我们首先将视频导出到临时文件夹中,然后在回调中检查AVAssetExportSession的状态。如果导出成功,我们可以将临时文件移动到另一个位置并删除它。之后,您就可以在应用程序中使用导出的视频文件。

注意:确保您有适当的访问iCloud文件的权限,并且将导出的文件保存在应用程序沙盒内的临时文件夹中。

相关内容

热门资讯

透视挂!aapoker怎么选牌... 透视挂!aapoker怎么选牌(透视)真的假的(果然是真的有挂)1、进入游戏-大厅左侧-新手福利-激...
透视能赢!aapoker辅助怎... 透视能赢!aapoker辅助怎么用(透视)免费透视脚本(确实真的是有挂)1、金币登录送、破产送、升级...
透视软件!aapoker透视脚... 透视软件!aapoker透视脚本(透视)透视方法(好像存在有挂);1、让任何用户在无需aapoker...
透视辅助!aapoker脚本怎... 透视辅助!aapoker脚本怎么用(透视)透视脚本下载(原来是有挂)1、下载好aapoker脚本怎么...
透视能赢!aapoker透视怎... 透视能赢!aapoker透视怎么用(透视)透视软件(竟然真的有挂);1、起透看视 aapoker透视...
透视透视!aapoker辅助器... 透视透视!aapoker辅助器怎么用(透视)插件下载(其实真的是有挂);1、金币登录送、破产送、升级...
透视真的!aapoker万能辅... 透视真的!aapoker万能辅助器(透视)脚本(切实真的是有挂)运aapoker万能辅助器辅助工具,...
透视科技!aapoker俱乐部... 透视科技!aapoker俱乐部靠谱吗(透视)万能辅助器(都是存在有挂)1、打开软件启动之后找到中间准...
透视规律!aapoker俱乐部... 透视规律!aapoker俱乐部靠谱吗(透视)透视脚本(切实真的是有挂)1、许多玩家不知道aapoke...
透视规律!aapoker怎么拿... 透视规律!aapoker怎么拿好牌(透视)插件(都是有挂)进入游戏-大厅左侧-新手福利-激活码辅助透...