簡體   English   中英

如何在Swift中將視頻從“ file:///”保存到相機膠卷中?

[英]How to save videos from “file:///” to camera roll in Swift?

在我的應用程序中,我有一個自定義的攝像頭,可將捕獲的視頻寫到如下所示的臨時路徑: file:///private/var/mobile... 我的問題是,如何將視頻保存到相機膠卷中?

我試過的

PHPhotoLibrary.shared().performChanges({
    PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: videoURL)

    // I've also tried this
    // let exportURL = URL(fileURLWithPath: videoURL.absoluteString, isDirectory: true)
    // PHAssetChangeRequest.creationRequestForAssetFromVideo(atFile: exportURL)
}, completionHandler: { success, error in
    if success {
        print("Successful")
    } else if let error = error {
        print("\(error.localizedDescription)")
    }
})

但是它總是打印: This operation could not be completed

有什么想法嗎?

實際上,您應該首先檢查文件擴展名。如果蘋果不支持該擴展名,則無法將其保存在相機膠卷中。您可以通過嘗試將.mp4文件保存在相機膠卷中查看保存過程,以了解是否保存過程是否有效。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM