Example usage for android.media MediaPlayer setPlaybackParams

List of usage examples for android.media MediaPlayer setPlaybackParams

Introduction

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

Prototype

public native void setPlaybackParams(@NonNull PlaybackParams params);

Source Link

Document

Sets playback rate using PlaybackParams .

Usage

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

/**
 * Called when media player is done preparing.
 *
 * @see OnPreparedListener//from  w  w w  .j ava  2  s .co m
 */
@Override
public void onPrepared(MediaPlayer player) {
    mPrepared = true;
    // The media player is done preparing. That means we can start playing if we
    // have audio focus.
    if (mSurface != null && mSurface.isValid())
        player.setSurface(mSurface);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (mPlaybackParams != null)
            player.setPlaybackParams(mPlaybackParams);
    }

    if (mMediaPlayer != null && mMetadata != null
            && mMetadata.getLong(MediaMetadataCompat.METADATA_KEY_DURATION) != mMediaPlayer.getDuration()) {
        mMetadata.setDuration(getDuration());
        if (mCallback != null)
            mCallback.onMetadataChanged(mMetadata);
    }

    configMediaPlayerState();
}

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   ww  w .  j  av  a  2s. 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);
        }
    }
}