Added in API level 23

SyncParams


class SyncParams
kotlin.Any
   ↳ android.media.SyncParams

Structure for common A/V sync params. Used by MediaSync {link MediaSync#getSyncParams()} and {link MediaSync#setSyncParams(SyncParams)} to control A/V sync behavior.

audio adjust mode: select handling of audio track when changing playback speed due to sync.

sync source: select clock source for sync.

tolerance: specifies the amount of allowed playback rate change to keep media in sync with the sync source. The handling of this depends on the sync source, but must not be negative, and must be less than one.

frameRate: initial hint for video frame rate. Used when sync source is vsync. Negative values can be used to clear a previous hint.

Summary

Constants
static Int

System will determine best handling of audio for playback rate adjustments.

static Int

Resample audio when playback rate must be adjusted.

static Int

Time stretch audio when playback rate must be adjusted.

static Int

Use audio track for sync source.

static Int

Use the default sync source (default).

static Int

Use system monotonic clock for sync source.

static Int

Use vsync as the sync source.

Public constructors

Public methods
SyncParams!

Allows defaults to be returned for properties not set.

Int

Retrieves the audio adjust mode.

Float

Retrieves the video frame rate hint.

Int

Retrieves the sync source.

Float

Retrieves the tolerance factor.

SyncParams!
setAudioAdjustMode(audioAdjustMode: Int)

Sets the audio adjust mode.

SyncParams!
setFrameRate(frameRate: Float)

Sets the video frame rate hint to be used.

SyncParams!
setSyncSource(syncSource: Int)

Sets the sync source.

SyncParams!
setTolerance(tolerance: Float)

Sets the tolerance.

Constants

AUDIO_ADJUST_MODE_DEFAULT

Added in API level 23
static val AUDIO_ADJUST_MODE_DEFAULT: Int

System will determine best handling of audio for playback rate adjustments.

Used by default. This will make audio play faster or slower as required by the sync source without changing its pitch; however, system may fall back to some other method (e.g. change the pitch, or mute the audio) if time stretching is no longer supported for the playback rate.

Value: 0

AUDIO_ADJUST_MODE_RESAMPLE

Added in API level 23
static val AUDIO_ADJUST_MODE_RESAMPLE: Int

Resample audio when playback rate must be adjusted.

This will make audio play faster or slower as required by the sync source by changing its pitch (making it lower to play slower, and higher to play faster.)

Value: 2

AUDIO_ADJUST_MODE_STRETCH

Added in API level 23
static val AUDIO_ADJUST_MODE_STRETCH: Int

Time stretch audio when playback rate must be adjusted.

This will make audio play faster or slower as required by the sync source without changing its pitch, as long as it is supported for the playback rate.

Value: 1

SYNC_SOURCE_AUDIO

Added in API level 23
static val SYNC_SOURCE_AUDIO: Int

Use audio track for sync source. This requires audio data and an audio track.

Value: 2

SYNC_SOURCE_DEFAULT

Added in API level 23
static val SYNC_SOURCE_DEFAULT: Int

Use the default sync source (default). If media has video, the sync renders to a surface that directly renders to a display, and tolerance is non zero (e.g. not less than 0.001) vsync source is used for clock source. Otherwise, if media has audio, audio track is used. Finally, if media has no audio, system clock is used.

Value: 0

SYNC_SOURCE_SYSTEM_CLOCK

Added in API level 23
static val SYNC_SOURCE_SYSTEM_CLOCK: Int

Use system monotonic clock for sync source.

Value: 1

SYNC_SOURCE_VSYNC

Added in API level 23
static val SYNC_SOURCE_VSYNC: Int

Use vsync as the sync source. This requires video data and an output surface that directly renders to the display, e.g. android.view.SurfaceView

This mode allows smoother playback experience by adjusting the playback speed to match the vsync rate, e.g. playing 30fps content on a 59.94Hz display. When using this mode, the tolerance should be set to greater than 0 (e.g. at least 1/1000), so that the playback speed can actually be adjusted.

This mode can also be used to play 25fps content on a 60Hz display using a 2:3 pulldown (basically playing the content at 24fps), which results on better playback experience on most devices. In this case the tolerance should be at least (1/24).

Value: 3

Public constructors

SyncParams

SyncParams()

Public methods

allowDefaults

Added in API level 23
fun allowDefaults(): SyncParams!

Allows defaults to be returned for properties not set. Otherwise a java.lang.IllegalArgumentException exception is raised when getting those properties which have defaults but have never been set.

Return
SyncParams! this SyncParams instance.

getAudioAdjustMode

Added in API level 23
fun getAudioAdjustMode(): Int

Retrieves the audio adjust mode.

Return
Int audio adjust mode Value is android.media.SyncParams#AUDIO_ADJUST_MODE_DEFAULT, android.media.SyncParams#AUDIO_ADJUST_MODE_STRETCH, or android.media.SyncParams#AUDIO_ADJUST_MODE_RESAMPLE
Exceptions
java.lang.IllegalStateException if the audio adjust mode is not set.

getFrameRate

Added in API level 23
fun getFrameRate(): Float

Retrieves the video frame rate hint.

Return
Float frame rate factor. A non-negative number representing the maximum deviation of the playback rate from the playback rate set. (abs(actual_rate - set_rate) / set_rate), or a negative number representing the desire to clear a previous hint using these params.
Exceptions
java.lang.IllegalStateException if frame rate is not set.

getSyncSource

Added in API level 23
fun getSyncSource(): Int

Retrieves the sync source.

Return
Int sync source Value is android.media.SyncParams#SYNC_SOURCE_DEFAULT, android.media.SyncParams#SYNC_SOURCE_SYSTEM_CLOCK, android.media.SyncParams#SYNC_SOURCE_AUDIO, or android.media.SyncParams#SYNC_SOURCE_VSYNC
Exceptions
java.lang.IllegalStateException if the sync source is not set.

getTolerance

Added in API level 23
fun getTolerance(): Float

Retrieves the tolerance factor.

Return
Float tolerance factor. A non-negative number representing the maximum deviation of the playback rate from the playback rate set. (abs(actual_rate - set_rate) / set_rate)
Exceptions
java.lang.IllegalStateException if tolerance is not set.

setAudioAdjustMode

Added in API level 23
fun setAudioAdjustMode(audioAdjustMode: Int): SyncParams!

Sets the audio adjust mode.

Parameters
audioAdjustMode Int: Value is android.media.SyncParams#AUDIO_ADJUST_MODE_DEFAULT, android.media.SyncParams#AUDIO_ADJUST_MODE_STRETCH, or android.media.SyncParams#AUDIO_ADJUST_MODE_RESAMPLE
Return
SyncParams! this SyncParams instance.

setFrameRate

Added in API level 23
fun setFrameRate(frameRate: Float): SyncParams!

Sets the video frame rate hint to be used. By default the frame rate is unspecified.

Parameters
frameRate Float: A non-negative number used as an initial hint on the video frame rate to be used when using vsync as the sync source. A negative number is used to clear a previous hint.
Return
SyncParams! this SyncParams instance.

setSyncSource

Added in API level 23
fun setSyncSource(syncSource: Int): SyncParams!

Sets the sync source.

Parameters
syncSource Int: Value is android.media.SyncParams#SYNC_SOURCE_DEFAULT, android.media.SyncParams#SYNC_SOURCE_SYSTEM_CLOCK, android.media.SyncParams#SYNC_SOURCE_AUDIO, or android.media.SyncParams#SYNC_SOURCE_VSYNC
Return
SyncParams! this SyncParams instance.

setTolerance

Added in API level 23
fun setTolerance(tolerance: Float): SyncParams!

Sets the tolerance. The default tolerance is platform specific, but is never more than 1/24.

Parameters
tolerance Float: A non-negative number representing the maximum deviation of the playback rate from the playback rate set. (abs(actual_rate - set_rate) / set_rate)
Return
SyncParams! this SyncParams instance.
Exceptions
java.lang.IllegalArgumentException if the tolerance is negative, or not less than one.