Skip to content

Most visited

Recently visited

navigation

SyncParams

public final class SyncParams
extends Object

java.lang.Object
   ↳ 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

int AUDIO_ADJUST_MODE_DEFAULT

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

int AUDIO_ADJUST_MODE_RESAMPLE

Resample audio when playback rate must be adjusted.

int AUDIO_ADJUST_MODE_STRETCH

Time stretch audio when playback rate must be adjusted.

int SYNC_SOURCE_AUDIO

Use audio track for sync source.

int SYNC_SOURCE_DEFAULT

Use the default sync source (default).

int SYNC_SOURCE_SYSTEM_CLOCK

Use system monotonic clock for sync source.

int SYNC_SOURCE_VSYNC

Use vsync as the sync source.

Public constructors

SyncParams()

Public methods

SyncParams allowDefaults()

Allows defaults to be returned for properties not set.

int getAudioAdjustMode()

Retrieves the audio adjust mode.

float getFrameRate()

Retrieves the video frame rate hint.

int getSyncSource()

Retrieves the sync source.

float getTolerance()

Retrieves the tolerance factor.

SyncParams setAudioAdjustMode(int audioAdjustMode)

Sets the audio adjust mode.

SyncParams setFrameRate(float frameRate)

Sets the video frame rate hint to be used.

SyncParams setSyncSource(int syncSource)

Sets the sync source.

SyncParams setTolerance(float tolerance)

Sets the tolerance.

Inherited methods

From class java.lang.Object

Constants

AUDIO_ADJUST_MODE_DEFAULT

added in API level 23
int AUDIO_ADJUST_MODE_DEFAULT

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.

Constant Value: 0 (0x00000000)

AUDIO_ADJUST_MODE_RESAMPLE

added in API level 23
int AUDIO_ADJUST_MODE_RESAMPLE

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.)

See also:

Constant Value: 2 (0x00000002)

AUDIO_ADJUST_MODE_STRETCH

added in API level 23
int AUDIO_ADJUST_MODE_STRETCH

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.

See also:

Constant Value: 1 (0x00000001)

SYNC_SOURCE_AUDIO

added in API level 23
int SYNC_SOURCE_AUDIO

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

See also:

Constant Value: 2 (0x00000002)

SYNC_SOURCE_DEFAULT

added in API level 23
int SYNC_SOURCE_DEFAULT

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.

Constant Value: 0 (0x00000000)

SYNC_SOURCE_SYSTEM_CLOCK

added in API level 23
int SYNC_SOURCE_SYSTEM_CLOCK

Use system monotonic clock for sync source.

See also:

Constant Value: 1 (0x00000001)

SYNC_SOURCE_VSYNC

added in API level 23
int SYNC_SOURCE_VSYNC

Use vsync as the sync source. This requires video data and an output surface that directly renders to the display, e.g. 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).

See also:

Constant Value: 3 (0x00000003)

Public constructors

SyncParams

added in API level 23
SyncParams ()

Public methods

allowDefaults

added in API level 23
SyncParams allowDefaults ()

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

Returns
SyncParams this SyncParams instance.

getAudioAdjustMode

added in API level 23
int getAudioAdjustMode ()

Retrieves the audio adjust mode.

Returns
int audio adjust mode

Throws
IllegalStateException if the audio adjust mode is not set.

getFrameRate

added in API level 23
float getFrameRate ()

Retrieves the video frame rate hint.

Returns
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.

Throws
IllegalStateException if frame rate is not set.

getSyncSource

added in API level 23
int getSyncSource ()

Retrieves the sync source.

Returns
int sync source

Throws
IllegalStateException if the sync source is not set.

getTolerance

added in API level 23
float getTolerance ()

Retrieves the tolerance factor.

Returns
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)

Throws
IllegalStateException if tolerance is not set.

setAudioAdjustMode

added in API level 23
SyncParams setAudioAdjustMode (int audioAdjustMode)

Sets the audio adjust mode.

Returns
SyncParams this SyncParams instance.

setFrameRate

added in API level 23
SyncParams setFrameRate (float frameRate)

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.

Returns
SyncParams this SyncParams instance.

setSyncSource

added in API level 23
SyncParams setSyncSource (int syncSource)

Sets the sync source.

Returns
SyncParams this SyncParams instance.

setTolerance

added in API level 23
SyncParams setTolerance (float tolerance)

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)

Returns
SyncParams this SyncParams instance.

Throws
if the tolerance is negative, or not less than one
This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience.
(Sep 2017 survey)