PlaybackParams
public
final
class
PlaybackParams
extends Object
java.lang.Object | |
↳ | androidx.media2.player.PlaybackParams |
Structure for common playback params.
Used by MediaPlayer
MediaPlayer.getPlaybackParams()
and
MediaPlayer.setPlaybackParams(PlaybackParams)
to control playback behavior.
PlaybackParams returned by MediaPlayer.getPlaybackParams()
will always have values.
In case of MediaPlayer.setPlaybackParams(PlaybackParams)
, 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
SessionPlayer.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.
-
AUDIO_FALLBACK_MODE_DEFAULT
: System will determine best handling. -
AUDIO_FALLBACK_MODE_MUTE
: Play silence for params normally out of range. -
AUDIO_FALLBACK_MODE_FAIL
: ReturnIllegalArgumentException
fromAudioTrack.setPlaybackParams(PlaybackParams)
.
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 | |
---|---|
class |
PlaybackParams.Builder
The builder class that makes it easy to chain setters to create a |
Constants | |
---|---|
int |
AUDIO_FALLBACK_MODE_DEFAULT
|
int |
AUDIO_FALLBACK_MODE_FAIL
|
int |
AUDIO_FALLBACK_MODE_MUTE
|
Public methods | |
---|---|
Integer
|
getAudioFallbackMode()
Returns the audio fallback mode. |
Float
|
getPitch()
Returns the pitch factor. |
Float
|
getSpeed()
Returns the speed factor. |
Inherited methods | |
---|---|
Constants
AUDIO_FALLBACK_MODE_DEFAULT
public static final int AUDIO_FALLBACK_MODE_DEFAULT
Constant Value: 0 (0x00000000)
AUDIO_FALLBACK_MODE_FAIL
public static final int AUDIO_FALLBACK_MODE_FAIL
Constant Value: 2 (0x00000002)
AUDIO_FALLBACK_MODE_MUTE
public static final int AUDIO_FALLBACK_MODE_MUTE
Constant Value: 1 (0x00000001)
Public methods
getAudioFallbackMode
public Integer getAudioFallbackMode ()
Returns the audio fallback mode. null
if a value is not set.
Returns | |
---|---|
Integer |
getPitch
public Float getPitch ()
Returns the pitch factor. null
if a value is not set.
Returns | |
---|---|
Float |
getSpeed
public Float getSpeed ()
Returns the speed factor. null
if a value is not set.
Returns | |
---|---|
Float |
Content and code samples on this page are subject to the licenses described in the Content License. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2020-09-30 UTC.