marinofaggiana 3 жил өмнө
parent
commit
6b5c8122d3

+ 3 - 0
iOSClient/AppDelegate.swift

@@ -311,6 +311,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         
         // close detail
         NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterMenuDetailClose)
+        
+        // Video proxy
+        NCKTVHTTPCache.shared.restartProxy(user: user, password: password)
 
         // Registeration domain File Provider
         //FileProviderDomain *fileProviderDomain = [FileProviderDomain new];

+ 9 - 2
iOSClient/Viewer/NCViewerVideo/NCKTVHTTPCache.swift

@@ -61,13 +61,20 @@ class NCKTVHTTPCache: NSObject {
         }        
     }
     
-    func stopProxy(metadata: tableMetadata) {
+    func stopProxy() {
+        
+        if KTVHTTPCache.proxyIsRunning() {
+            KTVHTTPCache.proxyStop()
+        }
+    }
+    
+    func restartProxy(user: String, password: String) {
         
         if KTVHTTPCache.proxyIsRunning() {
             KTVHTTPCache.proxyStop()
         }
         
-        saveCache(metadata: metadata)
+        startProxy(user: user, password: password)
     }
     
     func getProxyURL(stringURL: String) -> URL {

+ 6 - 12
iOSClient/Viewer/NCViewerVideo/NCViewerVideo.swift

@@ -33,8 +33,6 @@ class NCViewerVideo: NSObject {
     
     private let appDelegate = UIApplication.shared.delegate as! AppDelegate
     private var imageView: UIImageView?
-//    private var timeObserver: Any?
-//    private var rateObserver: Any?
     private var durationSeconds: Double = 0
     private var viewerVideoToolBar: NCViewerVideoToolBar?
 
@@ -52,9 +50,7 @@ class NCViewerVideo: NSObject {
     }
     
     func initVideoPlayer(imageView: UIImageView?, viewerVideoToolBar: NCViewerVideoToolBar?, metadata: tableMetadata) {
-        
-        NCKTVHTTPCache.shared.startProxy(user: appDelegate.user, password: appDelegate.password)
-        
+                
         guard let imageView = imageView else { return }
         if self.metadata == metadata { return }
         
@@ -74,6 +70,7 @@ class NCViewerVideo: NSObject {
                 if let item = notification.object as? AVPlayerItem, let currentItem = self.player?.currentItem, item == currentItem {
                     self.player?.seek(to: .zero)
                     self.viewerVideoToolBar?.showToolBar()
+                    NCKTVHTTPCache.shared.saveCache(metadata: metadata)
                 }
             }
             
@@ -102,9 +99,7 @@ class NCViewerVideo: NSObject {
     }
     
     func videoPlay() {
-        
-        NCKTVHTTPCache.shared.startProxy(user: appDelegate.user, password: appDelegate.password)
-        
+                
         self.player?.play()
     }
     
@@ -115,6 +110,8 @@ class NCViewerVideo: NSObject {
         if let time = self.player?.currentTime() {
             NCManageDatabase.shared.addVideoTime(metadata: metadata, time: time, durationSeconds: nil)
         }
+        
+        NCKTVHTTPCache.shared.saveCache(metadata: metadata)
     }
     
     func videoSeek(time: CMTime) {
@@ -125,12 +122,9 @@ class NCViewerVideo: NSObject {
     }
     
     func videoRemoved() {
-        guard let metadata = self.metadata else { return }
 
         videoPause()
-                  
-        NCKTVHTTPCache.shared.stopProxy(metadata: metadata)
-        
+                            
         self.videoLayer?.removeFromSuperlayer()
     }