Skip to main content

Stop Live Streaming

Stop the current RTSP or JPEG device live-stream session and release any player, relay, image, or UI resources owned by the host app.

Prerequisites

  • The target device conforms to LiveStreamingAPI.
  • Keep references to presentation resources created for the current session.
  • Make stop handling idempotent so view dismissal and an explicit stop action can share the same cleanup path.

API Reference

Framework

AIBuds.xcframework

Import

Swift
import AIBuds
import AIBudsLiveStream

Instance Method

Swift
/// Stop live streaming
func stopLiveStreaming()

See stopLiveStreaming.

Parameters

This method has no parameters.

Return Value

This method does not return a value or accept a completion handler. Observe the sessionFinishHandler supplied when starting the session for terminal context.

Usage Examples

The Demo stops an optional RTMP relay before stopping RTSP playback, then clears device-session and UI state. The device command and host resources are separate lifecycles.

Swift
func stopCurrentLiveStream() {
    // Stop optional host-side relay and playback resources.
    liveStreamer?.stopStreaming()
    liveStreamer = nil
    mediaPlayer?.stop()

    // Stop the RTSP or JPEG session on the connected device.
    (device as? LiveStreamingAPI)?.stopLiveStreaming()

    currentRTSPAddress = nil
    imageView.image = nil
    setStreamingActive(false)
}

Error Handling

Because stopLiveStreaming() has no completion handler, make local cleanup safe to repeat and use the original session's finish callback to distinguish isUserInitiatedStop from an interruption. Log or present the callback error when a session ends unexpectedly.

Best Practices

  1. Stop live streaming when leaving the owning screen or ending the feature.
  2. Release the RTMP relay, player, and retained RTSP address together with the device session.
  3. Do not wait for a stop completion that the public method does not provide.
  4. Keep finish-callback handling idempotent because it can run after local cleanup.

Notes

  • The same stop method ends either an RTSP or JPEG device session.
  • Stopping LiveStreamingPlayer alone does not stop the device session.
  • Stopping the device session alone does not automatically release host-owned playback or relay objects.