This commit is contained in:
Marino Faggiana 2023-04-26 11:29:49 +02:00
Родитель 236811d5be
Коммит 155afd0847
4 изменённых файлов: 15 добавлений и 46 удалений

Просмотреть файл

@ -26,4 +26,4 @@ import Foundation
// Database Realm
//
let databaseName = "nextcloud.realm"
let databaseSchemaVersion: UInt64 = 280
let databaseSchemaVersion: UInt64 = 281

Просмотреть файл

@ -28,7 +28,6 @@ import NextcloudKit
class tableVideo: Object {
@objc dynamic var account = ""
@objc dynamic var length: Int = 0
@objc dynamic var ocId = ""
@objc dynamic var position: Float = 0
@objc dynamic var codecNameVideo: String?
@ -45,7 +44,7 @@ class tableVideo: Object {
extension NCManageDatabase {
func addVideo(metadata: tableMetadata, position: Float, length: Int? = nil) {
func addVideo(metadata: tableMetadata, position: Float) {
if metadata.livePhoto { return }
let realm = try! Realm()
@ -54,9 +53,6 @@ extension NCManageDatabase {
try realm.write {
if let result = realm.objects(tableVideo.self).filter("account == %@ AND ocId == %@", metadata.account, metadata.ocId).first {
if let length = length {
result.length = length
}
result.position = position
realm.add(result, update: .all)
@ -65,9 +61,6 @@ extension NCManageDatabase {
let addObject = tableVideo()
addObject.account = metadata.account
if let length = length {
addObject.length = length
}
addObject.ocId = metadata.ocId
addObject.position = position
realm.add(addObject, update: .all)
@ -121,20 +114,6 @@ extension NCManageDatabase {
return tableVideo.init(value: result)
}
func getVideoLength(metadata: tableMetadata?) -> Int? {
guard let metadata = metadata else { return nil }
if metadata.livePhoto { return nil }
let realm = try! Realm()
guard let result = realm.objects(tableVideo.self).filter("account == %@ AND ocId == %@", metadata.account, metadata.ocId).first else {
return nil
}
if result.length == 0 { return nil }
return result.length
}
func getVideoPosition(metadata: tableMetadata) -> Float? {
if metadata.livePhoto { return nil }

Просмотреть файл

@ -159,20 +159,14 @@ class NCPlayer: NSObject {
@objc func playerStop() {
savePosition()
player?.stop()
playerToolBar?.playButtonPlay()
}
@objc func playerPause(withSnapshot: Bool = true) {
if let width = width, let height = height, withSnapshot {
player?.saveVideoSnapshot(at: fileNamePreviewLocalPath, withWidth: Int32(width), andHeight: Int32(height))
}
if let position = player?.position {
NCManageDatabase.shared.addVideo(metadata: metadata, position: position)
}
savePosition()
player?.pause()
playerToolBar?.playButtonPlay()
}
@ -182,12 +176,15 @@ class NCPlayer: NSObject {
player?.position = position
}
func savePosition(_ position: Float) {
func savePosition() {
if metadata.classFile == NKCommon.TypeClassFile.audio.rawValue { return }
let length = Int(player?.media?.length.intValue ?? 0)
guard let position = player?.position, metadata.classFile == NKCommon.TypeClassFile.video.rawValue else { return }
NCManageDatabase.shared.addVideo(metadata: metadata, position: position, length: length)
if let width = width, let height = height {
player?.saveVideoSnapshot(at: fileNamePreviewLocalPath, withWidth: Int32(width), andHeight: Int32(height))
}
NCManageDatabase.shared.addVideo(metadata: metadata, position: position)
}
func snapshot() {

Просмотреть файл

@ -140,17 +140,10 @@ class NCViewerMediaDetailView: UIView {
}
dateValue.textColor = textColor
// Dimension / Duration
if metadata.classFile == NKCommon.TypeClassFile.image.rawValue {
if let image = image {
dimLabel.text = NSLocalizedString("_resolution_", comment: "")
dimValue.text = "\(Int(image.size.width)) x \(Int(image.size.height))"
}
} else if metadata.classFile == NKCommon.TypeClassFile.video.rawValue || metadata.classFile == NKCommon.TypeClassFile.audio.rawValue {
if let lenth = NCManageDatabase.shared.getVideoLength(metadata: metadata) {
self.dimLabel.text = NSLocalizedString("_duration_", comment: "")
// self.dimValue.text = NCUtility.shared.stringFromTime(durationTime)
}
// Dimension
if let image = image {
dimLabel.text = NSLocalizedString("_resolution_", comment: "")
dimValue.text = "\(Int(image.size.width)) x \(Int(image.size.height))"
}
dimValue.textColor = textColor