Marino Faggiana il y a 2 ans
Parent
commit
c3f558f2c1

+ 2 - 2
Nextcloud.xcodeproj/project.pbxproj

@@ -1818,11 +1818,11 @@
 		F79018B1240962C7007C9B6D /* NCViewerMedia */ = {
 			isa = PBXGroup;
 			children = (
-				F79EDA9E26B004980007D134 /* NCPlayer */,
+				F718C24D254D507B00C5C256 /* NCViewerMediaDetailView.swift */,
 				F70753F62542A9C000972D44 /* NCViewerMediaPage.storyboard */,
 				F70753EA2542A99800972D44 /* NCViewerMediaPage.swift */,
-				F718C24D254D507B00C5C256 /* NCViewerMediaDetailView.swift */,
 				F70753F02542A9A200972D44 /* NCViewerMedia.swift */,
+				F79EDA9E26B004980007D134 /* NCPlayer */,
 			);
 			path = NCViewerMedia;
 			sourceTree = "<group>";

+ 13 - 10
iOSClient/Viewer/NCViewerMedia/NCPlayer/NCPlayer.swift

@@ -80,6 +80,8 @@ class NCPlayer: NSObject {
 
     func openAVPlayer(url: URL) {
 
+        var position: Float = 0
+
         self.url = url
         self.singleTapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(didSingleTapWith(gestureRecognizer:)))
 
@@ -111,7 +113,8 @@ class NCPlayer: NSObject {
             player?.audio?.volume = Int32(volume)
         } else {
             player?.audio?.volume = Int32(volume)
-            if let position = NCManageDatabase.shared.getVideoPosition(metadata: metadata) {
+            if let result = NCManageDatabase.shared.getVideoPosition(metadata: metadata) {
+                position = result
                 player?.position = position
             }
         }
@@ -129,7 +132,7 @@ class NCPlayer: NSObject {
             playerToolBar?.show(enableTimerAutoHide: false)
         }
 
-        playerToolBar?.setBarPlayer(ncplayer: self)
+        playerToolBar?.setBarPlayer(ncplayer: self, position: position)
         playerToolBar?.setMetadata(self.metadata)
     }
 
@@ -163,7 +166,7 @@ class NCPlayer: NSObject {
 
     @objc func applicationDidBecomeActive(_ notification: NSNotification) {
 
-        playerToolBar?.update()
+        playerToolBar?.update(position: player?.position)
     }
 
     // MARK: -
@@ -181,13 +184,13 @@ class NCPlayer: NSObject {
             player?.position = position
         }
         
-        playerToolBar?.update()
+        playerToolBar?.update(position: player?.position)
     }
 
     @objc func playerPause() {
 
         player?.pause()
-        playerToolBar?.update()
+        playerToolBar?.update(position: player?.position)
 
         if let playerToolBar = self.playerToolBar, playerToolBar.isPictureInPictureActive() {
             playerToolBar.pictureInPictureController?.stopPictureInPicture()
@@ -197,7 +200,7 @@ class NCPlayer: NSObject {
     func videoSeek(position: Float) {
 
         player?.position = position
-        playerToolBar?.update()
+        playerToolBar?.update(position: position)
     }
 
     func savePosition(_ position: Float) {
@@ -281,18 +284,18 @@ extension NCPlayer: VLCMediaPlayerDelegate {
             break
         case .ended:
             print("Played mode: ENDED")
-            playerToolBar?.update()
+            playerToolBar?.update(position: player.position)
             break
         case .error:
             print("Played mode: ERROR")
             break
         case .playing:
             print("Played mode: PLAYING")
-            playerToolBar?.update()
+            playerToolBar?.update(position: player.position)
             break
         case .paused:
             print("Played mode: PAUSED")
-            playerToolBar?.update()
+            playerToolBar?.update(position: player.position)
             break
         default: break
         }
@@ -302,7 +305,7 @@ extension NCPlayer: VLCMediaPlayerDelegate {
 
     func mediaPlayerTimeChanged(_ aNotification: Notification) {
 
-        self.playerToolBar?.update()
+        self.playerToolBar?.update(position: player?.position)
     }
 
     func mediaPlayerTitleChanged(_ aNotification: Notification) {

+ 8 - 9
iOSClient/Viewer/NCViewerMedia/NCPlayer/NCPlayerToolBar.swift

@@ -139,25 +139,24 @@ class NCPlayerToolBar: UIView {
         self.metadata = metadata
     }
 
-    func setBarPlayer(ncplayer: NCPlayer) {
+    func setBarPlayer(ncplayer: NCPlayer, position: Float) {
 
         self.ncplayer = ncplayer
 
-        playbackSlider.value = ncplayer.player?.position ?? 0
+        playbackSlider.value = position
         playbackSlider.addTarget(self, action: #selector(onSliderValChanged(slider:event:)), for: .valueChanged)
 
         labelCurrentTime.text = ncplayer.player?.time.stringValue
         labelLeftTime.text = ncplayer.player?.remainingTime?.stringValue
 
-        update()
+        update(position: position)
     }
 
-    public func update() {
+    public func update(position: Float?) {
 
-        guard let ncplayer = self.ncplayer else { return }
+        guard let ncplayer = self.ncplayer, let position = position else { return }
 
         // SAVE POSITION
-        let position = ncplayer.player?.position ?? 0
         if position > 0 {
             ncplayer.savePosition(position)
         }
@@ -235,7 +234,7 @@ class NCPlayerToolBar: UIView {
             self.isHidden = false
         })
 
-        update()
+        update(position: ncplayer?.player?.position)
     }
 
     func isShow() -> Bool {
@@ -282,7 +281,7 @@ class NCPlayerToolBar: UIView {
 
         ncplayer.videoSeek(position: newPosition)
 
-        update()
+        update(position: ncplayer.player?.position)
         reStartTimerAutoHide()
     }
 
@@ -356,7 +355,7 @@ class NCPlayerToolBar: UIView {
             ncplayer?.player?.audio?.volume = 100
         }
 
-        update()
+        update(position: ncplayer?.player?.position)
         reStartTimerAutoHide()
     }