Example usage for android.media PlaybackParams setSpeed

List of usage examples for android.media PlaybackParams setSpeed

Introduction

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

Prototype

public PlaybackParams setSpeed(float speed) 

Source Link

Document

Sets the speed factor.

Usage

From source file:com.android.tv.ui.TunableTvView.java

/**
 * Rewinds the media with the given speed, if the current input supports time-shifting.
 *
 * @param speed The speed to rewind the media. e.g. 2 for 2x, 3 for 3x and 4 for 4x.
 *///from   www.j  a  va  2  s  . co  m
public void timeshiftRewind(int speed) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        Log.w(TAG, "Time shifting is not supported in this platform.");
    } else if (!isTimeShiftAvailable()) {
        throw new IllegalStateException("Time-shift is not supported for the current channel");
    } else {
        if (speed <= 0) {
            throw new IllegalArgumentException("The speed should be a positive integer.");
        }
        mTimeShiftState = TIME_SHIFT_STATE_REWIND;
        PlaybackParams params = new PlaybackParams();
        params.setSpeed(speed * -1);
        mTvView.timeShiftSetPlaybackParams(params);
    }
}

From source file:com.android.tv.ui.TunableTvView.java

/**
 * Fast-forwards the media with the given speed, if the current input supports time-shifting.
 *
 * @param speed The speed to forward the media. e.g. 2 for 2x, 3 for 3x and 4 for 4x.
 *//*  www. ja  v  a  2  s.  c  om*/
public void timeshiftFastForward(int speed) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        Log.w(TAG, "Time shifting is not supported in this platform.");
    } else if (!isTimeShiftAvailable()) {
        throw new IllegalStateException("Time-shift is not supported for the current channel");
    } else {
        if (speed <= 0) {
            throw new IllegalArgumentException("The speed should be a positive integer.");
        }
        mTimeShiftState = TIME_SHIFT_STATE_FAST_FORWARD;
        PlaybackParams params = new PlaybackParams();
        params.setSpeed(speed);
        mTvView.timeShiftSetPlaybackParams(params);
    }
}

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   www.j a  v a  2  s.com
    }
    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;
        }
    }
}

From source file:github.popeen.dsub.service.DownloadService.java

private synchronized void applyPlaybackParams(MediaPlayer mediaPlayer) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        float playbackSpeed = getPlaybackSpeed();

        try {//from  w w w .j a v a  2 s  . c o m
            if (Math.abs(playbackSpeed - 1.0) > 0.01 || mediaPlayer.getPlaybackParams() != null) {
                PlaybackParams playbackParams = new PlaybackParams();
                playbackParams.setSpeed(playbackSpeed);
                mediaPlayer.setPlaybackParams(playbackParams);
            }
        } catch (Exception e) {
            Log.e(TAG, "Error while applying media player params", e);
        }
    }
}