Automatically play next voice recording when the previous one ends

This commit is contained in:
Benoit Martins 2026-02-25 16:28:40 +01:00
parent 9cc8923e3f
commit 75e96ed8a5
2 changed files with 41 additions and 3 deletions

View file

@ -2,6 +2,6 @@ import Foundation
public enum AppGitInfo { public enum AppGitInfo {
public static let branch = "master" public static let branch = "master"
public static let commit = "db9c9f183" public static let commit = "9cc8923e3"
public static let tag = "6.1.0-alpha" public static let tag = "6.1.0-alpha"
} }

View file

@ -20,6 +20,7 @@
import SwiftUI import SwiftUI
import WebKit import WebKit
import QuickLook import QuickLook
import Combine
// swiftlint:disable type_body_length // swiftlint:disable type_body_length
// swiftlint:disable cyclomatic_complexity // swiftlint:disable cyclomatic_complexity
@ -1162,13 +1163,15 @@ struct CustomSlider: View {
let eventLogMessage: EventLogMessage let eventLogMessage: EventLogMessage
@State private var timer: Timer?
@State private var value: Double = 0.0 @State private var value: Double = 0.0
@State private var isPlaying: Bool = false @State private var isPlaying: Bool = false
@State private var timer: Timer? @State private var cancellable: AnyCancellable?
var minTrackColor: Color = .white.opacity(0.5) var minTrackColor: Color = .white.opacity(0.5)
var maxTrackGradient: Gradient = Gradient(colors: [Color.orangeMain300, Color.orangeMain500]) var maxTrackGradient: Gradient = Gradient(colors: [Color.orangeMain300, Color.orangeMain500])
var body: some View { var body: some View {
GeometryReader { geometry in GeometryReader { geometry in
let radius = geometry.size.height * 0.5 let radius = geometry.size.height * 0.5
@ -1223,7 +1226,26 @@ struct CustomSlider: View {
.padding(.horizontal, 10) .padding(.horizontal, 10)
} }
.clipShape(RoundedRectangle(cornerRadius: radius)) .clipShape(RoundedRectangle(cornerRadius: radius))
.onAppear {
if eventLogMessage.message.attachments.first?.type == .voiceRecording {
cancellable =
NotificationCenter.default
.publisher(for: NSNotification.Name("VoiceRecording"))
.compactMap { $0.userInfo?["messageId"] as? String }
.sink { messageId in
if messageId == eventLogMessage.message.id {
conversationViewModel.startVoiceRecordPlayer(
voiceRecordPath: eventLogMessage.message.attachments.first!.full
)
playProgress()
}
}
}
}
.onDisappear { .onDisappear {
cancellable?.cancel()
cancellable = nil
resetProgress() resetProgress()
} }
} }
@ -1247,7 +1269,23 @@ struct CustomSlider: View {
} }
} }
} else { } else {
resetProgress() self.resetProgress()
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
let rows = conversationViewModel.conversationMessagesSection[0].rows
if let index = rows.firstIndex(where: { $0.eventModel.eventLogId == eventLogMessage.message.id }),
rows.indices.contains(index - 1) {
let nextRow = rows[index - 1]
if nextRow.message.attachments.first?.type == .voiceRecording {
NotificationCenter.default.post(
name: NSNotification.Name("VoiceRecording"),
object: nil,
userInfo: ["messageId": nextRow.message.id]
)
}
}
}
} }
} }
} }