Kaynağa Gözat

Play a movie from Files

Marino Faggiana 1 yıl önce
ebeveyn
işleme
325a05c71d

+ 1 - 1
iOSClient/Data/NCManageDatabase+Metadata.swift

@@ -144,7 +144,7 @@ extension tableMetadata {
         sharePermissionsCollaborationServices == NCGlobal.shared.permissionReadShare && classFile == NKCommon.TypeClassFile.document.rawValue
     }
 
-    var isMediaPlay: Bool {
+    var isMovie: Bool {
         return classFile == NKCommon.TypeClassFile.audio.rawValue || classFile == NKCommon.TypeClassFile.video.rawValue
     }
 

+ 2 - 2
iOSClient/Main/Collection Common/NCCollectionViewCommon.swift

@@ -1342,10 +1342,10 @@ extension NCCollectionViewCommon: UICollectionViewDelegate {
             
             let imageIcon = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag))
 
-            if metadata.isImage || metadata.isMediaPlay {
+            if metadata.isImage || metadata.isMovie {
                 var metadatas: [tableMetadata] = []
                 for metadata in metadataSourceForAllSections {
-                    if metadata.isImage || metadata.isMediaPlay {
+                    if metadata.isImage || metadata.isMovie {
                         metadatas.append(metadata)
                     }
                 }

+ 40 - 25
iOSClient/Main/NCPickerViewController.swift

@@ -125,15 +125,20 @@ class customPhotoPickerViewController: TLPhotosPickerViewController {
 class NCDocumentPickerViewController: NSObject, UIDocumentPickerDelegate {
 
     let appDelegate = UIApplication.shared.delegate as! AppDelegate
+    var isViewerMedia: Bool
+    var viewController: UIViewController?
 
     @discardableResult
-    init (tabBarController: UITabBarController) {
+    init (tabBarController: UITabBarController, supportedTypes: [UTType], isViewerMedia: Bool, allowsMultipleSelection: Bool, viewController: UIViewController? = nil) {
+
+        self.isViewerMedia = isViewerMedia
+        self.viewController = viewController
         super.init()
 
-        let documentProviderMenu = UIDocumentPickerViewController(documentTypes: ["public.data"], in: .import)
+        let documentProviderMenu = UIDocumentPickerViewController(forOpeningContentTypes: supportedTypes)
 
         documentProviderMenu.modalPresentationStyle = .formSheet
-        documentProviderMenu.allowsMultipleSelection = true
+        documentProviderMenu.allowsMultipleSelection = allowsMultipleSelection
         documentProviderMenu.popoverPresentationController?.sourceView = tabBarController.tabBar
         documentProviderMenu.popoverPresentationController?.sourceRect = tabBarController.tabBar.bounds
         documentProviderMenu.delegate = self
@@ -143,41 +148,51 @@ class NCDocumentPickerViewController: NSObject, UIDocumentPickerDelegate {
 
     func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
 
-        for url in urls {
+        let ocId = NSUUID().uuidString
+
+        if isViewerMedia, let url = urls.first, let viewController = self.viewController {
 
             let fileName = url.lastPathComponent
-            let serverUrl = appDelegate.activeServerUrl
-            let ocId = NSUUID().uuidString
-            let atPath = url.path
-            let toPath = CCUtility.getDirectoryProviderStorageOcId(ocId, fileNameView: fileName)!
+            let metadata = NCManageDatabase.shared.createMetadata(account: appDelegate.account, user: appDelegate.user, userId: appDelegate.userId, fileName: fileName, fileNameView: fileName, ocId: ocId, serverUrl: "", urlBase: appDelegate.urlBase, url: url.path, contentType: "")
+            NCManageDatabase.shared.addMetadata(metadata)
+            NCViewer.shared.view(viewController: viewController, metadata: metadata, metadatas: [metadata], imageIcon: nil)
+
+        } else {
+            for url in urls {
 
-            if NCUtilityFileSystem.shared.copyFile(atPath: atPath, toPath: toPath) {
+                let serverUrl = appDelegate.activeServerUrl
+                let fileName = url.lastPathComponent
+                let atPath = url.path
+                let toPath = CCUtility.getDirectoryProviderStorageOcId(ocId, fileNameView: fileName)!
 
-                let metadataForUpload = NCManageDatabase.shared.createMetadata(account: appDelegate.account, user: appDelegate.user, userId: appDelegate.userId, fileName: fileName, fileNameView: fileName, ocId: ocId, serverUrl: serverUrl, urlBase: appDelegate.urlBase, url: "", contentType: "")
+                if NCUtilityFileSystem.shared.copyFile(atPath: atPath, toPath: toPath) {
 
-                metadataForUpload.session = NCNetworking.shared.sessionIdentifierBackground
-                metadataForUpload.sessionSelector = NCGlobal.shared.selectorUploadFile
-                metadataForUpload.size = NCUtilityFileSystem.shared.getFileSize(filePath: toPath)
-                metadataForUpload.status = NCGlobal.shared.metadataStatusWaitUpload
+                    let metadataForUpload = NCManageDatabase.shared.createMetadata(account: appDelegate.account, user: appDelegate.user, userId: appDelegate.userId, fileName: fileName, fileNameView: fileName, ocId: ocId, serverUrl: serverUrl, urlBase: appDelegate.urlBase, url: "", contentType: "")
 
-                if NCManageDatabase.shared.getMetadataConflict(account: appDelegate.account, serverUrl: serverUrl, fileNameView: fileName) != nil {
+                    metadataForUpload.session = NCNetworking.shared.sessionIdentifierBackground
+                    metadataForUpload.sessionSelector = NCGlobal.shared.selectorUploadFile
+                    metadataForUpload.size = NCUtilityFileSystem.shared.getFileSize(filePath: toPath)
+                    metadataForUpload.status = NCGlobal.shared.metadataStatusWaitUpload
 
-                    if let conflict = UIStoryboard(name: "NCCreateFormUploadConflict", bundle: nil).instantiateInitialViewController() as? NCCreateFormUploadConflict {
+                    if NCManageDatabase.shared.getMetadataConflict(account: appDelegate.account, serverUrl: serverUrl, fileNameView: fileName) != nil {
 
-                        conflict.delegate = appDelegate
-                        conflict.serverUrl = serverUrl
-                        conflict.metadatasUploadInConflict = [metadataForUpload]
+                        if let conflict = UIStoryboard(name: "NCCreateFormUploadConflict", bundle: nil).instantiateInitialViewController() as? NCCreateFormUploadConflict {
 
-                        appDelegate.window?.rootViewController?.present(conflict, animated: true, completion: nil)
+                            conflict.delegate = appDelegate
+                            conflict.serverUrl = serverUrl
+                            conflict.metadatasUploadInConflict = [metadataForUpload]
+
+                            appDelegate.window?.rootViewController?.present(conflict, animated: true, completion: nil)
+                        }
+
+                    } else {
+                        NCNetworkingProcessUpload.shared.createProcessUploads(metadatas: [metadataForUpload], completion: { _ in })
                     }
 
                 } else {
-                    NCNetworkingProcessUpload.shared.createProcessUploads(metadatas: [metadataForUpload], completion: { _ in })
+                    let error = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_read_file_error_")
+                    NCContentPresenter.shared.showError(error: error)
                 }
-
-            } else {
-                let error = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_read_file_error_")
-                NCContentPresenter.shared.showError(error: error)
             }
         }
     }

+ 2 - 1
iOSClient/Media/NCMedia.swift

@@ -31,6 +31,7 @@ class NCMedia: UIViewController, NCEmptyDataSetDelegate, NCSelectDelegate {
     private var emptyDataSet: NCEmptyDataSet?
     private var mediaCommandView: NCMediaCommandView?
     private var gridLayout: NCGridMediaLayout!
+    internal var documentPickerViewController: NCDocumentPickerViewController?
 
     internal let appDelegate = UIApplication.shared.delegate as! AppDelegate
 
@@ -393,7 +394,7 @@ extension NCMedia: UICollectionViewDataSource {
             cell.fileObjectId = metadata.ocId
             cell.fileUser = metadata.ownerId
 
-            if metadata.isMediaPlay {
+            if metadata.isMovie {
                 cell.imageStatus.image = cacheImages.cellPlayImage
             } else if metadata.livePhoto && livePhoto {
                 cell.imageStatus.image = cacheImages.cellLivePhotoImage

+ 1 - 1
iOSClient/Menu/AppDelegate+Menu.swift

@@ -57,7 +57,7 @@ extension AppDelegate {
             NCMenuAction(
                 title: NSLocalizedString("_upload_file_", comment: ""), icon: UIImage(named: "file")!.image(color: UIColor.systemGray, size: 50), action: { _ in
                     if let tabBarController = self.window?.rootViewController as? UITabBarController {
-                        self.documentPickerViewController = NCDocumentPickerViewController(tabBarController: tabBarController)
+                        self.documentPickerViewController = NCDocumentPickerViewController(tabBarController: tabBarController, supportedTypes: [UTType.data], isViewerMedia: false, allowsMultipleSelection: true)
                     }
                 }
             )

+ 16 - 0
iOSClient/Menu/NCMedia+Menu.swift

@@ -96,6 +96,22 @@ extension NCMedia {
                 )
             )
 
+            actions.append(.seperator(order: 0))
+
+            actions.append(
+                NCMenuAction(
+                    title: NSLocalizedString("_play_from_files_", comment: ""),
+                    icon: NCUtility.shared.loadImage(named: "play.circle"),
+                    action: { _ in
+                        if let tabBarController =  self.appDelegate.window?.rootViewController as? UITabBarController {
+                            self.documentPickerViewController = NCDocumentPickerViewController(tabBarController: tabBarController, supportedTypes: [UTType.movie], isViewerMedia: true, allowsMultipleSelection: false, viewController: self)
+                        }
+                    }
+                )
+            )
+
+            actions.append(.seperator(order: 0))
+
             actions.append(
                 NCMenuAction(
                     title: NSLocalizedString("_media_by_modified_date_", comment: ""),

+ 3 - 1
iOSClient/Networking/NCNetworking.swift

@@ -1537,7 +1537,9 @@ class NCNetworking: NSObject, NKCommonDelegate {
 
     func getVideoUrl(metadata: tableMetadata, completition: @escaping (_ url: URL?) -> Void) {
 
-        if CCUtility.fileProviderStorageExists(metadata) {
+        if !metadata.url.isEmpty {
+            completition(URL(fileURLWithPath: metadata.url))
+        } else if CCUtility.fileProviderStorageExists(metadata) {
             completition(URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)))
         } else {
             NextcloudKit.shared.getDirectDownload(fileId: metadata.fileId) { account, url, data, error in

+ 1 - 1
iOSClient/Supporting Files/en.lproj/Localizable.strings

@@ -939,7 +939,7 @@
 "_creation_"                = "Creation";
 "_modified_"                = "Modified";
 "_group_folders_"           = "Group folders";
-
+"_play_from_files_"         = "Play a movie from Files";
 
 // Video
 "_select_trace_"            = "Select the trace";

+ 1 - 1
iOSClient/Viewer/NCViewer.swift

@@ -69,7 +69,7 @@ class NCViewer: NSObject {
         }
 
         // IMAGE AUDIO VIDEO
-        if metadata.isImage || metadata.isMediaPlay {
+        if metadata.isImage || metadata.isMovie {
 
             if let navigationController = viewController.navigationController {
 

+ 3 - 3
iOSClient/Viewer/NCViewerMedia/NCViewerMedia.swift

@@ -88,7 +88,7 @@ class NCViewerMedia: UIViewController {
             statusLabel.text = ""
         }
         
-        if metadata.isMediaPlay {
+        if metadata.isMovie {
 
             playerToolBar = Bundle.main.loadNibNamed("NCPlayerToolBar", owner: self, options: nil)?.first as? NCPlayerToolBar
             if let playerToolBar = playerToolBar {
@@ -145,7 +145,7 @@ class NCViewerMedia: UIViewController {
 
             viewerMediaPage?.navigationController?.setNavigationBarHidden(false, animated: true)
 
-            if metadata.isMediaPlay {
+            if metadata.isMovie {
                 viewerMediaPage?.view.backgroundColor = .black
                 viewerMediaPage?.textColor = .white
             } else {
@@ -171,7 +171,7 @@ class NCViewerMedia: UIViewController {
     override func viewDidAppear(_ animated: Bool) {
         super.viewDidAppear(animated)
 
-        if metadata.isMediaPlay {
+        if metadata.isMovie {
 
             if let ncplayer = self.ncplayer {
 

+ 6 - 6
iOSClient/Viewer/NCViewerMedia/NCViewerMediaPage.swift

@@ -214,7 +214,7 @@ class NCViewerMediaPage: UIViewController {
             hideStatusBar = false
             progressView.isHidden = false
 
-            if metadatas[currentIndex].isMediaPlay {
+            if metadatas[currentIndex].isMovie {
                 currentViewController.playerToolBar?.show()
                 view.backgroundColor = .black
                 textColor = .white
@@ -231,7 +231,7 @@ class NCViewerMediaPage: UIViewController {
             hideStatusBar = true
             progressView.isHidden = true
 
-            if metadatas[currentIndex].isMediaPlay {
+            if metadatas[currentIndex].isMovie {
                 currentViewController.playerToolBar?.hide()
             }
 
@@ -256,7 +256,7 @@ class NCViewerMediaPage: UIViewController {
 
     @objc func autoHide() {
 
-        if metadatas[currentIndex].isMediaPlay, viewerMediaScreenMode == .normal {
+        if metadatas[currentIndex].isMovie, viewerMediaScreenMode == .normal {
             changeScreenMode(mode: .full)
         }
     }
@@ -275,7 +275,7 @@ class NCViewerMediaPage: UIViewController {
         let metadata = metadatas[currentIndex]
 
         if metadata.ocId == ocId,
-           metadata.isMediaPlay,
+           metadata.isMovie,
            CCUtility.fileProviderStorageExists(metadata),
            let ncplayer = currentViewController.ncplayer {
             let url = URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)!)
@@ -430,8 +430,8 @@ class NCViewerMediaPage: UIViewController {
             return .commandFailed
         }
 
-        // VIDEO / AUDIO () ()
-        if metadata.isMediaPlay {
+        // VIDEO AUDIO () ()
+        if metadata.isMovie {
 
             MPRemoteCommandCenter.shared().skipForwardCommand.isEnabled = true
             skipForwardCommand = MPRemoteCommandCenter.shared().skipForwardCommand.addTarget { event in

+ 1 - 1
iOSClient/Viewer/NCViewerProviderContextMenu.swift

@@ -100,7 +100,7 @@ class NCViewerProviderContextMenu: UIViewController {
             }
 
             // AUTO DOWNLOAD VIDEO / AUDIO
-            if !CCUtility.fileProviderStorageExists(metadata) && metadata.isMediaPlay {
+            if !CCUtility.fileProviderStorageExists(metadata) && metadata.isMovie {
 
                 var maxDownload: UInt64 = 0