Marino Faggiana 2 lat temu
rodzic
commit
a61b77f452

+ 6 - 11
iOSClient/Viewer/NCViewerMedia/NCPlayer/NCPlayer.swift

@@ -93,13 +93,13 @@ class NCPlayer: NSObject {
             }
         }
 
-        player?.drawable = self.imageVideoContainer
+        player?.drawable = imageVideoContainer
         if let view = player?.drawable as? UIView {
             view.isUserInteractionEnabled = true
             view.addGestureRecognizer(singleTapGestureRecognizer)
         }
 
-        playerToolBar?.setBarPlayer(ncplayer: self, position: position, metadata: self.metadata)
+        playerToolBar?.setBarPlayer(ncplayer: self, position: position, metadata: metadata)
 
         if let media = player?.media {
             thumbnailer = VLCMediaThumbnailer(media: media, andDelegate: self)
@@ -140,7 +140,7 @@ class NCPlayer: NSObject {
 
     @objc func applicationDidBecomeActive(_ notification: NSNotification) {
 
-        playerToolBar?.update(position: player?.position)
+        playerToolBar?.update()
     }
 
     // MARK: -
@@ -154,11 +154,8 @@ class NCPlayer: NSObject {
 
         player?.play()
 
-        if let position = NCManageDatabase.shared.getVideoPosition(metadata: self.metadata) {
+        if let position = NCManageDatabase.shared.getVideoPosition(metadata: metadata) {
             player?.position = position
-            playerToolBar?.update(position: position)
-        } else {
-            playerToolBar?.update(position: player?.position)
         }
     }
 
@@ -169,13 +166,11 @@ class NCPlayer: NSObject {
         }
 
         player?.pause()
-        playerToolBar?.update(position: player?.position)
     }
 
     func videoSeek(position: Float) {
 
         player?.position = position
-        playerToolBar?.update(position: position)
     }
 
     func savePosition(_ position: Float) {
@@ -241,13 +236,13 @@ extension NCPlayer: VLCMediaPlayerDelegate {
         default: break
         }
 
-        playerToolBar?.update(position: player.position)
+        playerToolBar?.update()
         print(player.state)
     }
 
     func mediaPlayerTimeChanged(_ aNotification: Notification) {
         print("\(player?.time.stringValue) - \(player?.position)")
-        playerToolBar?.update(position: player?.position)
+        playerToolBar?.update()
     }
 
     func mediaPlayerTitleChanged(_ aNotification: Notification) {

+ 7 - 18
iOSClient/Viewer/NCViewerMedia/NCPlayer/NCPlayerToolBar.swift

@@ -89,9 +89,7 @@ class NCPlayerToolBar: UIView {
         playbackSlider.isContinuous = true
         playbackSlider.tintColor = .lightGray
 
-        labelCurrentTime.text = NCUtility.shared.stringFromTime(.zero)
         labelCurrentTime.textColor = .white
-        labelLeftTime.text = NCUtility.shared.stringFromTime(.zero)
         labelLeftTime.textColor = .white
 
         muteButton.setImage(NCUtility.shared.loadImage(named: "audioOn", color: .white), for: .normal)
@@ -133,17 +131,16 @@ class NCPlayerToolBar: UIView {
         }
 
         show(enableTimerAutoHide: false)
-        update(position: position)
+        update()
     }
 
-    public func update(position: Float?) {
+    public func update() {
 
         guard let ncplayer = self.ncplayer,
               let length = ncplayer.player?.media?.length.intValue,
-              let position = position
+              let position = ncplayer.player?.position
         else { return }
         let positionInSecond = position * Float(length / 1000)
-        let status = ncplayer.player?.state
 
         // SLIDER & TIME
         playbackSlider.value = position
@@ -151,15 +148,6 @@ class NCPlayerToolBar: UIView {
         labelLeftTime.text = ncplayer.player?.remainingTime?.stringValue
         MPNowPlayingInfoCenter.default().nowPlayingInfo?[MPMediaItemPropertyPlaybackDuration] = length / 1000
         MPNowPlayingInfoCenter.default().nowPlayingInfo?[MPNowPlayingInfoPropertyElapsedPlaybackTime] = positionInSecond
-
-        // PLAY
-        if ncplayer.isPlay() {
-            playButton.setImage(NCUtility.shared.loadImage(named: "pause.fill", color: .white, symbolConfiguration: UIImage.SymbolConfiguration(pointSize: 30)), for: .normal)
-            MPNowPlayingInfoCenter.default().nowPlayingInfo?[MPNowPlayingInfoPropertyPlaybackRate] = 1
-        } else {
-            MPNowPlayingInfoCenter.default().nowPlayingInfo?[MPNowPlayingInfoPropertyPlaybackRate] = 0
-            playButton.setImage(NCUtility.shared.loadImage(named: "play.fill", color: .white, symbolConfiguration: UIImage.SymbolConfiguration(pointSize: 30)), for: .normal)
-        }
     }
 
     public func disableAllControl() {
@@ -190,7 +178,7 @@ class NCPlayerToolBar: UIView {
             self.isHidden = false
         })
 
-        update(position: ncplayer?.player?.position)
+        update()
     }
 
     func isShow() -> Bool {
@@ -241,7 +229,6 @@ class NCPlayerToolBar: UIView {
         }
 
         ncplayer.videoSeek(position: newPosition)
-        update(position: newPosition)
         reStartTimerAutoHide()
     }
 
@@ -258,7 +245,7 @@ class NCPlayerToolBar: UIView {
               let ncplayer = ncplayer
         else { return }
 
-        let newPosition = self.playbackSlider.value
+        let newPosition = playbackSlider.value
 
         switch touchEvent.phase {
         case .began:
@@ -289,9 +276,11 @@ class NCPlayerToolBar: UIView {
 
         if ncplayer.isPlay() {
             ncplayer.playerPause()
+            playButton.setImage(NCUtility.shared.loadImage(named: "play.fill", color: .white, symbolConfiguration: UIImage.SymbolConfiguration(pointSize: 30)), for: .normal)
             timerAutoHide?.invalidate()
         } else {
             ncplayer.playerPlay()
+            playButton.setImage(NCUtility.shared.loadImage(named: "pause.fill", color: .white, symbolConfiguration: UIImage.SymbolConfiguration(pointSize: 30)), for: .normal)
             startTimerAutoHide()
         }
     }