Autoplay the next voice message if it is the next timeline item. (#6089)

This commit is contained in:
Mauro
2026-09-01 18:00:14 +02:00
committed by GitHub
parent b4a36ad465
commit 86bc4d54b6
13 changed files with 463 additions and 16 deletions
@@ -6,11 +6,14 @@
// Please see LICENSE files in the repository root for full details.
//
import AVFoundation
import Foundation
class MediaPlayerProvider: MediaPlayerProviderProtocol {
private lazy var audioPlayer = AudioPlayer()
private var audioPlayerStates: [String: AudioPlayerState] = [:]
/// Held onto for the duration of the playback, an unowned player is silent.
private var soundEffectPlayer: AVAudioPlayer?
var player: AudioPlayerProtocol {
audioPlayer
@@ -55,6 +58,17 @@ class MediaPlayerProvider: MediaPlayerProviderProtocol {
}
}
/// Doesn't configure an audio session, so that it can be used alongside any existing player or session.
func play(soundEffect: SoundEffect) {
do {
let player = try AVAudioPlayer(contentsOf: soundEffect.fileURL)
soundEffectPlayer = player
player.play()
} catch {
MXLog.error("Failed playing the sound effect: \(error)")
}
}
// MARK: - Private
private func audioPlayerStateID(for identifier: AudioPlayerStateIdentifier) -> String? {
@@ -8,6 +8,17 @@
import Foundation
enum SoundEffect {
/// A short, light blip.
case tink
var fileURL: URL {
switch self {
case .tink: URL.systemSoundsDirectory.appending(component: "Tink.caf")
}
}
}
protocol MediaPlayerProviderProtocol {
var player: AudioPlayerProtocol { get }
@@ -15,6 +26,10 @@ protocol MediaPlayerProviderProtocol {
func register(audioPlayerState: AudioPlayerState)
func unregister(audioPlayerState: AudioPlayerState)
func detachAllStates(except exception: AudioPlayerState?) async
/// Plays a short sound on top of whatever is already playing. It goes through the app's own
/// audio session, so unlike the sounds built into iOS it is heard in silent mode too.
func play(soundEffect: SoundEffect)
}
// sourcery: AutoMockable