marinofaggiana vor 3 Jahren
Ursprung
Commit
7a78fd4f68

+ 11 - 11
iOSClient/Data/NCManageDatabase.swift

@@ -3128,7 +3128,7 @@ class NCManageDatabase: NSObject {
     //MARK: -
     //MARK: Table Video
     
-    func addVideoTime(metadata: tableMetadata, time: CMTime?, duration: CMTime?) {
+    func addVideoTime(metadata: tableMetadata, time: CMTime?, durationTime: CMTime?) {
         
         if metadata.livePhoto { return }
         let realm = try! Realm()
@@ -3137,11 +3137,11 @@ class NCManageDatabase: NSObject {
             try realm.safeWrite {
                 if let result = realm.objects(tableVideo.self).filter("account == %@ AND ocId == %@", metadata.account, metadata.ocId).first {
                     
-                    if let duration = duration {
-                        result.duration = Int64(CMTimeGetSeconds(duration)) * 1000
+                    if let durationTime = durationTime {
+                        result.duration = durationTime.value
                     }
                     if let time = time {
-                        result.time = Int64(CMTimeGetSeconds(time)) * 1000
+                        result.time = time.value
                     }
                     realm.add(result, update: .all)
 
@@ -3150,12 +3150,12 @@ class NCManageDatabase: NSObject {
                     let addObject = tableVideo()
                    
                     addObject.account = metadata.account
-                    if let duration = duration {
-                        addObject.duration = Int64(CMTimeGetSeconds(duration)) * 1000
+                    if let durationTime = durationTime {
+                        addObject.duration = durationTime.value //Int64(CMTimeGetSeconds(duration)) * 1000
                     }
                     addObject.ocId = metadata.ocId
                     if let time = time {
-                        addObject.time = Int64(CMTimeGetSeconds(time)) * 1000
+                        addObject.time = time.value //Int64(CMTimeGetSeconds(time)) * 1000
                     }
                     realm.add(addObject, update: .all)
                 }
@@ -3165,7 +3165,7 @@ class NCManageDatabase: NSObject {
         }
     }
     
-    func getVideoDuration(metadata: tableMetadata?) -> CMTime? {
+    func getVideoDurationTime(metadata: tableMetadata?) -> CMTime? {
         guard let metadata = metadata else { return nil }
 
         if metadata.livePhoto { return nil }
@@ -3176,7 +3176,7 @@ class NCManageDatabase: NSObject {
         }
         
         if result.duration == 0 { return nil }
-        let duration = CMTimeMake(value: result.duration, timescale: 1000)
+        let duration = CMTimeMake(value: result.duration, timescale: 0)
         return duration
     }
     
@@ -3190,11 +3190,11 @@ class NCManageDatabase: NSObject {
         }
         
         if result.time == 0 { return nil }
-        let time = CMTimeMake(value: result.time, timescale: 1000)
+        let time = CMTimeMake(value: result.time, timescale: 0)
         return time
     }
     
-    func deleteVideoTime(metadata: tableMetadata) {
+    func deleteVideo(metadata: tableMetadata) {
         
         let realm = try! Realm()
 

+ 2 - 2
iOSClient/Networking/NCNetworking.swift

@@ -1009,7 +1009,7 @@ import Queuer
             
             for metadata in metadatas {
             
-                NCManageDatabase.shared.deleteVideoTime(metadata: metadata)
+                NCManageDatabase.shared.deleteVideo(metadata: metadata)
                 NCManageDatabase.shared.deleteLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
                 NCUtilityFileSystem.shared.deleteFile(filePath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId))
             
@@ -1072,7 +1072,7 @@ import Queuer
                     try FileManager.default.removeItem(atPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId))
                 } catch { }
                       
-                NCManageDatabase.shared.deleteVideoTime(metadata: metadata)
+                NCManageDatabase.shared.deleteVideo(metadata: metadata)
                 NCManageDatabase.shared.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
                 NCManageDatabase.shared.deleteLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
 

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

@@ -177,15 +177,15 @@ class NCPlayer: NSObject {
         self.metadata = nil
     }
     
-    func getVideoCurrentSeconds() -> Float64 {
-        
-        return CMTimeGetSeconds(self.player?.currentTime() ?? .zero)
-    }
+//    func getVideoCurrentSeconds() -> Float64 {
+//
+//        return CMTimeGetSeconds(self.player?.currentTime() ?? .zero)
+//    }
     
-    func getVideoDurationSeconds() -> Float64 {
-        
-        return self.durationSeconds
-    }
+//    func getVideoDurationSeconds() -> Float64 {
+//
+//        return self.durationSeconds
+//    }
     
     func generatorImagePreview() {
         guard let time = self.player?.currentTime() else { return }

+ 27 - 25
iOSClient/Viewer/NCViewerMedia/NCPlayer/NCPlayerToolBar.swift

@@ -91,15 +91,16 @@ class NCPlayerToolBar: UIView {
     func setBarPlayer(ncplayer: NCPlayer) {
                         
         self.ncplayer = ncplayer
+        if let durationTime = NCManageDatabase.shared.getVideoDurationTime(metadata: ncplayer.metadata) {
         
-        playbackSlider.value = 0
-        playbackSlider.minimumValue = 0
-        playbackSlider.maximumValue = Float(ncplayer.getVideoDurationSeconds())
-        playbackSlider.addTarget(self, action: #selector(onSliderValChanged(slider:event:)), for: .valueChanged)
+            playbackSlider.value = 0
+            playbackSlider.minimumValue = 0
+            playbackSlider.maximumValue = Float(durationTime.value)
+            playbackSlider.addTarget(self, action: #selector(onSliderValChanged(slider:event:)), for: .valueChanged)
 
-        labelCurrentTime.text = NCUtility.shared.stringFromTime(.zero)
-        labelOverallDuration.text = "-" + NCUtility.shared.stringFromTimeInterval(interval:ncplayer.getVideoDurationSeconds())
-                
+            labelCurrentTime.text = NCUtility.shared.stringFromTime(.zero)
+            labelOverallDuration.text = "-" + NCUtility.shared.stringFromTime(durationTime)
+        }
         updateToolBar()
         
         ncplayer.player?.addPeriodicTimeObserver(forInterval: CMTimeMakeWithSeconds(1, preferredTimescale: 1), queue: .main, using: { (CMTime) in
@@ -152,11 +153,12 @@ class NCPlayerToolBar: UIView {
     public func updateToolBar() {
 
         var namedPlay = "play.fill"
+        let durationTime = NCManageDatabase.shared.getVideoDurationTime(metadata: ncplayer?.metadata) ?? .zero
+        let currentTime = ncplayer?.player?.currentTime() ?? .zero
+        
         if ncplayer?.player?.rate == 1 { namedPlay = "pause.fill"}
-        let currentSeconds = ncplayer?.getVideoCurrentSeconds() ?? 0
-        let durationSeconds = ncplayer?.getVideoDurationSeconds() ?? 0
         
-        playbackSlider.value = Float(currentSeconds)
+        playbackSlider.value = Float(currentTime.value)
         playbackSlider.isEnabled = true
         
         backButton.setImage(NCUtility.shared.loadImage(named: "gobackward.15", color: .white), for: .normal)
@@ -179,8 +181,8 @@ class NCPlayerToolBar: UIView {
         }
         muteButton.isEnabled = true
         
-        labelCurrentTime.text = NCUtility.shared.stringFromTimeInterval(interval: currentSeconds)
-        labelOverallDuration.text = "-" + NCUtility.shared.stringFromTimeInterval(interval: durationSeconds - currentSeconds)
+        labelCurrentTime.text = NCUtility.shared.stringFromTime(currentTime)
+        labelOverallDuration.text = "-" + NCUtility.shared.stringFromTime(durationTime - currentTime)
     }
     
     //MARK: - Event / Gesture
@@ -263,27 +265,27 @@ class NCPlayerToolBar: UIView {
         guard let ncplayer = ncplayer else { return }
         guard let player = ncplayer.player else { return }
         
-        let playerCurrentTime = CMTimeGetSeconds(player.currentTime())
-        let newTime = playerCurrentTime + seekDuration
+//        let playerCurrentTime = CMTimeGetSeconds(player.currentTime())
+//        let newTime = playerCurrentTime + seekDuration
         
-        if newTime < ncplayer.getVideoDurationSeconds() {
-            let time: CMTime = CMTimeMake(value: Int64(newTime * 1000 as Float64), timescale: 1000)
-            ncplayer.videoSeek(time: time)
-        } else if newTime >= ncplayer.getVideoDurationSeconds() {
-            ncplayer.videoSeek(time: .zero)
-        }
+//        if newTime < ncplayer.getVideoDurationSeconds() {
+//            let time: CMTime = CMTimeMake(value: Int64(newTime * 1000 as Float64), timescale: 1000)
+//            ncplayer.videoSeek(time: time)
+//        } else if newTime >= ncplayer.getVideoDurationSeconds() {
+//            ncplayer.videoSeek(time: .zero)
+//        }
     }
     
     @IBAction func backButtonSec(_ sender: Any) {
         guard let ncplayer = ncplayer else { return }
         guard let player = ncplayer.player else { return }
         
-        let playerCurrenTime = CMTimeGetSeconds(player.currentTime())
-        var newTime = playerCurrenTime - seekDuration
+//        let playerCurrenTime = CMTimeGetSeconds(player.currentTime())
+//        var newTime = playerCurrenTime - seekDuration
         
-        if newTime < 0 { newTime = 0 }
-        let time: CMTime = CMTimeMake(value: Int64(newTime * 1000 as Float64), timescale: 1000)
+//        if newTime < 0 { newTime = 0 }
+//        let time: CMTime = CMTimeMake(value: Int64(newTime * 1000 as Float64), timescale: 1000)
         
-        ncplayer.videoSeek(time: time)
+//        ncplayer.videoSeek(time: time)
     }
 }

+ 2 - 2
iOSClient/Viewer/NCViewerMedia/NCViewerMediaDetailView.swift

@@ -155,9 +155,9 @@ class NCViewerMediaDetailView: UIView {
                 dimValue.text = "\(Int(image.size.width)) x \(Int(image.size.height))"
             }
         } else if metadata?.classFile == NCCommunicationCommon.typeClassFile.video.rawValue || metadata?.classFile == NCCommunicationCommon.typeClassFile.audio.rawValue  {
-            if let duration = NCManageDatabase.shared.getVideoDuration(metadata: metadata) {
+            if let durationTime = NCManageDatabase.shared.getVideoDurationTime(metadata: metadata) {
                 self.dimLabel.text = NSLocalizedString("_duration_", comment: "")
-                self.dimValue.text = NCUtility.shared.stringFromTime(duration)
+                self.dimValue.text = NCUtility.shared.stringFromTime(durationTime)
             }
         }