Browse Source

change class name

marinofaggiana 3 years ago
parent
commit
08849aeac2

+ 11 - 11
Nextcloud.xcodeproj/project.pbxproj

@@ -275,8 +275,8 @@
 		F79EC77F26316193004E59D6 /* NCRenameFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = F70D87CE25EE6E58008CBBBD /* NCRenameFile.swift */; };
 		F79EC784263161BA004E59D6 /* NCRenameFile.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F70D87CD25EE6E58008CBBBD /* NCRenameFile.storyboard */; };
 		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 */; };
+		F79EDAA326B004980007D134 /* NCPlayerToolBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = F79EDA9F26B004980007D134 /* NCPlayerToolBar.swift */; };
+		F79EDAA526B004980007D134 /* NCPlayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = F79EDAA126B004980007D134 /* NCPlayer.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 */; };
@@ -675,8 +675,8 @@
 		F79A65C52191D95E00FF6DCC /* NCSelect.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCSelect.swift; sourceTree = "<group>"; };
 		F79B645F26CA661600838ACA /* UIControl+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIControl+Extensions.swift"; sourceTree = "<group>"; };
 		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>"; };
+		F79EDA9F26B004980007D134 /* NCPlayerToolBar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCPlayerToolBar.swift; sourceTree = "<group>"; };
+		F79EDAA126B004980007D134 /* NCPlayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCPlayer.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>"; };
@@ -1188,7 +1188,7 @@
 				F7F9D1BA25397CE000D9BFF5 /* NCViewer.swift */,
 				F7EFA47725ADBA500083159A /* NCViewerProviderContextMenu.swift */,
 				F79018B1240962C7007C9B6D /* NCViewerImage */,
-				F79EDA9E26B004980007D134 /* NCViewerVideo */,
+				F79EDA9E26B004980007D134 /* NCPlayer */,
 				F723986A253C9C0E00257F49 /* NCViewerQuickLook */,
 				F76D3CEF2428B3DD005DFA87 /* NCViewerPDF */,
 				F73D11FF253C5F5400DF9BEC /* NCViewerNextcloudText */,
@@ -1209,14 +1209,14 @@
 			path = Select;
 			sourceTree = "<group>";
 		};
-		F79EDA9E26B004980007D134 /* NCViewerVideo */ = {
+		F79EDA9E26B004980007D134 /* NCPlayer */ = {
 			isa = PBXGroup;
 			children = (
-				F79EDAA126B004980007D134 /* NCViewerVideo.swift */,
-				F79EDA9F26B004980007D134 /* NCViewerVideoToolBar.swift */,
+				F79EDAA126B004980007D134 /* NCPlayer.swift */,
+				F79EDA9F26B004980007D134 /* NCPlayerToolBar.swift */,
 				F716B75E26F09DF600D37EFC /* NCKTVHTTPCache.swift */,
 			);
-			path = NCViewerVideo;
+			path = NCPlayer;
 			sourceTree = "<group>";
 		};
 		F7A0D14E259229FA008F8A13 /* Extensions */ = {
@@ -2125,7 +2125,7 @@
 				F7DFB7F0219C5B8000680748 /* NCCreateFormUploadAssets.swift in Sources */,
 				F73B422C2476764F00A30FD3 /* NCNotification.swift in Sources */,
 				371B5A2E23D0B04500FAFAE9 /* NCMenu.swift in Sources */,
-				F79EDAA326B004980007D134 /* NCViewerVideoToolBar.swift in Sources */,
+				F79EDAA326B004980007D134 /* NCPlayerToolBar.swift in Sources */,
 				F77444F8222816D5000D5EB0 /* NCPickerViewController.swift in Sources */,
 				F72A47EC2487B06B005AD489 /* NCOperationQueue.swift in Sources */,
 				F769454622E9F1B0000A798A /* NCShareCommon.swift in Sources */,
@@ -2175,7 +2175,7 @@
 				F710D1F52405770F00A6033D /* NCViewerPDF.swift in Sources */,
 				F7501C332212E57500FB1415 /* NCMedia.swift in Sources */,
 				F70BFC7420E0FA7D00C67599 /* NCUtility.swift in Sources */,
-				F79EDAA526B004980007D134 /* NCViewerVideo.swift in Sources */,
+				F79EDAA526B004980007D134 /* NCPlayer.swift in Sources */,
 				F7C1EEA525053A9C00866ACC /* NCDataSource.swift in Sources */,
 				F713FF002472764100214AF6 /* UIImage+animatedGIF.m in Sources */,
 				F749C10B23C4A5340027D966 /* NCIntroCollectionViewCell.swift in Sources */,

+ 0 - 0
iOSClient/Viewer/NCViewerVideo/NCKTVHTTPCache.swift → iOSClient/Viewer/NCPlayer/NCKTVHTTPCache.swift


+ 40 - 59
iOSClient/Viewer/NCViewerVideo/NCViewerVideo.swift → iOSClient/Viewer/NCPlayer/NCPlayer.swift

@@ -1,5 +1,5 @@
 //
-//  NCViewerVideo.swift
+//  NCPlayer.swift
 //  Nextcloud
 //
 //  Created by Marino Faggiana on 01/07/21.
@@ -25,80 +25,66 @@ import Foundation
 import NCCommunication
 import UIKit
 
-class NCViewerVideo: NSObject {
+class NCPlayer: AVPlayer {
    
     private let appDelegate = UIApplication.shared.delegate as! AppDelegate
     private var imageVideoContainer: imageVideoContainerView?
     private var durationSeconds: Double = 0
-    private var viewerVideoToolBar: NCViewerVideoToolBar?
+    private var playerToolBar: NCPlayerToolBar?
 
     public var metadata: tableMetadata?
     public var videoLayer: AVPlayerLayer?
-    public var player: AVPlayer?
 
     //MARK: - NotificationCenter
 
     @objc func applicationDidEnterBackground(_ notification: NSNotification) {
         
         if metadata?.classFile == NCCommunicationCommon.typeClassFile.video.rawValue {
-            self.player?.pause()
+            self.pause()
         }
     }
     
-    init(viewerVideoToolBar: NCViewerVideoToolBar?, metadata: tableMetadata) {
-        super.init()
-                
-        NotificationCenter.default.addObserver(self, selector: #selector(applicationDidEnterBackground(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterApplicationDidEnterBackground), object: nil)
+    deinit {
+        print("deinit NCPlayer")
+    }
+    
+    func setupVideoLayer(imageVideoContainer: imageVideoContainerView?, playerToolBar: NCPlayerToolBar?, metadata: tableMetadata) {
+        
+        self.playerToolBar = playerToolBar
+        self.metadata = metadata
         
-        func initPlayer(url: URL) {
-                        
-            self.player = AVPlayer(url: url)
-            self.player?.isMuted = CCUtility.getAudioMute()
-            self.player?.seek(to: .zero)
+        isMuted = CCUtility.getAudioMute()
+        seek(to: .zero)
 
-            // At end go back to start & show toolbar
-            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)
-                    self.viewerVideoToolBar?.showToolBar(metadata: metadata)
-                    NCKTVHTTPCache.shared.saveCache(metadata: metadata)
-                }
+        // At end go back to start & show toolbar
+        NotificationCenter.default.addObserver(forName: .AVPlayerItemDidPlayToEndTime, object: currentItem, queue: .main) { (notification) in
+            if let item = notification.object as? AVPlayerItem, let currentItem = self.currentItem, item == currentItem {
+                self.seek(to: .zero)
+                self.playerToolBar?.showToolBar(metadata: metadata)
+                NCKTVHTTPCache.shared.saveCache(metadata: metadata)
             }
-            
-            // save durationSeconds on database
-            if let duration: CMTime = (player?.currentItem?.asset.duration) {
-                durationSeconds = CMTimeGetSeconds(duration)
-                NCManageDatabase.shared.addVideoTime(metadata: metadata, time: nil, durationSeconds: durationSeconds)
-            }
-            
-            // NO Live Photo, seek to datamebase time
-            if !metadata.livePhoto, let time = NCManageDatabase.shared.getVideoTime(metadata: metadata) {
-                self.player?.seek(to: time)
-            }
-            
-            viewerVideoToolBar?.setBarPlayer(viewerVideo: self)
         }
         
-        if let url = NCKTVHTTPCache.shared.getVideoURL(metadata: metadata) {
-            
-            self.viewerVideoToolBar = viewerVideoToolBar
-            self.metadata = metadata
-
-            initPlayer(url: url)
-        }        
-    }
-    
-    deinit {
-        print("deinit NCViewerVideo")
-    }
-    
-    func setupVideoLayer(imageVideoContainer: imageVideoContainerView?) {
+        // save durationSeconds on database
+        if let duration: CMTime = (currentItem?.asset.duration) {
+            durationSeconds = CMTimeGetSeconds(duration)
+            NCManageDatabase.shared.addVideoTime(metadata: metadata, time: nil, durationSeconds: durationSeconds)
+        }
+        
+        // NO Live Photo, seek to datamebase time
+        if !metadata.livePhoto, let time = NCManageDatabase.shared.getVideoTime(metadata: metadata) {
+            seek(to: time)
+        }
+        
+        playerToolBar?.setBarPlayer(player: self)
+        
+        NotificationCenter.default.addObserver(self, selector: #selector(applicationDidEnterBackground(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterApplicationDidEnterBackground), object: nil)
         
         if let imageVideoContainer = imageVideoContainer {
         
             self.imageVideoContainer = imageVideoContainer
 
-            self.videoLayer = AVPlayerLayer(player: self.player)
+            self.videoLayer = AVPlayerLayer(player: self)
             self.videoLayer!.frame = imageVideoContainer.bounds
             self.videoLayer!.videoGravity = .resizeAspect
         
@@ -110,16 +96,14 @@ class NCViewerVideo: NSObject {
     
     func videoPlay() {
                 
-        self.player?.play()
+        play()
     }
     
     func videoPause() {
         guard let metadata = self.metadata else { return }
         
-        self.player?.pause()
-        if let time = self.player?.currentTime() {
-            NCManageDatabase.shared.addVideoTime(metadata: metadata, time: time, durationSeconds: nil)
-        }
+        pause()
+        NCManageDatabase.shared.addVideoTime(metadata: metadata, time: currentTime(), durationSeconds: nil)
         
         NCKTVHTTPCache.shared.saveCache(metadata: metadata)
     }
@@ -127,7 +111,7 @@ class NCViewerVideo: NSObject {
     func videoSeek(time: CMTime) {
         guard let metadata = self.metadata else { return }
         
-        self.player?.seek(to: time)
+        seek(to: time)
         NCManageDatabase.shared.addVideoTime(metadata: metadata, time: time, durationSeconds: nil)
     }
     
@@ -140,10 +124,7 @@ class NCViewerVideo: NSObject {
     
     func getVideoCurrentSeconds() -> Float64 {
         
-        if let currentTime = player?.currentTime() {
-            return CMTimeGetSeconds(currentTime)
-        }
-        return 0
+        return CMTimeGetSeconds(currentTime())
     }
     
     func getVideoDurationSeconds() -> Float64 {

+ 26 - 28
iOSClient/Viewer/NCViewerVideo/NCViewerVideoToolBar.swift → iOSClient/Viewer/NCPlayer/NCPlayerToolBar.swift

@@ -1,5 +1,5 @@
 //
-//  NCViewerVideoToolBar.swift
+//  NCPlayerToolBar.swift
 //  Nextcloud
 //
 //  Created by Marino Faggiana on 01/07/21.
@@ -24,7 +24,7 @@
 import Foundation
 import NCCommunication
 
-class NCViewerVideoToolBar: UIView {
+class NCPlayerToolBar: UIView {
     
     @IBOutlet weak var playButton: UIButton!
     @IBOutlet weak var muteButton: UIButton!
@@ -40,7 +40,7 @@ class NCViewerVideoToolBar: UIView {
         case moved
     }
         
-    private var viewerVideo: NCViewerVideo!
+    private var player: NCPlayer!
     private var wasInPlay: Bool = false
     private var playbackSliderEvent: sliderEventType = .ended
     private let seekDuration: Float64 = 15
@@ -84,26 +84,26 @@ class NCViewerVideoToolBar: UIView {
     }
     
     deinit {
-        print("deinit NCViewerVideoToolBar")
+        print("deinit NCPlayerToolBar")
     }
     
-    func setBarPlayer(viewerVideo: NCViewerVideo) {
+    func setBarPlayer(player: NCPlayer) {
                         
-        self.viewerVideo = viewerVideo
+        self.player = player
         
         playbackSlider.value = 0
         playbackSlider.minimumValue = 0
-        playbackSlider.maximumValue = Float(viewerVideo.getVideoDurationSeconds())
+        playbackSlider.maximumValue = Float(player.getVideoDurationSeconds())
         playbackSlider.addTarget(self, action: #selector(onSliderValChanged(slider:event:)), for: .valueChanged)
 
         labelCurrentTime.text = NCUtility.shared.stringFromTimeInterval(interval: 0)
-        labelOverallDuration.text = "-" + NCUtility.shared.stringFromTimeInterval(interval:viewerVideo.getVideoDurationSeconds())
+        labelOverallDuration.text = "-" + NCUtility.shared.stringFromTimeInterval(interval:player.getVideoDurationSeconds())
                 
         updateToolBar()
         
-        viewerVideo.player?.addPeriodicTimeObserver(forInterval: CMTimeMakeWithSeconds(1, preferredTimescale: 1), queue: .main, using: { (CMTime) in
+        player.addPeriodicTimeObserver(forInterval: CMTimeMakeWithSeconds(1, preferredTimescale: 1), queue: .main, using: { (CMTime) in
             
-            if viewerVideo.player?.currentItem?.status == .readyToPlay {
+            if player.currentItem?.status == .readyToPlay {
                 if self.isHidden == false {
                     self.updateToolBar()
                 }
@@ -148,9 +148,9 @@ class NCViewerVideoToolBar: UIView {
     public func updateToolBar() {
 
         var namedPlay = "play.fill"
-        if viewerVideo.player?.rate == 1 { namedPlay = "pause.fill"}
-        let currentSeconds = viewerVideo.getVideoCurrentSeconds()
-        let durationSeconds = viewerVideo.getVideoDurationSeconds()
+        if player.rate == 1 { namedPlay = "pause.fill"}
+        let currentSeconds = player.getVideoCurrentSeconds()
+        let durationSeconds = player.getVideoDurationSeconds()
         
         playbackSlider.value = Float(currentSeconds)
         playbackSlider.isEnabled = true
@@ -190,16 +190,16 @@ class NCViewerVideoToolBar: UIView {
             
             switch touchEvent.phase {
             case .began:
-                wasInPlay = viewerVideo.player?.rate == 1 ? true : false
-                viewerVideo.videoPause()
+                wasInPlay = player.rate == 1 ? true : false
+                player.videoPause()
                 playbackSliderEvent = .began
             case .moved:
-                viewerVideo.videoSeek(time: targetTime)
+                player.videoSeek(time: targetTime)
                 playbackSliderEvent = .moved
             case .ended:
-                viewerVideo.videoSeek(time: targetTime)
+                player.videoSeek(time: targetTime)
                 if wasInPlay {
-                    viewerVideo.videoPlay()
+                    player.videoPlay()
                 }
                 playbackSliderEvent = .ended
             default:
@@ -220,10 +220,10 @@ class NCViewerVideoToolBar: UIView {
     
     @IBAction func playerPause(_ sender: Any) {
         
-        if viewerVideo.player?.timeControlStatus == .playing {
-            viewerVideo.videoPause()
-        } else if viewerVideo.player?.timeControlStatus == .paused {
-            viewerVideo.videoPlay()
+        if player.timeControlStatus == .playing {
+            player.videoPause()
+        } else if player.timeControlStatus == .paused {
+            player.videoPlay()
         }
     }
         
@@ -232,24 +232,22 @@ class NCViewerVideoToolBar: UIView {
         let mute = CCUtility.getAudioMute()
         
         CCUtility.setAudioMute(!mute)
-        viewerVideo.player?.isMuted = !mute
+        player.isMuted = !mute
         updateToolBar()
     }
     
     @IBAction func forwardButtonSec(_ sender: Any) {
-        guard let player = viewerVideo.player else { return }
         
         let playerCurrentTime = CMTimeGetSeconds(player.currentTime())
         let newTime = playerCurrentTime + seekDuration
         
-        if newTime < viewerVideo.getVideoDurationSeconds() {
+        if newTime < player.getVideoDurationSeconds() {
             let time: CMTime = CMTimeMake(value: Int64(newTime * 1000 as Float64), timescale: 1000)
-            viewerVideo.videoSeek(time: time)
+            player.videoSeek(time: time)
         }
     }
     
     @IBAction func backButtonSec(_ sender: Any) {
-        guard let player = viewerVideo.player else { return }
 
         let playerCurrenTime = CMTimeGetSeconds(player.currentTime())
         var newTime = playerCurrenTime - seekDuration
@@ -257,6 +255,6 @@ class NCViewerVideoToolBar: UIView {
         if newTime < 0 { newTime = 0 }
         let time: CMTime = CMTimeMake(value: Int64(newTime * 1000 as Float64), timescale: 1000)
         
-        viewerVideo.videoSeek(time: time)
+        player.videoSeek(time: time)
     }
 }

+ 2 - 2
iOSClient/Viewer/NCViewerImage/NCViewerImage.storyboard

@@ -229,7 +229,7 @@
                                             <outlet property="sizeValue" destination="XLb-0a-du9" id="9jm-Ku-sgt"/>
                                         </connections>
                                     </view>
-                                    <view hidden="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="sBp-t2-eFh" customClass="NCViewerVideoToolBar" customModule="Nextcloud" customModuleProvider="target">
+                                    <view hidden="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="sBp-t2-eFh" customClass="NCPlayerToolBar" customModule="Nextcloud" customModuleProvider="target">
                                         <rect key="frame" x="25" y="626" width="364" height="100"/>
                                         <subviews>
                                             <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="a0D-B0-eGX">
@@ -374,10 +374,10 @@
                         <outlet property="imageVideoContainer" destination="kPV-JM-UnM" id="2pA-VW-FuK"/>
                         <outlet property="imageViewBottomConstraint" destination="vEd-X2-yGs" id="wp3-67-aZ2"/>
                         <outlet property="imageViewTopConstraint" destination="tdo-XY-uqv" id="AM2-tz-fSt"/>
+                        <outlet property="playerToolBar" destination="sBp-t2-eFh" id="E24-0a-bN6"/>
                         <outlet property="scrollView" destination="CdQ-LC-Trx" id="3np-FR-s39"/>
                         <outlet property="statusLabel" destination="DAi-gz-qGP" id="zZH-1B-HiI"/>
                         <outlet property="statusViewImage" destination="2AU-85-K8y" id="22h-Ec-bj0"/>
-                        <outlet property="videoToolBar" destination="sBp-t2-eFh" id="mee-f9-Nko"/>
                     </connections>
                 </viewController>
                 <placeholder placeholderIdentifier="IBFirstResponder" id="fbE-Jv-mLH" userLabel="First Responder" sceneMemberID="firstResponder"/>

+ 16 - 12
iOSClient/Viewer/NCViewerImage/NCViewerImage.swift

@@ -50,7 +50,7 @@ class NCViewerImage: UIViewController {
     var nextIndex: Int?
        
     var currentViewerImageZoom: NCViewerImageZoom?
-    var viewerVideo: NCViewerVideo?
+    var player: NCPlayer?
     
     var panGestureRecognizer: UIPanGestureRecognizer!
     var singleTapGestureRecognizer: UITapGestureRecognizer!
@@ -132,7 +132,7 @@ class NCViewerImage: UIViewController {
     override func viewWillDisappear(_ animated: Bool) {
         super.viewWillDisappear(animated)
         
-        currentViewerImageZoom?.viewerVideo?.videoPause()
+        currentViewerImageZoom?.player?.videoPause()
 
         NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterDeleteFile), object: nil)
         NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterRenameFile), object: nil)
@@ -274,9 +274,11 @@ class NCViewerImage: UIViewController {
                     
                     AudioServicesPlaySystemSound(1519) // peek feedback
                     
-                    self.viewerVideo = NCViewerVideo.init(viewerVideoToolBar: nil, metadata: metadata)
-                    self.viewerVideo?.setupVideoLayer(imageVideoContainer: self.currentViewerImageZoom?.imageVideoContainer)
-                    self.viewerVideo?.videoPlay()
+                    if let url = NCKTVHTTPCache.shared.getVideoURL(metadata: metadata) {
+                        self.player = NCPlayer.init(url: url)
+                        self.player?.setupVideoLayer(imageVideoContainer: self.currentViewerImageZoom?.imageVideoContainer, playerToolBar: nil, metadata: metadata)
+                        self.player?.videoPlay()
+                    }
                     
                 } else {
                     
@@ -302,9 +304,11 @@ class NCViewerImage: UIViewController {
                             if gestureRecognizer.state == .changed || gestureRecognizer.state == .began {
                                 AudioServicesPlaySystemSound(1519) // peek feedback
                                 
-                                self.viewerVideo = NCViewerVideo.init(viewerVideoToolBar: nil, metadata: metadata)
-                                self.viewerVideo?.setupVideoLayer(imageVideoContainer: self.currentViewerImageZoom?.imageVideoContainer)
-                                self.viewerVideo?.videoPlay()
+                                if let url = NCKTVHTTPCache.shared.getVideoURL(metadata: metadata) {
+                                    self.player = NCPlayer.init(url: url)
+                                    self.player?.setupVideoLayer(imageVideoContainer: self.currentViewerImageZoom?.imageVideoContainer, playerToolBar: nil, metadata: metadata)
+                                    self.player?.videoPlay()
+                                }
                             }
                         }
                     }
@@ -315,7 +319,7 @@ class NCViewerImage: UIViewController {
             
             currentViewerImageZoom?.statusViewImage.isHidden = false
             currentViewerImageZoom?.statusLabel.isHidden = false
-            self.viewerVideo?.videoRemoved()
+            self.player?.videoRemoved()
         }
     }
     
@@ -449,7 +453,7 @@ extension NCViewerImage: UIPageViewControllerDelegate, UIPageViewControllerDataS
         guard let nextViewController = pendingViewControllers.first as? NCViewerImageZoom else { return }
         nextIndex = nextViewController.index
         
-        currentViewerImageZoom?.viewerVideo?.videoPause()
+        currentViewerImageZoom?.player?.videoPause()
     }
     
     func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {
@@ -510,8 +514,8 @@ extension NCViewerImage: UIGestureRecognizerDelegate {
     
     @objc func didSingleTapWith(gestureRecognizer: UITapGestureRecognizer) {
              
-        if let viewerVideoToolBar = currentViewerImageZoom?.videoToolBar {
-            if viewerVideoToolBar.showToolBar(metadata: currentMetadata) {
+        if let playerToolBar = currentViewerImageZoom?.playerToolBar {
+            if playerToolBar.showToolBar(metadata: currentMetadata) {
                 return
             }
         }

+ 11 - 12
iOSClient/Viewer/NCViewerImage/NCViewerImageZoom.swift

@@ -40,11 +40,11 @@ class NCViewerImageZoom: UIViewController {
     @IBOutlet weak var statusViewImage: UIImageView!
     @IBOutlet weak var statusLabel: UILabel!
     @IBOutlet weak var detailView: NCViewerImageDetailView!
-    @IBOutlet weak var videoToolBar: NCViewerVideoToolBar!
+    @IBOutlet weak var playerToolBar: NCPlayerToolBar!
     
     var delegate: NCViewerImageZoomDelegate?
     var viewerImage: NCViewerImage?
-    var viewerVideo: NCViewerVideo?
+    var player: NCPlayer?
     
     var image: UIImage?
     var metadata: tableMetadata = tableMetadata()
@@ -81,7 +81,7 @@ class NCViewerImageZoom: UIViewController {
             }
             // Show Video Toolbar
             if !metadata.livePhoto {
-                videoToolBar.isHidden = false
+                playerToolBar.isHidden = false
             }
         } else if metadata.classFile == NCCommunicationCommon.typeClassFile.audio.rawValue {
             if image == nil {
@@ -111,9 +111,10 @@ class NCViewerImageZoom: UIViewController {
         detailView.update(metadata: metadata, image: image, heightMap: heightMap)
         detailView.hide()
         
-        if metadata.classFile == NCCommunicationCommon.typeClassFile.video.rawValue || metadata.classFile == NCCommunicationCommon.typeClassFile.audio.rawValue {
-            self.viewerVideo = NCViewerVideo.init(viewerVideoToolBar: self.videoToolBar, metadata: self.metadata)
-            self.viewerImage?.viewerVideo = self.viewerVideo
+        if metadata.classFile == NCCommunicationCommon.typeClassFile.video.rawValue || metadata.classFile == NCCommunicationCommon.typeClassFile.audio.rawValue,  let url = NCKTVHTTPCache.shared.getVideoURL(metadata: metadata) {
+            
+//            self.viewerVideo = NCViewerVideo.init(url: url, viewerVideoToolBar: self.videoToolBar, metadata: self.metadata)
+//            self.viewerImage?.viewerVideo = self.viewerVideo
         }
     }
     
@@ -123,7 +124,7 @@ class NCViewerImageZoom: UIViewController {
         delegate?.didAppearImageZoom(viewerImageZoom: self, metadata: metadata)
         
         DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
-            self.viewerVideo?.setupVideoLayer(imageVideoContainer: self.imageVideoContainer)
+//            self.viewerVideo?.setupVideoLayer(imageVideoContainer: self.imageVideoContainer)
         }
     }
     
@@ -135,8 +136,6 @@ class NCViewerImageZoom: UIViewController {
             self.scrollView.zoom(to: CGRect(x: 0, y: 0, width: self.scrollView.bounds.width, height: self.scrollView.bounds.height), animated: false)
             self.view.layoutIfNeeded()
             UIView.animate(withDuration: context.transitionDuration) {
-                // resize frame video
-                //NCViewerVideo.shared.videoLayer?.frame = self.imageView.layer.bounds
                 // resize detail
                 if self.detailView.isShow() {
                     self.openDetail()
@@ -157,7 +156,7 @@ class NCViewerImageZoom: UIViewController {
         if detailView.isShow() { return }
         
         // NO ZOOM for Audio / Video
-        if (metadata.classFile == NCCommunicationCommon.typeClassFile.video.rawValue || metadata.classFile == NCCommunicationCommon.typeClassFile.audio.rawValue) && !videoToolBar.isHidden {
+        if (metadata.classFile == NCCommunicationCommon.typeClassFile.video.rawValue || metadata.classFile == NCCommunicationCommon.typeClassFile.audio.rawValue) && !playerToolBar.isHidden {
             return
         }
         
@@ -255,7 +254,7 @@ extension NCViewerImageZoom {
         
         scrollView.pinchGestureRecognizer?.isEnabled = false
         
-        videoToolBar.hideToolBar()
+        playerToolBar.hideToolBar()
     }
     
     private func closeDetail() {
@@ -273,7 +272,7 @@ extension NCViewerImageZoom {
         
         scrollView.pinchGestureRecognizer?.isEnabled = true
         
-        videoToolBar.showToolBar(metadata: metadata)
+        playerToolBar.showToolBar(metadata: metadata)
     }
 }