Marino Faggiana 2 жил өмнө
parent
commit
00d8b594c8

+ 3 - 8
iOSClient/Viewer/NCViewerMedia/NCPlayer/NCPlayer.swift

@@ -77,7 +77,7 @@ class NCPlayer: NSObject {
         player?.media = VLCMedia(url: url)
         player?.delegate = self
 
-        player?.media?.addOption("--network-caching=5000")
+        // player?.media?.addOption("--network-caching=5000")
         player?.media?.addOption(":http-user-agent=\(userAgent)")
 
         let volume = CCUtility.getAudioVolume()
@@ -210,16 +210,13 @@ extension NCPlayer: VLCMediaPlayerDelegate {
             print("Played mode: STOPPED")
             break
         case .opening:
-            playerToolBar?.buffering()
             print("Played mode: OPENING")
             break
         case .buffering:
-            playerToolBar?.buffering()
             print("Played mode: BUFFERING")
             break
         case .ended:
             print("Played mode: ENDED")
-            playerToolBar?.update(position: player.position)
             break
         case .error:
             let error = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_error_something_wrong_")
@@ -235,16 +232,15 @@ extension NCPlayer: VLCMediaPlayerDelegate {
                     }
                 }
             }
-            // let metaDictionary = player.media?.metaData
             print("Played mode: PLAYING")
             break
         case .paused:
             print("Played mode: PAUSED")
-            playerToolBar?.update(position: player.position)
             break
         default: break
         }
 
+        playerToolBar?.update(position: player.position)
         print(player.state)
     }
 
@@ -271,8 +267,7 @@ extension NCPlayer: VLCMediaPlayerDelegate {
            let data = image.jpegData(compressionQuality: 0.5) {
             try? data.write(to: URL(fileURLWithPath: fileNameIconLocalPath))
         }
-        print("Snapshot saved")
-
+        print("Snapshot saved on \(fileNameIconLocalPath)")
     }
 
     func mediaPlayerStartedRecording(_ player: VLCMediaPlayer) {

+ 22 - 41
iOSClient/Viewer/NCViewerMedia/NCPlayer/NCPlayerToolBar.swift

@@ -55,7 +55,7 @@ class NCPlayerToolBar: UIView {
     private var timerAutoHideSeconds: Double {
         get {
             if NCUtility.shared.isSimulator() { // for test
-                return 15
+                return 150
             } else {
                 return 3.5
             }
@@ -88,24 +88,19 @@ class NCPlayerToolBar: UIView {
         playbackSlider.maximumValue = 1
         playbackSlider.isContinuous = true
         playbackSlider.tintColor = .lightGray
-        playbackSlider.isEnabled = false
 
         labelCurrentTime.text = NCUtility.shared.stringFromTime(.zero)
-        labelCurrentTime.textColor = .lightGray
+        labelCurrentTime.textColor = .white
         labelLeftTime.text = NCUtility.shared.stringFromTime(.zero)
-        labelLeftTime.textColor = .lightGray
+        labelLeftTime.textColor = .white
 
-        muteButton.setImage(NCUtility.shared.loadImage(named: "audioOff", color: .lightGray), for: .normal)
-        muteButton.isEnabled = false
+        muteButton.setImage(NCUtility.shared.loadImage(named: "audioOff", color: .white), for: .normal)
 
-        playButton.setImage(NCUtility.shared.loadImage(named: "play.fill", color: .lightGray, symbolConfiguration: UIImage.SymbolConfiguration(pointSize: 30)), for: .normal)
-        playButton.isEnabled = false
+        playButton.setImage(NCUtility.shared.loadImage(named: "play.fill", color: .white, symbolConfiguration: UIImage.SymbolConfiguration(pointSize: 30)), for: .normal)
 
-        backButton.setImage(NCUtility.shared.loadImage(named: "gobackward.10", color: .lightGray), for: .normal)
-        backButton.isEnabled = false
+        backButton.setImage(NCUtility.shared.loadImage(named: "gobackward.10", color: .white), for: .normal)
 
-        forwardButton.setImage(NCUtility.shared.loadImage(named: "goforward.10", color: .lightGray), for: .normal)
-        forwardButton.isEnabled = false
+        forwardButton.setImage(NCUtility.shared.loadImage(named: "goforward.10", color: .white), for: .normal)
     }
 
     required init?(coder aDecoder: NSCoder) {
@@ -133,15 +128,6 @@ class NCPlayerToolBar: UIView {
         update(position: position)
     }
 
-    public func buffering() {
-
-        muteButton.isEnabled = false
-        playButton.isEnabled = false
-        forwardButton.isEnabled = false
-        backButton.isEnabled = false
-        playbackSlider.isEnabled = false
-    }
-
     public func update(position: Float?) {
 
         guard let ncplayer = self.ncplayer,
@@ -149,6 +135,7 @@ class NCPlayerToolBar: UIView {
               let position = position
         else { return }
         let positionInSecond = position * Float(length / 1000)
+        let status = ncplayer.player?.state
 
         // SAVE POSITION
         if position > 0 {
@@ -163,41 +150,35 @@ class NCPlayerToolBar: UIView {
             } else {
                 muteButton.setImage(NCUtility.shared.loadImage(named: "audioOn", color: .white), for: .normal)
             }
-            muteButton.isEnabled = true
         }
 
-        // SLIDER TIME (START - END)
+        // SLIDER & TIME
         playbackSlider.value = position
-        playbackSlider.isEnabled = true
         labelCurrentTime.text = ncplayer.player?.time.stringValue
         labelLeftTime.text = ncplayer.player?.remainingTime?.stringValue
         MPNowPlayingInfoCenter.default().nowPlayingInfo?[MPMediaItemPropertyPlaybackDuration] = length / 1000
         MPNowPlayingInfoCenter.default().nowPlayingInfo?[MPNowPlayingInfoPropertyElapsedPlaybackTime] = positionInSecond
 
-        // BACK FORWARD
-        if length > 0 {
-            forwardButton.isEnabled = true
-            forwardButton.setImage(NCUtility.shared.loadImage(named: "goforward.10", color: .white), for: .normal)
-            backButton.isEnabled = true
-            backButton.setImage(NCUtility.shared.loadImage(named: "gobackward.10", color: .white), for: .normal)
-        } else {
-            backButton.isEnabled = false
-            backButton.setImage(NCUtility.shared.loadImage(named: "gobackward.10", color: .lightGray), for: .normal)
-            forwardButton.isEnabled = false
-            forwardButton.setImage(NCUtility.shared.loadImage(named: "goforward.10", color: .lightGray), for: .normal)
-        }
-
         // 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)
         }
-        let namedPlay = ncplayer.isPlay() ? "pause.fill" : "play.fill"
-        playButton.setImage(NCUtility.shared.loadImage(named: namedPlay, color: .white, symbolConfiguration: UIImage.SymbolConfiguration(pointSize: 30)), for: .normal)
-        playButton.isEnabled = true
-
 
+        if status == .error {
+            playButton.isEnabled = false
+            forwardButton.isEnabled = false
+            backButton.isEnabled = false
+            playbackSlider.isEnabled = false
+        } else {
+            playButton.isEnabled = true
+            forwardButton.isEnabled = true
+            backButton.isEnabled = true
+            playbackSlider.isEnabled = true
+        }
     }
 
     // MARK: -