Skip to main content
Version: 20 Mar 2024

Control

Module: Audio / Audio Definitions / Audio Output

More...

Functions

Name
MLResultMLAudioStartSound(MLHandle handle)
Starts playback for a sound output.
MLResultMLAudioStopSound(MLHandle handle)
Stops playback for a sound output.
MLResultMLAudioPauseSound(MLHandle handle)
Pauses playback for a currently playing sound output.
MLResultMLAudioResumeSound(MLHandle handle)
Resumes playback for a currently paused sound output.
MLResultMLAudioGetSoundState(MLHandle handle, MLAudioState * out_state)
Queries the playback state of a sound output.
MLResultMLAudioGetSoundFormat(MLHandle handle, MLAudioBufferFormat * out_format)
Queries the audio format of a sound output.
MLResultMLAudioSetSoundEventCallback(MLHandle handle, MLAudioSoundEventCallback callback, void * context)
Registers a callback for Sound Events relating to a sound output.
MLResultMLAudioSetMediaEventCallback(MLAudioMediaEventCallback callback, void * context)
Registers a callback for media transport events.

Detailed Description

CONTROL.


Functions Documentation

MLAudioStartSound

MLResult MLAudioStartSound(
MLHandle handle
)

Starts playback for a sound output.

Parameters

MLHandlehandleMLHandle of the sound output.

Returns

MLResultMLResult_OkSound output is started, or continues if already playing.
MLResultMLResult_UnspecifiedFailureFailed due to an unknown error.
MLResultMLAudioResult_HandleNotFoundFailed due to a missing handle.
MLResultMLAudioResult_NotImplementedFailed because feature has not been implemented yet.
MLResultMLAudioResult_ResourceDiscardedFailed because file was closed.
MLResultMLAudioResult_ResourceNotFoundFailed because resource was not found.

Required Permissions:

  • None

Calling this function on a playing sound has no effect and returns success. Calling this function on a paused sound will start the sound output from the beginning. When starting playback for a buffered output stream, the "out_frames_played" counter retrieved by calling MLAudioGetBufferedOutputFramesPlayed is reset to 0.


MLAudioStopSound

MLResult MLAudioStopSound(
MLHandle handle
)

Stops playback for a sound output.

Parameters

MLHandlehandleMLHandle of the sound output.

Returns

MLResultMLResult_OkSound output is stopped, or remains stopped if already stopped.
MLResultMLResult_UnspecifiedFailureFailed to stop playback due to an unknown error.
MLResultMLAudioResult_HandleNotFoundFailed to stop playback due to a missing handle.
MLResultMLAudioResult_NotImplementedFailed to stop playback because feature has not been implemented yet.
MLResultMLAudioResult_ResourceNotFoundFailed to stop playback because resource was not found.

Required Permissions:

  • None

Calling this function on a stopped sound has no effect and returns success.


MLAudioPauseSound

MLResult MLAudioPauseSound(
MLHandle handle
)

Pauses playback for a currently playing sound output.

Parameters

MLHandlehandleMLHandle of the sound output.

Returns

MLResultMLResult_OkSound output is paused, or remains paused if already paused.
MLResultMLResult_UnspecifiedFailureFailed due to an unknown error.
MLResultMLAudioResult_HandleNotFoundFailed due to a missing handle.
MLResultMLAudioResult_NotImplementedFailed because feature has not been implemented yet.
MLResultMLAudioResult_OperationUnavailableFailed because operation is unavailable.

Required Permissions:

  • None

If the sound output is not playing, the pause will fail with MLAudioResult_OperationUnavailable. Calling this function on a paused sound has no effect and returns success.


MLAudioResumeSound

MLResult MLAudioResumeSound(
MLHandle handle
)

Resumes playback for a currently paused sound output.

Parameters

MLHandlehandleMLHandle of the sound output.

Returns

MLResultMLResult_OkSound output resumes playing.
MLResultMLResult_UnspecifiedFailureFailed due to an unknown error.
MLResultMLAudioResult_HandleNotFoundFailed due to a missing handle.
MLResultMLAudioResult_NotImplementedFailed because feature has not been implemented yet.
MLResultMLAudioResult_OperationUnavailableFailed because operation is unavailable.

Required Permissions:

  • None

Calling this function on a paused sound will resume playback from the current position. Calling this function on a playing or stopped sound will fail with MLAudioResult_OperationUnavailable.


MLAudioGetSoundState

MLResult MLAudioGetSoundState(
MLHandle handle,
MLAudioState * out_state
)

Queries the playback state of a sound output.

Parameters

MLHandlehandleMLHandle of the sound output.
MLAudioState *out_stateMLAudioState enum to be filled with the current playback state.

Returns

MLResultMLResult_InvalidParamFailed due to an invalid parameter.
MLResultMLResult_OkSuccessfully retrieved the properties.
MLResultMLResult_UnspecifiedFailureFailed due to an unknown error.
MLResultMLAudioResult_HandleNotFoundFailed due to a missing handle.
MLResultMLAudioResult_NotImplementedFailed because feature has not been implemented yet.

Required Permissions:

  • None

The MLAudioState enum defines the possible playback states which are Stopped, Playing and Paused.


MLAudioGetSoundFormat

MLResult MLAudioGetSoundFormat(
MLHandle handle,
MLAudioBufferFormat * out_format
)

Queries the audio format of a sound output.

Parameters

MLHandlehandleMLHandle of the sound output.
MLAudioBufferFormat *out_formatMLAudioBufferFormat struct to be filled with the format properties.

Returns

MLResultMLResult_InvalidParamFailed due to an invalid parameter.
MLResultMLResult_OkSuccessfully retrieved the properties.
MLResultMLResult_UnspecifiedFailureFailed due to an unknown error.
MLResultMLAudioResult_HandleNotFoundFailed due to a missing handle.
MLResultMLAudioResult_NotImplementedFailed because feature has not been implemented yet.
MLResultMLAudioResult_OperationUnavailableFailed because operation is unavailable.

Required Permissions:

  • None

For sound outputs referencing streamed resources, the format is not available until ~100 milliseconds after playback has started.


MLAudioSetSoundEventCallback

MLResult MLAudioSetSoundEventCallback(
MLHandle handle,
MLAudioSoundEventCallback callback,
void * context
)

Registers a callback for Sound Events relating to a sound output.

Parameters

MLHandlehandleMLHandle of the sound output.
MLAudioSoundEventCallbackcallbackCallback function pointer.
void *contextGeneric data pointer passed back through the callback.

Returns

MLResultMLResult_AllocFailedFailed due to memory allocation failure.
MLResultMLResult_InvalidParamFailed due to an invalid parameter.
MLResultMLResult_OkSuccessfully registered the callback.
MLResultMLResult_UnspecifiedFailureFailed due to an unknown error.
MLResultMLAudioResult_HandleNotFoundFailed due to a missing handle.
MLResultMLAudioResult_InternalConfigErrorFailed due to an internal configuration error.
MLResultMLAudioResult_NotImplementedFailed because feature has not been implemented yet.

Required Permissions:

  • None

Sound outputs generate events as specified in the MLAudioSoundEvent enum, such as when a sound has looped, stopped, etc. Each of these events will trigger the MLAudioSoundEventCallback.

API Level:

  • 20

MLAudioSetMediaEventCallback

MLResult MLAudioSetMediaEventCallback(
MLAudioMediaEventCallback callback,
void * context
)

Registers a callback for media transport events.

Parameters

MLAudioMediaEventCallbackcallbackCallback function pointer.
void *contextGeneric data pointer passed back through the callback.

Returns

MLResultMLResult_AllocFailedIf memory allocation fails.
MLResultMLResult_InvalidParamIf input parameter is invalid.
MLResultMLResult_OkSuccessfully registered the callback.
MLResultMLResult_UnspecifiedFailureInternal error.
MLResultMLAudioResult_HandleNotFoundHandle not found.
MLResultMLAudioResult_InternalConfigErrorInternal config error.
MLResultMLAudioResult_NotImplementedInternal error.

Required Permissions:

  • None

Media transport events can be triggered by devices such as bluetooth media controls. The possible events include Stop, Start, Pause, NextTrack and PrevTrack as specified in the MLAudioMediaEvent enum.

API Level:

  • 20