Media stream sending control

更新时间:
复制 MD 格式

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

// iOS / Mac
func enableSendMediaStream(_ trackType: AoqTrackType, enable: Bool)

Android

// Android
void enableSendMediaStream(AoqTrackType trackType, boolean enable)

HarmonyOS (ArkTS)

// HarmonyOS (ArkTS)
enableSendMediaStream(trackType: AoqTrackType, enable: boolean): void

Parameters:

Parameter

Type

Description

trackType

AoqTrackType

Media track type: .audio or .video

enable

Bool

true = start sending; false = pause sending

Control flow

A typical media stream control flow is as follows:

111

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

Scenario

Action

Description

Before connecting to the model

enable(.audio, false)

Wait for session.updated before sending

After receiving session.updated

enable(.audio, true)

AI is ready; start sending