Android Dev Summit, October 23-24: two days of technical content, directly from the Android team. Sign-up for livestream updates.

PlaybackParams

class PlaybackParams
kotlin.Any
   ↳ androidx.media2.player.PlaybackParams

Structure for common playback params. Used by MediaPlayerMediaPlayer#getPlaybackParams() and MediaPlayer#setPlaybackParams(PlaybackParams) to control playback behavior.

PlaybackParams returned by MediaPlayer#getPlaybackParams() will always have values. In case of MediaPlayer#setPlaybackParams, the player will not update the param if the value is not set. For example, if pitch is set while speed is not set, only pitch will be updated.

Note that the speed value does not change the player state. For example, if MediaPlayer#getPlaybackParams() is called with the speed of 2.0f in MediaPlayer#PLAYER_STATE_PAUSED, the player will just update internal property and stay paused. Once MediaPlayer#play() is called afterwards, the player will start playback with the given speed. Calling this with zero speed is not allowed.

audio fallback mode: select out-of-range parameter handling.

pitch: increases or decreases the tonal frequency of the audio content. It is expressed as a multiplicative factor, where normal pitch is 1.0f.

speed: increases or decreases the time to play back a set of audio or video frames. It is expressed as a multiplicative factor, where normal speed is 1.0f.

Different combinations of speed and pitch may be used for audio playback; some common ones:

  • Pitch equals 1.0f. Speed change will be done with pitch preserved, often called timestretching.
  • Pitch equals speed. Speed change will be done by resampling, similar to AudioTrack#setPlaybackRate(int).

Summary

Nested classes

The builder class that makes it easy to chain setters to create a PlaybackParams object.

Constants

static Int

static Int

static Int

Public methods

Int?

Returns the audio fallback mode.

Float?

Returns the pitch factor.

Float?

Returns the speed factor.

Constants

AUDIO_FALLBACK_MODE_DEFAULT

static val AUDIO_FALLBACK_MODE_DEFAULT: Int
Value: 0

AUDIO_FALLBACK_MODE_FAIL

static val AUDIO_FALLBACK_MODE_FAIL: Int
Value: 2

AUDIO_FALLBACK_MODE_MUTE

static val AUDIO_FALLBACK_MODE_MUTE: Int
Value: 1

Public methods

getAudioFallbackMode

@Nullable fun getAudioFallbackMode(): Int?

Returns the audio fallback mode. null if a value is not set.

getPitch

@Nullable fun getPitch(): Float?

Returns the pitch factor. null if a value is not set.

getSpeed

@Nullable fun getSpeed(): Float?

Returns the speed factor. null if a value is not set.