Implementa pausa diretta con copertina slate e ripresa.

Metti in pausa ferma RTMP lato app mantenendo la camera aperta, MediaMTX
manda offline.mp4 agli spettatori e Chiudi termina definitivamente.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-02 23:31:48 +02:00
parent 1bd81d84af
commit a87cda156b
19 changed files with 305 additions and 45 deletions

View File

@@ -88,6 +88,7 @@ class StreamingEngine(
private var lastFpsSampleAtMs: Long = 0L
private val reconnectAttempts = AtomicInteger(0)
private val isReleased = AtomicBoolean(false)
private val pausingIntentionally = AtomicBoolean(false)
private val bitrateAdapter = BitrateAdapter { adaptedBitrate ->
genericStream?.setVideoBitrateOnFly(adaptedBitrate)
@@ -235,6 +236,33 @@ class StreamingEngine(
startMetricsLoop()
}
fun pauseStream() {
ensureMainThread()
if (state != StreamingState.STREAMING &&
state != StreamingState.CONNECTING &&
state != StreamingState.RECONNECTING
) {
return
}
stopMetricsLoop()
pausingIntentionally.set(true)
genericStream?.let { stream ->
if (stream.isStreaming) {
stream.stopStream()
}
}
pausingIntentionally.set(false)
streamStartedAtMs = 0L
currentBitrateKbps = 0L
currentFps = 0
reconnectAttempts.set(0)
attachPreviewToStream()
updateState(StreamingState.PREVIEWING)
startMetricsLoop()
}
fun stopStream() {
ensureMainThread()
if (state == StreamingState.IDLE || state == StreamingState.STOPPING) {
@@ -291,6 +319,9 @@ class StreamingEngine(
override fun onConnectionFailed(reason: String) {
postMain {
if (pausingIntentionally.get()) {
return@postMain
}
lastError = reason
val stream = genericStream ?: return@postMain
val currentConfig = config ?: return@postMain
@@ -328,6 +359,9 @@ class StreamingEngine(
override fun onDisconnect() {
postMain {
if (pausingIntentionally.get()) {
return@postMain
}
if (state == StreamingState.STREAMING || state == StreamingState.RECONNECTING) {
updateState(StreamingState.RECONNECTING, "disconnected")
}

View File

@@ -128,6 +128,7 @@ class StreamingPlugin : FlutterPlugin, MethodCallHandler, ActivityAware, EventCh
when (call.method) {
"startStream" -> startStream(call, result)
"stopStream" -> stopStream(result)
"pauseStream" -> pauseStream(result)
"getMetrics" -> getMetrics(result)
"startPreview" -> startPreview(result)
"stopPreview" -> stopPreview(result)
@@ -203,6 +204,11 @@ class StreamingPlugin : FlutterPlugin, MethodCallHandler, ActivityAware, EventCh
result.success(true)
}
private fun pauseStream(result: Result) {
getEngine()?.pauseStream()
result.success(true)
}
private fun getMetrics(result: Result) {
val metrics = boundService?.getMetrics()
?: getEngine()?.getMetrics()?.toMap()