MediaContext

The MediaContext class.

The methods provided by the MediaContext class are used for:
  • Managing local audio and video devices.
  • Playing local audio.
  • Rendering and previewing local video.

openLocalDevice

Turns on the specified local device.

abstract fun openLocalDevice(deviceInfo: AgoraEduContextDeviceInfo,
                             callback: EduContextCallback<Unit>? = null)

Parameter

deviceInfo
The device information. See AgoraEduContextDeviceInfo.
callback
Get the method call result asynchronously through EduContextCallback.

closeLocalDevice

Turns off the local device.

abstract fun closeLocalDevice(deviceInfo: AgoraEduContextDeviceInfo,
                              callback: EduContextCallback<Unit>? = null)

Parameter

deviceInfo
The device information. See AgoraEduContextDeviceInfo.
callback
Get the method call result asynchronously through EduContextCallback.

startRenderLocalVideo

Starts rendering the video stream.

abstract fun startRenderLocalVideo(config: EduContextRenderConfig,
                                   container: ViewGroup,
                                   streamUuid: String)

Parameter

config
Video rendering configurations. See EduContextRenderConfig.
container
The view for rendering.
streamUuid
The ID of the stream to be rendered.

stopRenderLocalVideo

Stops rendering the video stream.

abstract fun stopRenderLocalVideo(streamUuid: String)

Parameter

streamUuid
The stream ID. If you want to stop previewing the video stream captured by the local camera before joining the room, set streamUuid as 0.

startAudioMixing

Starts audio mixing.

abstract fun startAudioMixing(filepath: String, 
                              loopback: Boolean, 
                              replace: Boolean, 
                              cycle: Int)

Call this method to mix the audio stream sampled by the microphone with the audio in the locally-played music file, so that the remote user can hear the music file more clearly.

Parameter

filePath
The path of the music file that needs to be mixed.
loopback
Whether to play the music file only on the local client.
replace
Whether to replace the audio sampled by the microphone with the music file.
cycle
The number of times the music file is played. Setting this parameter as -1 means loop playback.

setAudioMixingPosition

Sets the starting position of the music file for mixing.

abstract fun setAudioMixingPosition(position: Int)

Parameter

position
The starting position (in milliseconds) of the music file.

addAudioRawDataObserver

Registers an FcrAudioRawDataObserver.

abstract fun addAudioRawDataObserver(
        observer: FcrMediaRawDataObserver,
        config: FcrAudioRawDataConfig? = FcrAudioRawDataConfig()
)
This method can only be called before the user joins the channel. To add more observers, call this API multiple times.

Parameter

observer
The audio raw data observer: FcrAudioRawDataObserver.
config
The output configuration of the audio pipeline: FcrAudioRawDataConfig