Interface Media

This plugin provides the ability to record and play back audio files on a device. NOTE: The current implementation does not adhere to a W3C specification for media capture, and is provided for convenience only. A future implementation will adhere to the latest W3C specification and may deprecate the current APIs.

Index

Construct signatures

Properties

Methods

Construct signatures

constructor(): Media

Returns

Media

Properties

public Media.MEDIA_NONE: number

public Media.MEDIA_PAUSED: number

public Media.MEDIA_RUNNING: number

public Media.MEDIA_STARTING: number

public Media.MEDIA_STOPPED: number

public duration: number

The duration of the media, in seconds.

public position: number

The position within the audio playback, in seconds. Not automatically updated during play; call getCurrentPosition to update.

Methods

public getCurrentPosition(mediaSuccess: (position: number) => void, mediaError?: (error: MediaError) => void)

Returns the current position within an audio file. Also updates the Media object's position parameter.

Parameters

  • mediaSuccess: (position: number) => void

    The callback that is passed the current position in seconds.

  • mediaError?: (error: MediaError) => void optional

    The callback to execute if an error occurs.

public getDuration(): number

Returns the duration of an audio file in seconds. If the duration is unknown, it returns a value of -1.

Returns

number

public pause()

Pauses playing an audio file.

public play()

Starts or resumes playing an audio file.

public release()

Releases the underlying operating system's audio resources. This is particularly important for Android, since there are a finite amount of OpenCore instances for media playback. Applications should call the release function for any Media resource that is no longer needed.

public seekTo(position: number)

Sets the current position within an audio file.

Parameters

  • position: number

    Position in milliseconds.

public setVolume(volume: number)

Set the volume for an audio file.

Parameters

  • volume: number

    The volume to set for playback. The value must be within the range of 0.0 to 1.0.

public startRecord()

Starts recording an audio file.

public stop()

Stops playing an audio file.

public stopRecord()

Stops recording an audio file.