marinofaggiana 3 tahun lalu
induk
melakukan
ae936f3ade

+ 19 - 1
iOSClient/Viewer/NCViewerImage/NCViewerImage.storyboard

@@ -270,6 +270,18 @@
                                                     <action selector="playerPause:" destination="sBp-t2-eFh" eventType="touchUpInside" id="pRl-bT-hpi"/>
                                                 </connections>
                                             </button>
+                                            <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="00:00:00" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="kVv-X4-6SK">
+                                                <rect key="frame" x="9.9999999999999964" y="45" width="52.666666666666657" height="14.333333333333336"/>
+                                                <fontDescription key="fontDescription" type="system" pointSize="12"/>
+                                                <nil key="textColor"/>
+                                                <nil key="highlightedColor"/>
+                                            </label>
+                                            <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="99:99:99" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="OUD-HH-cXH">
+                                                <rect key="frame" x="301" y="42" width="53" height="14.333333333333336"/>
+                                                <fontDescription key="fontDescription" type="system" pointSize="12"/>
+                                                <nil key="textColor"/>
+                                                <nil key="highlightedColor"/>
+                                            </label>
                                         </subviews>
                                         <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
                                         <constraints>
@@ -279,10 +291,16 @@
                                             <constraint firstAttribute="height" constant="100" id="EyI-HW-pHA"/>
                                             <constraint firstAttribute="trailing" secondItem="SR4-e8-1hC" secondAttribute="trailing" constant="10" id="Q3r-ex-Cpf"/>
                                             <constraint firstItem="SR4-e8-1hC" firstAttribute="leading" secondItem="sBp-t2-eFh" secondAttribute="leading" constant="10" id="Xec-gd-9AB"/>
+                                            <constraint firstAttribute="trailing" secondItem="OUD-HH-cXH" secondAttribute="trailing" constant="10" id="j5v-RG-0JI"/>
+                                            <constraint firstItem="kVv-X4-6SK" firstAttribute="top" secondItem="SR4-e8-1hC" secondAttribute="bottom" id="l6a-l5-ZvL"/>
                                             <constraint firstItem="x3E-b2-obf" firstAttribute="centerX" secondItem="sBp-t2-eFh" secondAttribute="centerX" id="uPa-tM-Vx6"/>
                                             <constraint firstItem="SR4-e8-1hC" firstAttribute="top" secondItem="sBp-t2-eFh" secondAttribute="top" constant="15" id="uu1-ai-wmJ"/>
+                                            <constraint firstItem="OUD-HH-cXH" firstAttribute="top" secondItem="SR4-e8-1hC" secondAttribute="bottom" constant="-3" id="wwk-tz-5dj"/>
+                                            <constraint firstItem="kVv-X4-6SK" firstAttribute="leading" secondItem="sBp-t2-eFh" secondAttribute="leading" constant="10" id="yee-JQ-gRq"/>
                                         </constraints>
                                         <connections>
+                                            <outlet property="labelCurrentTime" destination="kVv-X4-6SK" id="vyf-Bb-TPL"/>
+                                            <outlet property="labelOverallDuration" destination="OUD-HH-cXH" id="E0O-99-aeq"/>
                                             <outlet property="muteButton" destination="8AB-hx-yqN" id="9zQ-k7-auv"/>
                                             <outlet property="playButton" destination="x3E-b2-obf" id="0Nw-L4-W7M"/>
                                             <outlet property="playbackSlider" destination="SR4-e8-1hC" id="Khx-Oe-NEQ"/>
@@ -334,7 +352,7 @@
                 </viewController>
                 <placeholder placeholderIdentifier="IBFirstResponder" id="fbE-Jv-mLH" userLabel="First Responder" sceneMemberID="firstResponder"/>
             </objects>
-            <point key="canvasLocation" x="4547.826086956522" y="777.45535714285711"/>
+            <point key="canvasLocation" x="4547.826086956522" y="776.9021739130435"/>
         </scene>
     </scenes>
     <resources>

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

@@ -583,7 +583,7 @@ extension NCViewerImage: NCViewerImageZoomDelegate {
         currentMetadata = metadata
         currentViewerImageZoom = viewerImageZoom
         viewerImageZoom.videoToolBar.isHidden = true
-        viewerVideo = NCViewerVideo.init(view: viewerImageZoom.imageView, progressView: progressView, viewerVideoToolBar: viewerImageZoom.videoToolBar)
+        viewerVideo = NCViewerVideo.init(view: viewerImageZoom.imageView, viewerVideoToolBar: viewerImageZoom.videoToolBar)
         
         if (currentMetadata.classFile == NCCommunicationCommon.typeClassFile.video.rawValue || currentMetadata.classFile == NCCommunicationCommon.typeClassFile.audio.rawValue) {
             DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {

+ 3 - 5
iOSClient/Viewer/NCViewerVideo/NCViewerVideo.swift

@@ -27,8 +27,6 @@ import NCCommunication
 class NCViewerVideo: NSObject {
     
     private let appDelegate = UIApplication.shared.delegate as! AppDelegate
-    private var progressView: UIProgressView?
-
     private var videoLayer: AVPlayerLayer?
     private var view: UIView?
     private var timeObserver: Any?
@@ -39,11 +37,10 @@ class NCViewerVideo: NSObject {
     public var player: AVPlayer?
     public var pictureInPictureOcId: String = ""
     
-    init(view: UIView?, progressView: UIProgressView?, viewerVideoToolBar: NCViewerVideoToolBar?) {
+    init(view: UIView?, viewerVideoToolBar: NCViewerVideoToolBar?) {
         super.init()
 
         self.view = view
-        self.progressView = progressView
         self.viewerVideoToolBar = viewerVideoToolBar
         
         NotificationCenter.default.addObserver(self, selector: #selector(applicationDidEnterBackground(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterApplicationDidEnterBackground), object: nil)
@@ -117,7 +114,6 @@ class NCViewerVideo: NSObject {
         
         player?.pause()
         player?.seek(to: CMTime.zero)
-//        progressView.progress = 0
         
         if let timeObserver = timeObserver {
             player?.removeTimeObserver(timeObserver)
@@ -149,6 +145,7 @@ class NCViewerVideo: NSObject {
                     player?.isMuted = CCUtility.getAudioMute()
                 }
                 
+                /*
                 if rateObserver != nil && !metadata.livePhoto {
                     self.progressView?.progress = 0
                     if let duration = self.player?.currentItem?.asset.duration {
@@ -171,6 +168,7 @@ class NCViewerVideo: NSObject {
                         }
                     }
                 }
+                */
                 
             } else if !metadata.livePhoto {
                 

+ 34 - 8
iOSClient/Viewer/NCViewerVideo/NCViewerVideoToolBar.swift

@@ -28,7 +28,9 @@ class NCViewerVideoToolBar: UIView {
     @IBOutlet weak var playButton: UIButton!
     @IBOutlet weak var muteButton: UIButton!
     @IBOutlet weak var playbackSlider: UISlider!
-
+    @IBOutlet weak var labelOverallDuration: UILabel!
+    @IBOutlet weak var labelCurrentTime: UILabel!
+    
     var player: AVPlayer?
     
     override func willMove(toWindow newWindow: UIWindow?) {
@@ -66,6 +68,20 @@ class NCViewerVideoToolBar: UIView {
                 self.player?.play()
             }
         }
+        
+        labelCurrentTime.text = stringFromTimeInterval(interval: 0)
+        labelCurrentTime.textColor = .white
+        labelOverallDuration.text = stringFromTimeInterval(interval: seconds)
+        labelOverallDuration.textColor = .white
+        
+        player?.addPeriodicTimeObserver(forInterval: CMTimeMakeWithSeconds(1, preferredTimescale: 1), queue: .main, using: { (CMTime) in
+            
+            if self.player?.currentItem?.status == .readyToPlay {
+                let time: Float64 = CMTimeGetSeconds(self.player!.currentTime())
+                self.playbackSlider.value = Float(time)
+                self.labelCurrentTime.text = self.stringFromTimeInterval(interval: time)
+            }
+        })
     }
     
     func setToolBar() {
@@ -105,13 +121,23 @@ class NCViewerVideoToolBar: UIView {
     
     @objc func playbackSliderValueChanged(_ playbackSlider:UISlider) {
            
-           let seconds : Int64 = Int64(playbackSlider.value)
-           let targetTime:CMTime = CMTimeMake(value: seconds, timescale: 1)
+        let seconds : Int64 = Int64(playbackSlider.value)
+        let targetTime:CMTime = CMTimeMake(value: seconds, timescale: 1)
            
-           player?.seek(to: targetTime)
+        player?.seek(to: targetTime)
            
-           if player?.rate == 0 {
-               player?.play()
-           }
-       }
+        if player?.rate == 0 {
+            player?.play()
+        }
+    }
+    
+    func stringFromTimeInterval(interval: TimeInterval) -> String {
+    
+        let interval = Int(interval)
+        let seconds = interval % 60
+        let minutes = (interval / 60) % 60
+        let hours = (interval / 3600)
+        
+        return String(format: "%02d:%02d:%02d", hours, minutes, seconds)
+    }
 }