Skip to main content
AOQ SDK Features

Media stream control

AOQ SDK media stream send/stop control

enableSendMediaStream controls whether the client sends audio or video media streams to the AI service, giving you precise control over when media transmission starts in AOQ protocol scenarios.

Overview

enableSendMediaStream controls whether the client sends audio or video media streams to the AI service. In AOQ protocol scenarios, some models require a session.updated confirmation before they can accept media data. Use this API to start sending at the right time.

API definition

  • iOS / Mac
  • Android
  • HarmonyOS (ArkTS)
// iOS / Mac
func enableSendMediaStream(_ trackType: AoqTrackType, enable: Bool)
Parameters:
ParameterTypeDescription
trackTypeAoqTrackTypeMedia track type: .audio or .video
enableBooltrue = start sending; false = pause sending

Control flow

A typical media stream control flow is as follows:
Media stream control flow

Example (iOS Swift)

Disable sending before connect

// Disable audio and video sending before connecting to prevent the model
// from receiving data before it is ready
engine.enableSendMediaStream(.audio, enable: false)
engine.enableSendMediaStream(.video, enable: false)
// Initiate the connection
engine.connect(config)

Enable after receiving session.updated

func onDataMsg(_ msg: AoqDataMsg) {
  guard let obj = try? JSONSerialization.jsonObject(with: msg.data) as? [String: Any],
        let type = obj["type"] as? String else { return }
  if type == "session.updated" {
    // The AI has confirmed the session configuration; start sending media
    engine.enableSendMediaStream(.audio, enable: true)
    engine.enableSendMediaStream(.video, enable: true)
  }
}

Important notes

  • When to call: Must be called after createEngine. Calling before the engine is created has no effect.
  • Default behavior: If this API is not called, the SDK starts sending media streams immediately after a successful connection.
  • Model compatibility: Some models require a session.updated event before they accept media data. Use the "disable first, then enable" pattern for maximum compatibility.
  • Independent control: Audio and video can be controlled independently -- for example, you can send audio without sending video.

Common scenarios

ScenarioActionDescription
Before connecting to the modelenable(.audio, false)Wait for session.updated before sending
After receiving session.updatedenable(.audio, true)AI is ready; start sending