marinofaggiana 3 år sedan
förälder
incheckning
0e549506bc

+ 0 - 4
Nextcloud.xcodeproj/project.pbxproj

@@ -277,7 +277,6 @@
 		F79EC78926316AC4004E59D6 /* NCPopupViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F702F30725EE5D47008F8E80 /* NCPopupViewController.swift */; };
 		F79EDAA326B004980007D134 /* NCViewerVideoToolBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = F79EDA9F26B004980007D134 /* NCViewerVideoToolBar.swift */; };
 		F79EDAA526B004980007D134 /* NCViewerVideo.swift in Sources */ = {isa = PBXBuildFile; fileRef = F79EDAA126B004980007D134 /* NCViewerVideo.swift */; };
-		F79EDAA626B004980007D134 /* NCViewerAVPlayerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F79EDAA226B004980007D134 /* NCViewerAVPlayerViewController.swift */; };
 		F7A0D1352591FBC5008F8A13 /* String+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7A0D1342591FBC5008F8A13 /* String+Extensions.swift */; };
 		F7A0D1362591FBC5008F8A13 /* String+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7A0D1342591FBC5008F8A13 /* String+Extensions.swift */; };
 		F7A0D1372591FBC5008F8A13 /* String+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7A0D1342591FBC5008F8A13 /* String+Extensions.swift */; };
@@ -678,7 +677,6 @@
 		F79B869A265E19D40085C0E0 /* NSMutableAttributedString+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSMutableAttributedString+Extensions.swift"; sourceTree = "<group>"; };
 		F79EDA9F26B004980007D134 /* NCViewerVideoToolBar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCViewerVideoToolBar.swift; sourceTree = "<group>"; };
 		F79EDAA126B004980007D134 /* NCViewerVideo.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCViewerVideo.swift; sourceTree = "<group>"; };
-		F79EDAA226B004980007D134 /* NCViewerAVPlayerViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCViewerAVPlayerViewController.swift; sourceTree = "<group>"; };
 		F7A0D1342591FBC5008F8A13 /* String+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+Extensions.swift"; sourceTree = "<group>"; };
 		F7A321AB1E9E6AD50069AD1B /* CCAdvanced.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCAdvanced.h; sourceTree = "<group>"; };
 		F7A321AC1E9E6AD50069AD1B /* CCAdvanced.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CCAdvanced.m; sourceTree = "<group>"; };
@@ -1217,7 +1215,6 @@
 				F716B75E26F09DF600D37EFC /* NCKTVHTTPCache.swift */,
 				F79EDA9F26B004980007D134 /* NCViewerVideoToolBar.swift */,
 				F79EDAA126B004980007D134 /* NCViewerVideo.swift */,
-				F79EDAA226B004980007D134 /* NCViewerAVPlayerViewController.swift */,
 			);
 			path = NCViewerVideo;
 			sourceTree = "<group>";
@@ -2198,7 +2195,6 @@
 				F7EFA47825ADBA500083159A /* NCViewerProviderContextMenu.swift in Sources */,
 				F755BD9B20594AC7008C5FBB /* NCService.swift in Sources */,
 				F79B869B265E19D40085C0E0 /* NSMutableAttributedString+Extensions.swift in Sources */,
-				F79EDAA626B004980007D134 /* NCViewerAVPlayerViewController.swift in Sources */,
 				F7B7504B2397D38F004E13EC /* UIImage+Extensions.swift in Sources */,
 				F7EFC0CD256BF8DD00461AAD /* NCUserStatus.swift in Sources */,
 				F7DFB7F4219C5CA800680748 /* NCCreateFormUploadScanDocument.swift in Sources */,

+ 1 - 1
iOSClient/AppDelegate.swift

@@ -48,7 +48,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
     @objc var activeMedia: NCMedia?
     var activeServerUrl: String = ""
     @objc var activeViewController: UIViewController?
-    var activeViewerAVPlayerViewController: NCViewerAVPlayerViewController?
+    //var activeViewerAVPlayerViewController: NCViewerAVPlayerViewController?
     var mainTabBar: NCMainTabBar?
     var activeMetadata: tableMetadata?
     

+ 4 - 17
iOSClient/Viewer/NCViewerImage/NCViewerImage.swift

@@ -523,10 +523,11 @@ extension NCViewerImage: UIGestureRecognizerDelegate {
             return
         }
         
+        /*
         if currentMetadata.classFile == NCCommunicationCommon.typeClassFile.video.rawValue || currentMetadata.classFile == NCCommunicationCommon.typeClassFile.audio.rawValue {
             
             if self.viewerVideo?.pictureInPictureOcId != currentMetadata.ocId {
-                                
+                   
                 // Kill PIP
                 appDelegate.activeViewerAVPlayerViewController?.player?.replaceCurrentItem(with: nil)
                 // --------
@@ -543,7 +544,8 @@ extension NCViewerImage: UIGestureRecognizerDelegate {
             
             currentMode = .full
         }
-                    
+        */
+        
         if currentMode == .full {
             
             navigationController?.setNavigationBarHidden(false, animated: false)
@@ -641,18 +643,3 @@ extension NCViewerImage: NCViewerImageZoomDelegate {
     }
 }
 
-//MARK: - NCViewerVideoDelegate
-
-extension NCViewerImage: NCViewerAVPlayerViewControllerDelegate {
-    
-    func startPictureInPicture(metadata: tableMetadata) {
-        self.viewerVideo?.pictureInPictureOcId = metadata.ocId
-    }
-    
-    func stopPictureInPicture(metadata: tableMetadata, playing: Bool) {
-        self.viewerVideo?.pictureInPictureOcId = ""
-        if playing && currentMetadata.ocId == metadata.ocId {
-            self.viewerVideo?.viewerVideoToolBar?.playerPause(self)
-        }
-    }
-}

+ 0 - 166
iOSClient/Viewer/NCViewerVideo/NCViewerAVPlayerViewController.swift

@@ -1,166 +0,0 @@
-//
-//  NCViewerAVPlayerViewController.swift
-//  Nextcloud
-//
-//  Created by Marino Faggiana on 27/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 AVKit
-import NCCommunication
-
-protocol NCViewerAVPlayerViewControllerDelegate {
-    func startPictureInPicture(metadata: tableMetadata)
-    func stopPictureInPicture(metadata: tableMetadata, playing: Bool)
-}
-
-class NCViewerAVPlayerViewController: AVPlayerViewController {
-    
-    let appDelegate = UIApplication.shared.delegate as! AppDelegate
-    var metadata = tableMetadata()
-    var pictureInPicture: Bool = false
-    var imageBackground: UIImage?
-    var delegateViewerVideo: NCViewerAVPlayerViewControllerDelegate?
-    private var rateObserverToken: Any?
-
-    // MARK: - View Life Cycle
-
-    override func viewDidLoad() {
-        super.viewDidLoad()
-        
-        delegate = self
-    }
-    
-    override func viewDidAppear(_ animated: Bool) {
-        super.viewDidAppear(animated)
-        
-        NCKTVHTTPCache.shared.startProxy(user: appDelegate.user, password: appDelegate.password, metadata: metadata)
-        
-        func play(url: URL) {
-            
-            player = AVPlayer(url: url)
-            
-            if  metadata.classFile == NCCommunicationCommon.typeClassFile.audio.rawValue {
-                                
-                let imageView = UIImageView.init(image: imageBackground)
-                imageView.translatesAutoresizingMaskIntoConstraints = false
-                contentOverlayView?.addSubview(imageView)
-                
-                if let view = contentOverlayView {
-                    NSLayoutConstraint.activate([
-                        imageView.centerYAnchor.constraint(equalTo: view.centerYAnchor),
-                        imageView.centerXAnchor.constraint(equalTo: view.centerXAnchor),
-                        imageView.heightAnchor.constraint(equalToConstant: view.frame.height/3),
-                        imageView.widthAnchor.constraint(equalToConstant: view.frame.height/3),
-                    ])
-                }
-            }
-        
-            // 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: CMTime.zero)
-                }
-            }
-        
-            rateObserverToken = player?.addObserver(self, forKeyPath: "rate", options: [], context: nil)
-            
-            player?.play()
-            if let time = NCManageDatabase.shared.getVideoTime(metadata: self.metadata) {
-                player?.seek(to: time)
-            }
-            player?.isMuted = CCUtility.getAudioMute()
-            
-            // AIRPLAY
-            if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
-                player?.allowsExternalPlayback = true
-            } else {
-                player?.allowsExternalPlayback = false
-            }
-        }
-        
-        if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
-            
-            play(url: URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)))
-            
-        } else {
-            
-            /*
-            NCCommunication.shared.getDirectDownload(fileId: metadata.fileId) { account, url, errorCode, errorDescription in
-                
-                if let url = URL(string: url) {
-                    play(url: url)
-                }
-            }
-            */
-            
-            if let url = NCKTVHTTPCache.shared.getVideoURL(metadata: metadata) {
-                play(url: url)
-            }
-            
-        }
-    }
-    
-    override func viewWillDisappear(_ animated: Bool) {
-        super.viewWillDisappear(animated)
-        
-        NCManageDatabase.shared.addVideoTime(metadata: metadata, time: player?.currentTime())
-        
-        if let player = self.player {
-            CCUtility.setAudioMute(player.isMuted)
-        }
-        
-        if !pictureInPicture {
-            player?.pause()
-            
-            if rateObserverToken != nil {
-                player?.removeObserver(self, forKeyPath: "rate")
-                NotificationCenter.default.removeObserver(self, name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: nil)
-                NCKTVHTTPCache.shared.stopProxy(metadata: metadata)
-                self.rateObserverToken = nil
-            }
-        }
-    }
-    
-    override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
-        
-        if keyPath != nil && keyPath == "rate" {
-           NCKTVHTTPCache.shared.saveCache(metadata: metadata)
-        }
-    }
-}
-
-extension NCViewerAVPlayerViewController: AVPlayerViewControllerDelegate {
-    
-    func playerViewControllerShouldAutomaticallyDismissAtPictureInPictureStart(_ playerViewController: AVPlayerViewController) -> Bool {
-        true
-    }
-    
-    func playerViewControllerDidStartPictureInPicture(_ playerViewController: AVPlayerViewController) {
-        pictureInPicture = true
-        delegateViewerVideo?.startPictureInPicture(metadata: metadata)
-    }
-    
-    func playerViewControllerWillStopPictureInPicture(_ playerViewController: AVPlayerViewController) {
-        NCManageDatabase.shared.addVideoTime(metadata: metadata, time: player?.currentTime())
-        pictureInPicture = false
-        let playing = player?.timeControlStatus == .playing
-        delegateViewerVideo?.stopPictureInPicture(metadata: metadata, playing: playing)
-    }
-}

+ 0 - 26
iOSClient/Viewer/NCViewerVideo/NCViewerVideo.swift

@@ -96,7 +96,6 @@ class NCViewerVideo: NSObject {
             
             // TOOLBAR
             viewerVideoToolBar?.setPlayer(player: player)
-            viewerVideoToolBar?.setToolBar()
         }
         
         //NCNetworking.shared.getVideoUrl(metadata: metadata) { url in
@@ -145,31 +144,6 @@ class NCViewerVideo: NSObject {
                     player?.isMuted = CCUtility.getAudioMute()
                 }
                 
-                /*
-                if rateObserver != nil && !metadata.livePhoto {
-                    self.progressView?.progress = 0
-                    if let duration = self.player?.currentItem?.asset.duration {
-                        let durationSeconds = Double(CMTimeGetSeconds(duration))
-                        if durationSeconds > 0 {
-                            let width = Double(self.progressView?.bounds.width ?? 0)
-                            let interval = (0.5 * durationSeconds) / width
-                            let time = CMTime(seconds: interval, preferredTimescale: CMTimeScale(NSEC_PER_SEC))
-                            if CMTIME_IS_VALID(time) && CMTimeCompare(time, .zero) != 0 {
-                                self.timeObserver = self.player?.addPeriodicTimeObserver(forInterval: time, queue: .main, using: { [weak self] time in
-                                    let durationSeconds = Float(CMTimeGetSeconds(duration))
-                                    if durationSeconds > 0 {
-                                        let currentTimeSeconds = Float(CMTimeGetSeconds(time))
-                                        self?.progressView?.progress = currentTimeSeconds / durationSeconds
-                                    } else {
-                                        self?.progressView?.progress = 0
-                                    }
-                                })
-                            }
-                        }
-                    }
-                }
-                */
-                
             } else if !metadata.livePhoto {
                 
                 if let time = player?.currentTime(), let duration = self.player?.currentItem?.asset.duration {

+ 24 - 13
iOSClient/Viewer/NCViewerVideo/NCViewerVideoToolBar.swift

@@ -50,6 +50,22 @@ class NCViewerVideoToolBar: UIView {
             blurEffectView.frame = self.bounds
             blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
             self.insertSubview(blurEffectView, at:0)
+            
+            playbackSlider.value = 0
+            playbackSlider.minimumValue = 0
+            playbackSlider.maximumValue = 0
+            playbackSlider.isContinuous = true
+            playbackSlider.tintColor = .lightGray
+            
+            labelCurrentTime.text = stringFromTimeInterval(interval: 0)
+            labelCurrentTime.textColor = .lightGray
+            labelOverallDuration.text = stringFromTimeInterval(interval: 0)
+            labelOverallDuration.textColor = .lightGray
+            
+            backButton.setImage(NCUtility.shared.loadImage(named: "gobackward.15", color: .white), for: .normal)
+            forwardButton.setImage(NCUtility.shared.loadImage(named: "goforward.15", color: .white), for: .normal)
+
+            setToolBar()
         }
     }
     
@@ -59,10 +75,10 @@ class NCViewerVideoToolBar: UIView {
         let duration: CMTime = (player?.currentItem?.asset.duration)!
         let durationSeconds: Float64 = CMTimeGetSeconds(duration)
         
+        playbackSlider.value = 0
         playbackSlider.minimumValue = 0
         playbackSlider.maximumValue = Float(durationSeconds)
-        playbackSlider.isContinuous = true
-        playbackSlider.tintColor = .lightGray
+        
         playbackSlider.action(for: .valueChanged) { _ in
             let seconds : Int64 = Int64(self.playbackSlider.value)
             let targetTime:CMTime = CMTimeMake(value: seconds, timescale: 1)
@@ -73,9 +89,7 @@ class NCViewerVideoToolBar: UIView {
         }
         
         labelCurrentTime.text = stringFromTimeInterval(interval: 0)
-        labelCurrentTime.textColor = .lightGray
         labelOverallDuration.text = "-" + stringFromTimeInterval(interval: durationSeconds)
-        labelOverallDuration.textColor = .lightGray
         
         player?.addPeriodicTimeObserver(forInterval: CMTimeMakeWithSeconds(1, preferredTimescale: 1), queue: .main, using: { (CMTime) in
             
@@ -86,26 +100,23 @@ class NCViewerVideoToolBar: UIView {
                 self.labelOverallDuration.text = "-" + self.stringFromTimeInterval(interval: durationSeconds - currentSeconds)
             }
         })
+        
+        setToolBar()
     }
     
-    func setToolBar() {
-        
-        let mute = CCUtility.getAudioMute()
-        
-        if  player?.rate == 1 {
+    public func setToolBar() {
+
+        if player?.rate == 1 {
             playButton.setImage(NCUtility.shared.loadImage(named: "pause.fill", color: .white), for: .normal)
         } else {
             playButton.setImage(NCUtility.shared.loadImage(named: "play.fill", color: .white), for: .normal)
         }
        
-        if mute {
+        if CCUtility.getAudioMute() {
             muteButton.setImage(NCUtility.shared.loadImage(named: "audioOff", color: .white), for: .normal)
         } else {
             muteButton.setImage(NCUtility.shared.loadImage(named: "audioOn", color: .white), for: .normal)
         }
-        
-        backButton.setImage(NCUtility.shared.loadImage(named: "gobackward.15", color: .white), for: .normal)
-        forwardButton.setImage(NCUtility.shared.loadImage(named: "goforward.15", color: .white), for: .normal)
     }
 
     //MARK: - Action