Class: OdinMedia
The OdinMedia class represents a local audio stream for sending audio to the room.
Don't create OdinMedia instances directly, use createAudioStream from OdinRoom instead.
This wrapper closely follows the core ODIN SDK pattern:
- Create audio stream:
media = room.createAudioStream(48000, 2) - Set server-assigned media ID:
media.setMediaId(mediaIds[0])// From Joined event - Send audio chunks:
media.sendAudioData(chunk)// 20ms chunks recommended - When done:
media.close()
Or use the convenience API for file playback: await media.sendMP3('./file.mp3'); // Auto handles everything await media.sendWAV('./file.wav'); await media.sendBuffer(audioBuffer);
Constructors
new OdinMedia()
new OdinMedia(
room,sampleRate,channelCount,options?):OdinMedia
Creates a new instance of a media object.
Don't create OdinMedia directly, use createAudioStream from OdinRoom instead.
Parameters
• room: OdinRoom
The room to add the media to.
• sampleRate: number
The sample rate of the audio stream (between 8000 and 48000)
• channelCount: number
The number of channels of the audio stream (1 or 2)
• options?: OdinAPMSettings
Optional configuration options for Odin Audio Processing Module (APM).
Returns
Defined in
odin.media.d.ts:38
Accessors
closed
getclosed():boolean
Checks if this media stream has been closed.
Returns
boolean
True if the stream is closed and can no longer be used.
Defined in
odin.media.d.ts:98
id
getid():null|number
Gets the ID of the media.
Returns
null | number
The ID of the media, or null if closed.
Defined in
odin.media.d.ts:92
Methods
close()
close():
void
Closes the local audio stream and releases resources. After calling this, the media stream cannot be used.
Returns
void
Defined in
odin.media.d.ts:51
sendAudioData()
sendAudioData(
data):void
Sends audio data to the room. Data must be a 32-bit float array with samples between -1 and 1. Audio data should be sent in regular intervals (20ms chunks recommended).
Parameters
• data: Float32Array
A 32-bit float array containing the audio data.
Returns
void
Defined in
odin.media.d.ts:59
sendBuffer()
sendBuffer(
audioBuffer):Promise<void>
Send decoded audio with real-time streaming. Handles all setup (media ID, StartMedia RPC, timing) automatically.
Parameters
• audioBuffer: AudioBuffer
Decoded audio buffer (from audio-decode library)
Returns
Promise<void>
Promise that resolves when audio streaming is complete
Defined in
odin.media.d.ts:86
sendMP3()
sendMP3(
filePath):Promise<void>
Send an MP3 file with automatic decoding and real-time streaming. Handles all setup (media ID, StartMedia RPC, timing) automatically.
Parameters
• filePath: string
Path to the MP3 file
Returns
Promise<void>
Promise that resolves when audio streaming is complete
Defined in
odin.media.d.ts:68
sendWAV()
sendWAV(
filePath):Promise<void>
Send a WAV file with automatic decoding and real-time streaming. Handles all setup (media ID, StartMedia RPC, timing) automatically.
Parameters
• filePath: string
Path to the WAV file
Returns
Promise<void>
Promise that resolves when audio streaming is complete
Defined in
odin.media.d.ts:77
setMediaId()
setMediaId(
mediaId):void
Sets the server-assigned media ID. Must be called before sendAudioData() with an ID from the Joined event's mediaIds array.
Parameters
• mediaId: number
The media ID from Joined event
Returns
void
Defined in
odin.media.d.ts:45