Example usage for android.media PlaybackParams PlaybackParams

List of usage examples for android.media PlaybackParams PlaybackParams

Introduction

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

Prototype

public PlaybackParams() 

Source Link

Usage

From source file:nuclei.media.playback.FallbackPlayback.java

@Override
public void setPlaybackParams(PlaybackParameters playbackParams) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (mMediaPlayer == null || !mPrepared) {
            mPlaybackParams = new PlaybackParams().setSpeed(playbackParams.speed)
                    .setPitch(playbackParams.pitch);
        } else {/*from  w  ww  . ja v  a  2 s .c  o  m*/
            mMediaPlayer.setPlaybackParams(
                    new PlaybackParams().setSpeed(playbackParams.speed).setPitch(playbackParams.pitch));

            if (mState != PlaybackStateCompat.STATE_PLAYING && mMediaPlayer.isPlaying()) {
                mState = PlaybackStateCompat.STATE_PLAYING;
            }
            if (mCallback != null) {
                mCallback.onPlaybackStatusChanged(mState);
            }
        }
    }
}

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  ww w .  jav a 2s.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.
 *///from www.j ava  2  s.  co m
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: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 {// w w w  .j  av a2s. 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);
        }
    }
}