Files
lnreader/modules/nitro-tts/ios/TtsRemoteCommandController.swift
Rajarshee Chatterjee 74808f086e feat: Replace Legacy Media Controls with Nitro-Powered Playback (#1896)
* feat: Replace Legacy Media Controls with Nitro-Powered Playback

* feat: Add TTS Engine Selection

* chore: Remove User-Facing Error Reporting

* refactor: Combine `Tts` and `TtsSession` Imports from `nitro-tts` Module

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-07-24 23:42:17 +05:30

38 lines
1.0 KiB
Swift

import MediaPlayer
final class TtsRemoteCommandController {
private let commandCenter = MPRemoteCommandCenter.shared()
private var targets: [(MPRemoteCommand, Any)] = []
init(
onPlay: @escaping () -> Void,
onPause: @escaping () -> Void,
onStop: @escaping () -> Void,
onPrevious: @escaping () -> Void,
onNext: @escaping () -> Void
) {
register(commandCenter.playCommand, action: onPlay)
register(commandCenter.pauseCommand, action: onPause)
register(commandCenter.stopCommand, action: onStop)
register(commandCenter.previousTrackCommand, action: onPrevious)
register(commandCenter.nextTrackCommand, action: onNext)
}
deinit {
targets.forEach { command, target in
command.removeTarget(target)
}
}
private func register(_ command: MPRemoteCommand, action: @escaping () -> Void) {
command.isEnabled = true
let target = command.addTarget { _ in
DispatchQueue.main.async {
action()
}
return .success
}
targets.append((command, target))
}
}