Example usage for android.media PlaybackParams getSpeed

List of usage examples for android.media PlaybackParams getSpeed

Introduction

In this page you can find the example usage for android.media PlaybackParams getSpeed.

Prototype

public float getSpeed() 

Source Link

Document

Retrieves the speed factor.

Usage

From source file:androidx.media.widget.VideoView2.java

private void applySpeed() {
    if (android.os.Build.VERSION.SDK_INT < 23) {
        // TODO: MediaPlayer2 will cover this, or implement with SoundPool.
        return;/*from   w ww. jav  a 2 s .  c  o m*/
    }
    PlaybackParams params = mMediaPlayer.getPlaybackParams().allowDefaults();
    if (mSpeed != params.getSpeed()) {
        try {
            params.setSpeed(mSpeed);
            mMediaPlayer.setPlaybackParams(params);
            mFallbackSpeed = mSpeed;
        } catch (IllegalArgumentException e) {
            Log.e(TAG, "PlaybackParams has unsupported value: " + e);
            // TODO: should revise this part after integrating with MP2.
            // If mSpeed had an illegal value for speed rate, system will determine best
            // handling (see PlaybackParams.AUDIO_FALLBACK_MODE_DEFAULT).
            // Note: The pre-MP2 returns 0.0f when it is paused. In this case, VideoView2 will
            // use mFallbackSpeed instead.
            float fallbackSpeed = mMediaPlayer.getPlaybackParams().allowDefaults().getSpeed();
            if (fallbackSpeed > 0.0f) {
                mFallbackSpeed = fallbackSpeed;
            }
            mSpeed = mFallbackSpeed;
        }
    }
}