marinofaggiana 3 years ago
parent
commit
5656561e7f

+ 0 - 1
Cartfile

@@ -5,7 +5,6 @@ github "FabrizioBrancati/Queuer"
 github "xmartlabs/XLForm" ~> 4.1
 github "AssistoLab/DropDown" "v2.3.13"
 
-github "https://github.com/marinofaggiana/KTVHTTPCache" "2.0.2"
 github "https://github.com/marinofaggiana/TOPasscodeViewController" "0.0.10"
 github "https://github.com/marinofaggiana/OpenSSL" "master"
 github "https://github.com/marinofaggiana/ChromaColorPicker" "master"

+ 0 - 12
Nextcloud.xcodeproj/project.pbxproj

@@ -53,8 +53,6 @@
 		F70B86752642CE3B00ED5349 /* FirebaseCrashlytics in Frameworks */ = {isa = PBXBuildFile; productRef = F70B86742642CE3B00ED5349 /* FirebaseCrashlytics */; };
 		F70B86762642CF5300ED5349 /* ChromaColorPicker.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = F70B866F2642CA9500ED5349 /* ChromaColorPicker.xcframework */; };
 		F70B86772642CF5300ED5349 /* ChromaColorPicker.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = F70B866F2642CA9500ED5349 /* ChromaColorPicker.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
-		F70B86852642CF5600ED5349 /* KTVHTTPCache.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = F70B86792642CF5300ED5349 /* KTVHTTPCache.xcframework */; };
-		F70B86862642CF5600ED5349 /* KTVHTTPCache.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = F70B86792642CF5300ED5349 /* KTVHTTPCache.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
 		F70B86872642CF5600ED5349 /* TLPhotoPicker.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = F70B867A2642CF5300ED5349 /* TLPhotoPicker.xcframework */; };
 		F70B86882642CF5600ED5349 /* TLPhotoPicker.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = F70B867A2642CF5300ED5349 /* TLPhotoPicker.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
 		F70B86892642CF5600ED5349 /* XLForm.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = F70B867B2642CF5300ED5349 /* XLForm.xcframework */; };
@@ -63,8 +61,6 @@
 		F70B868C2642CF5600ED5349 /* Queuer.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = F70B867C2642CF5300ED5349 /* Queuer.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
 		F70B868D2642CF5600ED5349 /* UICKeyChainStore.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = F70B867D2642CF5400ED5349 /* UICKeyChainStore.xcframework */; };
 		F70B868E2642CF5600ED5349 /* UICKeyChainStore.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = F70B867D2642CF5400ED5349 /* UICKeyChainStore.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
-		F70B868F2642CF5600ED5349 /* KTVCocoaHTTPServer.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = F70B867E2642CF5400ED5349 /* KTVCocoaHTTPServer.xcframework */; };
-		F70B86902642CF5600ED5349 /* KTVCocoaHTTPServer.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = F70B867E2642CF5400ED5349 /* KTVCocoaHTTPServer.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
 		F70B86932642CF5700ED5349 /* OpenSSL.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = F70B86802642CF5400ED5349 /* OpenSSL.xcframework */; };
 		F70B86942642CF5700ED5349 /* OpenSSL.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = F70B86802642CF5400ED5349 /* OpenSSL.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
 		F70B86972642CF5700ED5349 /* TOPasscodeViewController.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = F70B86822642CF5500ED5349 /* TOPasscodeViewController.xcframework */; };
@@ -331,7 +327,6 @@
 		F7F878AE1FB9E3B900599E4F /* NCEndToEndMetadata.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7F878AD1FB9E3B900599E4F /* NCEndToEndMetadata.swift */; };
 		F7F878AF1FB9E3B900599E4F /* NCEndToEndMetadata.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7F878AD1FB9E3B900599E4F /* NCEndToEndMetadata.swift */; };
 		F7F9D1BB25397CE000D9BFF5 /* NCViewer.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7F9D1BA25397CE000D9BFF5 /* NCViewer.swift */; };
-		F7FAC2672549E1B5008EE2C4 /* NCKTVHTTPCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7FAC2662549E1B5008EE2C4 /* NCKTVHTTPCache.swift */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXContainerItemProxy section */
@@ -366,14 +361,12 @@
 			dstSubfolderSpec = 10;
 			files = (
 				F70B869A2642CF5800ED5349 /* FSCalendar.xcframework in Embed Frameworks */,
-				F70B86862642CF5600ED5349 /* KTVHTTPCache.xcframework in Embed Frameworks */,
 				F70B868E2642CF5600ED5349 /* UICKeyChainStore.xcframework in Embed Frameworks */,
 				F70B86982642CF5700ED5349 /* TOPasscodeViewController.xcframework in Embed Frameworks */,
 				F70B86942642CF5700ED5349 /* OpenSSL.xcframework in Embed Frameworks */,
 				F70B868C2642CF5600ED5349 /* Queuer.xcframework in Embed Frameworks */,
 				F70B868A2642CF5600ED5349 /* XLForm.xcframework in Embed Frameworks */,
 				F70B869C2642CF5800ED5349 /* DropDown.xcframework in Embed Frameworks */,
-				F70B86902642CF5600ED5349 /* KTVCocoaHTTPServer.xcframework in Embed Frameworks */,
 				F70B86882642CF5600ED5349 /* TLPhotoPicker.xcframework in Embed Frameworks */,
 				F70B86772642CF5300ED5349 /* ChromaColorPicker.xcframework in Embed Frameworks */,
 			);
@@ -751,7 +744,6 @@
 		F7F67BB81A24D27800EE80DA /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
 		F7F878AD1FB9E3B900599E4F /* NCEndToEndMetadata.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCEndToEndMetadata.swift; sourceTree = "<group>"; };
 		F7F9D1BA25397CE000D9BFF5 /* NCViewer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCViewer.swift; sourceTree = "<group>"; };
-		F7FAC2662549E1B5008EE2C4 /* NCKTVHTTPCache.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCKTVHTTPCache.swift; sourceTree = "<group>"; };
 		F7FC7D551DC1F93800BB2C6A /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; };
 /* End PBXFileReference section */
 
@@ -801,7 +793,6 @@
 				F7ED547C25EEA65400956C55 /* QRCodeReader in Frameworks */,
 				F70B86972642CF5700ED5349 /* TOPasscodeViewController.xcframework in Frameworks */,
 				F788ECC7263AAAFA00ADC67F /* MarkdownKit in Frameworks */,
-				F70B868F2642CF5600ED5349 /* KTVCocoaHTTPServer.xcframework in Frameworks */,
 				F70B869B2642CF5800ED5349 /* DropDown.xcframework in Frameworks */,
 				F70B86892642CF5600ED5349 /* XLForm.xcframework in Frameworks */,
 				F770768E263A8C3400A1BA94 /* FloatingPanel in Frameworks */,
@@ -811,7 +802,6 @@
 				F75E57BD25BF0EC1002B72C2 /* SVGKit in Frameworks */,
 				F70B86752642CE3B00ED5349 /* FirebaseCrashlytics in Frameworks */,
 				F70B86992642CF5800ED5349 /* FSCalendar.xcframework in Frameworks */,
-				F70B86852642CF5600ED5349 /* KTVHTTPCache.xcframework in Frameworks */,
 				F70B86762642CF5300ED5349 /* ChromaColorPicker.xcframework in Frameworks */,
 				F72DA9B425F53E4E00B87DB1 /* SwiftRichString in Frameworks */,
 				F70B86932642CF5700ED5349 /* OpenSSL.xcframework in Frameworks */,
@@ -1235,7 +1225,6 @@
 			isa = PBXGroup;
 			children = (
 				F752011C25480387000BF3A7 /* NCViewerVideo.swift */,
-				F7FAC2662549E1B5008EE2C4 /* NCKTVHTTPCache.swift */,
 			);
 			path = NCViewerVideo;
 			sourceTree = "<group>";
@@ -2182,7 +2171,6 @@
 				F7134186259747BA00768D21 /* NCPushNotification.m in Sources */,
 				F726EEEC1FED1C820030B9C8 /* NCEndToEndInitialize.swift in Sources */,
 				F79A65C62191D95E00FF6DCC /* NCSelect.swift in Sources */,
-				F7FAC2672549E1B5008EE2C4 /* NCKTVHTTPCache.swift in Sources */,
 				F75D19E325EFE09000D74598 /* NCTrash+Menu.swift in Sources */,
 				F70CAE3A1F8CF31A008125FD /* NCEndToEndEncryption.m in Sources */,
 				F70753EB2542A99800972D44 /* NCViewerImage.swift in Sources */,

+ 25 - 0
iOSClient/Networking/NCNetworking.swift

@@ -1294,6 +1294,31 @@ import Queuer
         }
     }
     
+    //MARK: - Direct Download
+
+    func getVideoUrl(metadata: tableMetadata, completition: @escaping (_ url: URL?)->()) {
+        
+        if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
+            
+            completition(URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)))
+                        
+        } else {
+            
+            NCCommunication.shared.getDirectDownload(fileId: metadata.fileId) { account, url, errorCode, errorDescription in
+                
+                if errorCode == 0 && url != nil {
+                    if let url = URL(string: url!) {
+                        completition(url)
+                    } else {
+                        completition(nil)
+                    }
+                } else {
+                    completition(nil)
+                }
+            }
+        }
+    }
+    
     //MARK: - TEST API
       
     /*

+ 0 - 3
iOSClient/Settings/CCAdvanced.m

@@ -24,7 +24,6 @@
 #import "CCAdvanced.h"
 #import "CCUtility.h"
 #import "NSNotificationCenter+MainThread.h"
-#import <KTVHTTPCache/KTVHTTPCache.h>
 #import "NCBridgeSwift.h"
 
 @interface CCAdvanced ()
@@ -415,7 +414,6 @@
     
     [[NSURLCache sharedURLCache] setMemoryCapacity:0];
     [[NSURLCache sharedURLCache] setDiskCapacity:0];
-    [KTVHTTPCache cacheDeleteAllCaches];
     
     [[NCManageDatabase shared] clearDatabaseWithAccount:appDelegate.account removeAccount:false];
     
@@ -490,7 +488,6 @@
                 
         [[NSURLCache sharedURLCache] setMemoryCapacity:0];
         [[NSURLCache sharedURLCache] setDiskCapacity:0];
-        [KTVHTTPCache cacheDeleteAllCaches];
 
         [CCUtility removeGroupDirectoryProviderStorage];
         [CCUtility removeGroupApplicationSupport];

+ 0 - 2
iOSClient/Utility/NCUtility.swift

@@ -23,7 +23,6 @@
 
 import UIKit
 import SVGKit
-import KTVHTTPCache
 import NCCommunication
 import PDFKit
 import Accelerate
@@ -266,7 +265,6 @@ class NCUtility: NSObject {
         
         URLCache.shared.memoryCapacity = 0
         URLCache.shared.diskCapacity = 0
-        KTVHTTPCache.cacheDeleteAllCaches()
         
         NCManageDatabase.shared.clearDatabase(account: nil, removeAccount: true)
         

+ 26 - 26
iOSClient/Viewer/NCViewerImage/NCViewerImage.swift

@@ -399,36 +399,37 @@ class NCViewerImage: UIViewController {
     //MARK: - Video
     
     func videoPlay(metadata: tableMetadata) {
-                                
-        NCKTVHTTPCache.shared.startProxy(user: appDelegate.user, password: appDelegate.password, metadata: metadata)
-
-        if let url = NCKTVHTTPCache.shared.getVideoURL(metadata: metadata) {
-            
-            player = AVPlayer(url: url)
-            player?.isMuted = CCUtility.getAudioMute()
-            videoLayer = AVPlayerLayer(player: player)
-            
-            if videoLayer != nil && currentViewerImageZoom != nil {
+           
+        NCNetworking.shared.getVideoUrl(metadata: metadata) { url in
             
-                videoLayer!.frame = currentViewerImageZoom!.imageView.bounds
-                videoLayer!.videoGravity = AVLayerVideoGravity.resizeAspect
+            if let url = url {
+                
+                self.player = AVPlayer(url: url)
+                self.player?.isMuted = CCUtility.getAudioMute()
+                self.videoLayer = AVPlayerLayer(player: self.player)
                 
-                currentViewerImageZoom!.imageView.layer.addSublayer(videoLayer!)
+                if self.videoLayer != nil && self.currentViewerImageZoom != nil {
                 
-                // At end go back to start
-                NotificationCenter.default.addObserver(forName: .AVPlayerItemDidPlayToEndTime, object: player?.currentItem, queue: .main) { (notification) in
-                    if let item = notification.object as? AVPlayerItem, let currentItem = self.player?.currentItem, item == currentItem {
-                        self.player?.seek(to: .zero)
-                        if !self.currentMetadata.livePhoto {
-                            NCManageDatabase.shared.deleteVideoTime(metadata: self.currentMetadata)
+                    self.videoLayer!.frame = self.currentViewerImageZoom!.imageView.bounds
+                    self.videoLayer!.videoGravity = AVLayerVideoGravity.resizeAspect // .resizeAspectFill
+                    
+                    self.currentViewerImageZoom!.imageView.layer.addSublayer(self.videoLayer!)
+                    
+                    // At end go back to start
+                    NotificationCenter.default.addObserver(forName: .AVPlayerItemDidPlayToEndTime, object: self.player?.currentItem, queue: .main) { (notification) in
+                        if let item = notification.object as? AVPlayerItem, let currentItem = self.player?.currentItem, item == currentItem {
+                            self.player?.seek(to: .zero)
+                            if !self.currentMetadata.livePhoto {
+                                NCManageDatabase.shared.deleteVideoTime(metadata: self.currentMetadata)
+                            }
                         }
                     }
-                }
-                            
-                rateObserver = player?.addObserver(self, forKeyPath: "rate", options: [], context: nil)
-                
-                if pictureInPictureOcId != metadata.ocId {
-                    self.player?.play()
+                                
+                    self.rateObserver = self.player?.addObserver(self, forKeyPath: "rate", options: [], context: nil)
+                    
+                    if self.pictureInPictureOcId != metadata.ocId {
+                        self.player?.play()
+                    }
                 }
             }
         }
@@ -448,7 +449,6 @@ class NCViewerImage: UIViewController {
         if rateObserver != nil {
             player?.removeObserver(self, forKeyPath: "rate")
             NotificationCenter.default.removeObserver(self, name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: nil)
-            NCKTVHTTPCache.shared.stopProxy()
             self.rateObserver = nil
         }
                

+ 15 - 13
iOSClient/Viewer/NCViewerImage/NCViewerImageDetailView.swift

@@ -150,19 +150,21 @@ class NCViewerImageDetailView: UIView {
                 dimValue.text = "\(Int(image.size.width)) x \(Int(image.size.height))"
             }
         } else if metadata?.typeFile == NCGlobal.shared.metadataTypeFileVideo || metadata?.typeFile == NCGlobal.shared.metadataTypeFileAudio  {
-            if let url = NCKTVHTTPCache.shared.getVideoURL(metadata: metadata!) {
-                let playerVideo = AVPlayer(url: url)
-                if let duration = playerVideo.currentItem?.asset.duration {
-                    let durationVideo = Int(CMTimeGetSeconds(duration))
-                    let timer = secondsToHoursMinutesSeconds(seconds: durationVideo)
-                    dimLabel.text = NSLocalizedString("_duration_", comment: "")
-                    var hh = "\(timer.0)"
-                    var mm = "\(timer.1)"
-                    var ss = "\(timer.2)"
-                    if hh.count == 1 { hh = "0" + hh }
-                    if mm.count == 1 { mm = "0" + mm }
-                    if ss.count == 1 { ss = "0" + ss }
-                    dimValue.text = hh + ":" + mm + ":" + ss
+            NCNetworking.shared.getVideoUrl(metadata: metadata!) { url in
+                if let url = url {
+                    let playerVideo = AVPlayer(url: url)
+                    if let duration = playerVideo.currentItem?.asset.duration {
+                        let durationVideo = Int(CMTimeGetSeconds(duration))
+                        let timer = self.secondsToHoursMinutesSeconds(seconds: durationVideo)
+                        self.dimLabel.text = NSLocalizedString("_duration_", comment: "")
+                        var hh = "\(timer.0)"
+                        var mm = "\(timer.1)"
+                        var ss = "\(timer.2)"
+                        if hh.count == 1 { hh = "0" + hh }
+                        if mm.count == 1 { mm = "0" + mm }
+                        if ss.count == 1 { ss = "0" + ss }
+                        self.dimValue.text = hh + ":" + mm + ":" + ss
+                    }
                 }
             }
         }

+ 0 - 129
iOSClient/Viewer/NCViewerVideo/NCKTVHTTPCache.swift

@@ -1,129 +0,0 @@
-//
-//  NCKTVHTTPCache.swift
-//  Nextcloud
-//
-//  Created by Marino Faggiana on 28/10/2020.
-//  Copyright © 2020 Marino Faggiana. All rights reserved.
-//
-//  Author Marino Faggiana <marino.faggiana@nextcloud.com>
-//
-//  This program is free software: you can redistribute it and/or modify
-//  it under the terms of the GNU General Public License as published by
-//  the Free Software Foundation, either version 3 of the License, or
-//  (at your option) any later version.
-//
-//  This program is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-//  GNU General Public License for more details.
-//
-//  You should have received a copy of the GNU General Public License
-//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
-//
-
-import UIKit
-import KTVHTTPCache
-
-class NCKTVHTTPCache: NSObject {
-    @objc static let shared: NCKTVHTTPCache = {
-        let instance = NCKTVHTTPCache()
-        instance.setupHTTPCache()
-        return instance
-    }()
-    
-    func getVideoURL(metadata: tableMetadata) -> URL? {
-        
-        if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
-            
-            return URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView))
-            
-        } else {
-            
-            guard let stringURL = (metadata.serverUrl + "/" + metadata.fileName).addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) else { return nil }
-            
-            return NCKTVHTTPCache.shared.getProxyURL(stringURL: stringURL)
-        }
-    }
-    
-    func startProxy(user: String, password: String, metadata: tableMetadata) {
-        
-        guard let authData = (user + ":" + password).data(using: .utf8) else { return }
-        
-        let authValue = "Basic " + authData.base64EncodedString(options: [])
-        KTVHTTPCache.downloadSetAdditionalHeaders(["Authorization":authValue, "User-Agent":CCUtility.getUserAgent()])
-        
-        if !KTVHTTPCache.proxyIsRunning() {
-            do {
-                try KTVHTTPCache.proxyStart()
-            } catch let error {
-                print("Proxy Start error : \(error)")
-            }
-        }
-        
-        saveCache(metadata: metadata)
-    }
-    
-    func stopProxy() {
-        
-        if KTVHTTPCache.proxyIsRunning() {
-            KTVHTTPCache.proxyStop()
-        }
-    }
-    
-    func getProxyURL(stringURL: String) -> URL {
-        
-        return KTVHTTPCache.proxyURL(withOriginalURL: URL(string: stringURL))
-    }
-    
-    func getCacheCompleteFileURL(videoURL: URL?) -> URL? {
-        
-        return KTVHTTPCache.cacheCompleteFileURL(with: videoURL)
-    }
-    
-    func deleteCache(videoURL: URL?) {
-        
-        KTVHTTPCache.cacheDelete(with: videoURL)
-    }
-    
-    func saveCache(metadata: tableMetadata) {
-        
-        if !CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView:metadata.fileNameView) {
-            
-            guard let stringURL = (metadata.serverUrl + "/" + metadata.fileName).addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) else { return }
-            
-            let videoURL = URL(string: stringURL)
-            guard let url = KTVHTTPCache.cacheCompleteFileURL(with: videoURL) else { return }
-            
-            CCUtility.copyFile(atPath: url.path, toPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView))
-            NCManageDatabase.shared.addLocalFile(metadata: metadata)
-            KTVHTTPCache.cacheDelete(with: videoURL)
-            
-            NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterReloadDataSource, userInfo: ["ocId":metadata.ocId, "serverUrl":metadata.serverUrl])
-        }
-    }
-    
-    private func setupHTTPCache() {
-        
-        KTVHTTPCache.cacheSetMaxCacheLength(NCGlobal.shared.maxHTTPCache)
-        
-        if ProcessInfo.processInfo.environment["SIMULATOR_DEVICE_NAME"] != nil {
-            KTVHTTPCache.logSetConsoleLogEnable(true)
-        }
-        
-        do {
-            try KTVHTTPCache.proxyStart()
-        } catch let error {
-            print("Proxy Start error : \(error)")
-        }
-        
-        KTVHTTPCache.encodeSetURLConverter { (url) -> URL? in
-            print("URL Filter reviced URL : " + String(describing: url))
-            return url
-        }
-        
-        KTVHTTPCache.downloadSetUnacceptableContentTypeDisposer { (url, contentType) -> Bool in
-            print("Unsupport Content-Type Filter reviced URL : " + String(describing: url) + " " + String(describing: contentType))
-            return false
-        }
-    }
-}

+ 20 - 8
iOSClient/Viewer/NCViewerVideo/NCViewerVideo.swift

@@ -23,6 +23,7 @@
 
 import UIKit
 import AVKit
+import NCCommunication
 
 protocol NCViewerVideoDelegate {
     func startPictureInPicture(metadata: tableMetadata)
@@ -49,9 +50,7 @@ class NCViewerVideo: AVPlayerViewController {
     override func viewDidAppear(_ animated: Bool) {
         super.viewDidAppear(animated)
         
-        NCKTVHTTPCache.shared.startProxy(user: appDelegate.user, password: appDelegate.password, metadata: metadata)
-        
-        if let url = NCKTVHTTPCache.shared.getVideoURL(metadata: metadata) {
+        func play(url: URL) {
             
             player = AVPlayer(url: url)
             
@@ -85,13 +84,27 @@ class NCViewerVideo: AVPlayerViewController {
                 player?.seek(to: time)
             }
             player?.isMuted = CCUtility.getAudioMute()
+            
+            // AIRPLAY
+            if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
+                player?.allowsExternalPlayback = true
+            } else {
+                player?.allowsExternalPlayback = false
+            }
         }
         
-        // AIRPLAY
         if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
-            player?.allowsExternalPlayback = true
+            
+            play(url: URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)))
+            
         } else {
-            player?.allowsExternalPlayback = false
+            
+            NCCommunication.shared.getDirectDownload(fileId: metadata.fileId) { account, url, errorCode, errorDescription in
+                
+                if let url = URL(string: url) {
+                    play(url: url)
+                }
+            }
         }
     }
     
@@ -110,7 +123,6 @@ class NCViewerVideo: AVPlayerViewController {
             if rateObserverToken != nil {
                 player?.removeObserver(self, forKeyPath: "rate")
                 NotificationCenter.default.removeObserver(self, name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: nil)
-                NCKTVHTTPCache.shared.stopProxy()
                 self.rateObserverToken = nil
             }
         }
@@ -119,7 +131,7 @@ class NCViewerVideo: AVPlayerViewController {
     override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
         
         if keyPath != nil && keyPath == "rate" {
-            NCKTVHTTPCache.shared.saveCache(metadata: metadata)
+           // NCKTVHTTPCache.shared.saveCache(metadata: metadata)
         }
     }
 }