marinofaggiana 4 жил өмнө
parent
commit
0f68b94220

+ 0 - 4
Nextcloud.xcodeproj/project.pbxproj

@@ -237,7 +237,6 @@
 		F78F74342163757000C2ADAD /* NCTrash.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F78F74332163757000C2ADAD /* NCTrash.storyboard */; };
 		F78F74342163757000C2ADAD /* NCTrash.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F78F74332163757000C2ADAD /* NCTrash.storyboard */; };
 		F78F74362163781100C2ADAD /* NCTrash.swift in Sources */ = {isa = PBXBuildFile; fileRef = F78F74352163781100C2ADAD /* NCTrash.swift */; };
 		F78F74362163781100C2ADAD /* NCTrash.swift in Sources */ = {isa = PBXBuildFile; fileRef = F78F74352163781100C2ADAD /* NCTrash.swift */; };
 		F790110E21415BF600D7B136 /* NCViewerRichdocument.swift in Sources */ = {isa = PBXBuildFile; fileRef = F790110D21415BF600D7B136 /* NCViewerRichdocument.swift */; };
 		F790110E21415BF600D7B136 /* NCViewerRichdocument.swift in Sources */ = {isa = PBXBuildFile; fileRef = F790110D21415BF600D7B136 /* NCViewerRichdocument.swift */; };
-		F79630EE215527D40015EEA5 /* NCVideoCommon.swift in Sources */ = {isa = PBXBuildFile; fileRef = F79630ED215527D40015EEA5 /* NCVideoCommon.swift */; };
 		F79728D422F96F2E003CACA7 /* NCShareLinkFolderMenuView.xib in Resources */ = {isa = PBXBuildFile; fileRef = F79728D322F96F2D003CACA7 /* NCShareLinkFolderMenuView.xib */; };
 		F79728D422F96F2E003CACA7 /* NCShareLinkFolderMenuView.xib in Resources */ = {isa = PBXBuildFile; fileRef = F79728D322F96F2D003CACA7 /* NCShareLinkFolderMenuView.xib */; };
 		F79728D622F9A0B1003CACA7 /* NCShareUserFolderMenuView.xib in Resources */ = {isa = PBXBuildFile; fileRef = F79728D522F9A0B0003CACA7 /* NCShareUserFolderMenuView.xib */; };
 		F79728D622F9A0B1003CACA7 /* NCShareUserFolderMenuView.xib in Resources */ = {isa = PBXBuildFile; fileRef = F79728D522F9A0B0003CACA7 /* NCShareUserFolderMenuView.xib */; };
 		F79918A221997FA300C2E308 /* UICKeyChainStore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F79918A021997F9000C2E308 /* UICKeyChainStore.framework */; };
 		F79918A221997FA300C2E308 /* UICKeyChainStore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F79918A021997F9000C2E308 /* UICKeyChainStore.framework */; };
@@ -586,7 +585,6 @@
 		F7956FC91B4886E60085DEA3 /* CCUploadFromOtherUpp.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCUploadFromOtherUpp.h; sourceTree = "<group>"; };
 		F7956FC91B4886E60085DEA3 /* CCUploadFromOtherUpp.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCUploadFromOtherUpp.h; sourceTree = "<group>"; };
 		F7956FCA1B4886E60085DEA3 /* CCUploadFromOtherUpp.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CCUploadFromOtherUpp.m; sourceTree = "<group>"; };
 		F7956FCA1B4886E60085DEA3 /* CCUploadFromOtherUpp.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CCUploadFromOtherUpp.m; sourceTree = "<group>"; };
 		F7956FCB1B4886E60085DEA3 /* CCUploadFromOtherUpp.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = CCUploadFromOtherUpp.storyboard; sourceTree = "<group>"; };
 		F7956FCB1B4886E60085DEA3 /* CCUploadFromOtherUpp.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = CCUploadFromOtherUpp.storyboard; sourceTree = "<group>"; };
-		F79630ED215527D40015EEA5 /* NCVideoCommon.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCVideoCommon.swift; sourceTree = "<group>"; };
 		F79728D322F96F2D003CACA7 /* NCShareLinkFolderMenuView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = NCShareLinkFolderMenuView.xib; sourceTree = "<group>"; };
 		F79728D322F96F2D003CACA7 /* NCShareLinkFolderMenuView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = NCShareLinkFolderMenuView.xib; sourceTree = "<group>"; };
 		F79728D522F9A0B0003CACA7 /* NCShareUserFolderMenuView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = NCShareUserFolderMenuView.xib; sourceTree = "<group>"; };
 		F79728D522F9A0B0003CACA7 /* NCShareUserFolderMenuView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = NCShareUserFolderMenuView.xib; sourceTree = "<group>"; };
 		F79918A021997F9000C2E308 /* UICKeyChainStore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UICKeyChainStore.framework; path = Carthage/Build/iOS/UICKeyChainStore.framework; sourceTree = "<group>"; };
 		F79918A021997F9000C2E308 /* UICKeyChainStore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UICKeyChainStore.framework; path = Carthage/Build/iOS/UICKeyChainStore.framework; sourceTree = "<group>"; };
@@ -1098,7 +1096,6 @@
 			isa = PBXGroup;
 			isa = PBXGroup;
 			children = (
 			children = (
 				F752011C25480387000BF3A7 /* NCVideoViewController.swift */,
 				F752011C25480387000BF3A7 /* NCVideoViewController.swift */,
-				F79630ED215527D40015EEA5 /* NCVideoCommon.swift */,
 				F70753F62542A9C000972D44 /* NCViewerImage.storyboard */,
 				F70753F62542A9C000972D44 /* NCViewerImage.storyboard */,
 				F70753EA2542A99800972D44 /* NCViewerImagePageContainer.swift */,
 				F70753EA2542A99800972D44 /* NCViewerImagePageContainer.swift */,
 				F70753F02542A9A200972D44 /* NCViewerImageZoom.swift */,
 				F70753F02542A9A200972D44 /* NCViewerImageZoom.swift */,
@@ -2143,7 +2140,6 @@
 				F765608F23BF813600765969 /* NCContentPresenter.swift in Sources */,
 				F765608F23BF813600765969 /* NCContentPresenter.swift in Sources */,
 				F70CEF5623E9C7E50007035B /* UIColor+adjust.swift in Sources */,
 				F70CEF5623E9C7E50007035B /* UIColor+adjust.swift in Sources */,
 				F75AC2431F1F62450073EC19 /* NCManageAutoUploadFileName.swift in Sources */,
 				F75AC2431F1F62450073EC19 /* NCManageAutoUploadFileName.swift in Sources */,
-				F79630EE215527D40015EEA5 /* NCVideoCommon.swift in Sources */,
 				F7CA1ED620E7E3FE002CC65E /* CALayer+PKDownloadButtonAnimations.m in Sources */,
 				F7CA1ED620E7E3FE002CC65E /* CALayer+PKDownloadButtonAnimations.m in Sources */,
 				F7C7B489245EBA4100D93E60 /* NCViewerQuickLook.swift in Sources */,
 				F7C7B489245EBA4100D93E60 /* NCViewerQuickLook.swift in Sources */,
 				F758B45E212C569D00515F55 /* ScanCell.swift in Sources */,
 				F758B45E212C569D00515F55 /* ScanCell.swift in Sources */,

+ 0 - 5
iOSClient/AppDelegate.m

@@ -277,11 +277,6 @@
     // Setting Theming
     // Setting Theming
     [[NCBrandColor sharedInstance] settingThemingColor];
     [[NCBrandColor sharedInstance] settingThemingColor];
     
     
-    // If AVPlayer in play -> Stop
-    if (NCVideoCommon.shared.player != nil && NCVideoCommon.shared.player.rate != 0) {
-        [NCVideoCommon.shared.player pause];
-    }
-    
     // close detail
     // close detail
     [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_notificationCenter_menuDetailClose object:nil];
     [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_notificationCenter_menuDetailClose object:nil];
     
     

+ 0 - 150
iOSClient/Viewer/NCViewerImageAudioVideo/NCVideoCommon.swift

@@ -1,150 +0,0 @@
-//
-//  NCVideoCommon.swift
-//  Nextcloud
-//
-//  Created by Marino Faggiana on 21/09/18.
-//  Copyright © 2018 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 Foundation
-import KTVHTTPCache
-
-class NCVideoCommon: NSObject {
-    @objc static let shared: NCVideoCommon = {
-        let viewVideo = NCVideoCommon()
-        viewVideo.setupHTTPCache()
-        return viewVideo
-    }()
-    
-    // Audio Video
-    @objc var player: AVPlayer!
-    @objc var playerController: AVPlayerViewController!
-    @objc var isMediaObserver: Bool = false
-    
-    var metadata: tableMetadata!
-    var videoURL: URL?
-    let appDelegate = UIApplication.shared.delegate as! AppDelegate
-   
-    @objc func viewMedia(_ metadata: tableMetadata, view: UIView, frame: CGRect) {
-        
-        var videoURLProxy: URL!
-
-        self.metadata = metadata
-        
-        if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
-        
-            self.videoURL = URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView))
-            videoURLProxy = videoURL
-        
-        } else {
-            
-            guard let stringURL = (metadata.serverUrl + "/" + metadata.fileName).addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) else {
-                return
-            }
-            
-            self.videoURL = URL(string: stringURL)
-            videoURLProxy = KTVHTTPCache.proxyURL(withOriginalURL: self.videoURL)
-            
-            guard let authData = (appDelegate.user + ":" + appDelegate.password).data(using: .utf8) else {
-                return
-            }
-            
-            let authValue = "Basic " + authData.base64EncodedString(options: [])
-            KTVHTTPCache.downloadSetAdditionalHeaders(["Authorization":authValue, "User-Agent":CCUtility.getUserAgent()])
-        }
-        
-        player = AVPlayer(url: videoURLProxy)
-        playerController = AVPlayerViewController()
-        
-        playerController.player = player
-        playerController.view.frame = frame
-        playerController.allowsPictureInPicturePlayback = false
-        
-        view.addSubview(playerController.view)
-        
-        NotificationCenter.default.addObserver(forName: .AVPlayerItemDidPlayToEndTime, object: nil, queue: nil) { (notification) in
-            let player = notification.object as! AVPlayerItem
-            player.seek(to: CMTime.zero, completionHandler: nil)
-        }
-        
-        DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
-            
-            self.player.addObserver(self, forKeyPath: "rate", options: [], context: nil)
-            self.isMediaObserver = true
-            
-            self.player.play()
-        }
-    }
-    
-    override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
-        
-        if keyPath != nil && keyPath == "rate" {
-            
-            if player.rate == 1 {
-                print("start")
-            } else {
-                print("stop")
-            }
-            
-            // Save cache
-            if !CCUtility.fileProviderStorageExists(self.metadata.ocId, fileNameView:self.metadata.fileNameView) {
-                
-                guard let url = KTVHTTPCache.cacheCompleteFileURL(with: self.videoURL) else {
-                    return
-                }
-                
-                CCUtility.copyFile(atPath: url.path, toPath: CCUtility.getDirectoryProviderStorageOcId(self.metadata.ocId, fileNameView: self.metadata.fileNameView))
-                NCManageDatabase.sharedInstance.addLocalFile(metadata: self.metadata)
-                KTVHTTPCache.cacheDelete(with: self.videoURL)
-                
-                NotificationCenter.default.postOnMainThread(name: k_notificationCenter_reloadDataSource, userInfo: ["ocId":self.metadata.ocId, "serverUrl":self.metadata.serverUrl])
-            }
-        }
-    }
-    
-    @objc func removeObserver() {
-        
-        player.removeObserver(self, forKeyPath: "rate", context: nil)
-        NotificationCenter.default.removeObserver(self, name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: nil)
-    }
-    
-    @objc func setupHTTPCache() {
-        
-        KTVHTTPCache.cacheSetMaxCacheLength(Int64(k_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
-        }
-    }
-}

+ 25 - 4
iOSClient/Viewer/NCViewerImageAudioVideo/NCVideoViewController.swift

@@ -19,6 +19,7 @@ class NCVideoViewController: AVPlayerViewController {
     override func viewDidLoad() {
     override func viewDidLoad() {
         super.viewDidLoad()
         super.viewDidLoad()
 
 
+        setupHTTPCache()
         
         
         if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
         if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
             
             
@@ -56,10 +57,11 @@ class NCVideoViewController: AVPlayerViewController {
     override func viewDidDisappear(_ animated: Bool) {
     override func viewDidDisappear(_ animated: Bool) {
         super.viewDidDisappear(animated)
         super.viewDidDisappear(animated)
         
         
-    }
-    
-    deinit {
-        
+        player?.pause()
+        removeObserver()
+        if KTVHTTPCache.proxyIsRunning() {
+            KTVHTTPCache.proxyStop()
+        }
     }
     }
     
     
     //MARK: - Observer
     //MARK: - Observer
@@ -100,6 +102,9 @@ class NCVideoViewController: AVPlayerViewController {
     
     
     @objc func setupHTTPCache() {
     @objc func setupHTTPCache() {
         
         
+        if KTVHTTPCache.proxyIsRunning() {
+            KTVHTTPCache.proxyStop()
+        }
         KTVHTTPCache.cacheSetMaxCacheLength(Int64(k_maxHTTPCache))
         KTVHTTPCache.cacheSetMaxCacheLength(Int64(k_maxHTTPCache))
         
         
         if ProcessInfo.processInfo.environment["SIMULATOR_DEVICE_NAME"] != nil {
         if ProcessInfo.processInfo.environment["SIMULATOR_DEVICE_NAME"] != nil {
@@ -123,3 +128,19 @@ class NCVideoViewController: AVPlayerViewController {
         }
         }
     }
     }
 }
 }
+
+/*
+ @IBAction func touchUpInsidecloseButton(_ sender: Any) {
+     
+     if NCVideoCommon.shared.player != nil && NCVideoCommon.shared.player.rate != 0 {
+         NCVideoCommon.shared.player.pause()
+     }
+     
+     if NCVideoCommon.shared.isMediaObserver {
+         NCVideoCommon.shared.isMediaObserver = false
+         NCVideoCommon.shared.removeObserver()
+     }
+
+     dismiss(animated: false) { }
+ }
+ */