Java Code Examples for android.media.PlaybackParams#setSpeed()

The following examples show how to use android.media.PlaybackParams#setSpeed() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SystemPlayerManager.java    From GSYVideoPlayer with Apache License 2.0 6 votes vote down vote up
private void setSpeed(float speed) {
    if (release) {
        return;
    }
    if (mediaPlayer != null && mediaPlayer.getInternalMediaPlayer() != null && mediaPlayer.isPlayable()) {
        try {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                PlaybackParams playbackParams = new PlaybackParams();
                playbackParams.setSpeed(speed);
                mediaPlayer.getInternalMediaPlayer().setPlaybackParams(playbackParams);
            } else {
                Debuger.printfError(" not support setSpeed");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
Example 2
Source File: MediaPlayerImpl.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@Override
public void setSpeed(float speed) {
    if (Build.VERSION.SDK_INT > 23) {
        PlaybackParams params = new PlaybackParams();
        params.setSpeed(speed);
        mPlayer.setPlaybackParams(params);
    } else {
        LogUtils.w("setSpeed is invalid.");
    }
}
 
Example 3
Source File: JZMediaSystem.java    From imsdk-android with MIT License 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
public void setSpeed(float speed) {
    PlaybackParams pp = mediaPlayer.getPlaybackParams();
    pp.setSpeed(speed);
    mediaPlayer.setPlaybackParams(pp);
}
 
Example 4
Source File: JZMediaSystemAssertFolder.java    From imsdk-android with MIT License 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
public void setSpeed(float speed) {
    PlaybackParams pp = mediaPlayer.getPlaybackParams();
    pp.setSpeed(speed);
    mediaPlayer.setPlaybackParams(pp);
}
 
Example 5
Source File: SimpleExoPlayer.java    From K-Sonic with MIT License 5 votes vote down vote up
public void setPlaybackSpeed(float speed) {
  this.speed = speed;
  if (Build.VERSION.SDK_INT >= 23) {
    PlaybackParams params = new PlaybackParams();
    params.setSpeed(speed);
    setPlaybackParams(params);
  } else if (sonicMediaCodecAudioRenderer != null) {
    sonicMediaCodecAudioRenderer.setSonicSpeed(speed);
  }
}
 
Example 6
Source File: NativeAudioPlayer.java    From ExoMedia with Apache License 2.0 5 votes vote down vote up
@Override
public boolean setPlaybackSpeed(float speed) {
    // Marshmallow+ support setting the playback speed natively
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        PlaybackParams params = new PlaybackParams();
        params.setSpeed(speed);

        mediaPlayer.setPlaybackParams(params);
        return true;
    }

    return false;
}
 
Example 7
Source File: NativeVideoDelegate.java    From ExoMedia with Apache License 2.0 5 votes vote down vote up
public boolean setPlaybackSpeed(float speed) {
    // Marshmallow+ support setting the playback speed natively
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        PlaybackParams params = new PlaybackParams();
        params.setSpeed(speed);

        mediaPlayer.setPlaybackParams(params);
        return true;
    }

    return false;
}
 
Example 8
Source File: DownloadService.java    From Popeens-DSub with GNU General Public License v3.0 5 votes vote down vote up
private synchronized void applyPlaybackParams(MediaPlayer mediaPlayer) {
	if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
		float playbackSpeed = getPlaybackSpeed();

		try {
			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);
		}
	}
}
 
Example 9
Source File: AndroidAudioPlayer.java    From AntennaPod-AudioPlayer with Apache License 2.0 5 votes vote down vote up
@Override
public void setPlaybackSpeed(float f) {
    Log.d(AMP_TAG, "setPlaybackSpeed(" + f + ")");
    if (Build.VERSION.SDK_INT < 23) {
        return;
    }
    PlaybackParams params = mp.getPlaybackParams();
    params.setSpeed(f);
    boolean isPaused = this.owningMediaPlayer.state == org.antennapod.audio.MediaPlayer.State.PAUSED;
    mp.setPlaybackParams(params);
    if (isPaused) {
        mp.pause();
    }
}
 
Example 10
Source File: FullscreenVideoMediaPlayer.java    From fullscreen-video-view with Apache License 2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.M)
public void changePlaybackSpeed(float speed) {
    PlaybackParams playbackParams = new PlaybackParams();
    playbackParams.setSpeed(speed);
    setPlaybackParams(playbackParams);
}
 
Example 11
Source File: BaseTvInputService.java    From xipl with Apache License 2.0 4 votes vote down vote up
@Override
public void onTimeShiftResume() {
    if (DEBUG) Log.d(TAG, "Resume playback of program");
    mTimeShiftIsPaused = false;
    if (mCurrentProgram == null) {
        return;
    }

    if (!mPlayingRecordedProgram) {
        // If currently playing program content, past ad durations must be recalculated
        // based on getTvPlayer.getCurrentPosition().
        mElapsedAdsTime = 0;
        mElapsedProgramTime = getTvPlayer().getCurrentPosition();
        long elapsedProgramTimeAdjusted =
                mElapsedProgramTime + mCurrentProgram.getStartTimeUtcMillis();
        if (mCurrentProgram.getInternalProviderData() != null) {
            List<Advertisement> ads = mCurrentProgram.getInternalProviderData().getAds();
            // First, sort the ads in time order.
            TreeMap<Long, Long> scheduledAds = new TreeMap<>();
            for (Advertisement ad : ads) {
                scheduledAds.put(ad.getStartTimeUtcMillis(), ad.getStopTimeUtcMillis());
            }
            // Second, add up all ad times which should have played before the elapsed
            // program time.
            long programDurationPlayed = 0;
            long totalDurationPlayed = 0;
            for (Long adStartTime : scheduledAds.keySet()) {
                programDurationPlayed += adStartTime - totalDurationPlayed;
                if (programDurationPlayed < elapsedProgramTimeAdjusted) {
                    long adDuration = scheduledAds.get(adStartTime) - adStartTime;
                    mElapsedAdsTime += adDuration;
                    totalDurationPlayed = programDurationPlayed + adDuration;
                } else {
                    break;
                }
            }
        } else {
            Log.w(
                    TAG,
                    "Failed to get program provider data for "
                            + mCurrentProgram.getTitle()
                            + ". Try to do an EPG sync.");
        }

        mTimeShiftedPlaybackPosition = elapsedProgramTimeAdjusted + mElapsedAdsTime;

        scheduleNextAd();
        scheduleNextProgram();
    }

    if (getTvPlayer() != null) {
        getTvPlayer().play();
    }
    // Resume and make sure media is playing at regular speed.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        PlaybackParams normalParams = new PlaybackParams();
        normalParams.setSpeed(1);
        onTimeShiftSetPlaybackParams(normalParams);
    }
}
 
Example 12
Source File: BaseTvInputService.java    From androidtv-sample-inputs with Apache License 2.0 4 votes vote down vote up
@Override
public void onTimeShiftResume() {
    if (DEBUG) Log.d(TAG, "Resume playback of program");
    mTimeShiftIsPaused = false;
    if (mCurrentProgram == null) {
        return;
    }

    if (!mPlayingRecordedProgram) {
        // If currently playing program content, past ad durations must be recalculated
        // based on getTvPlayer.getCurrentPosition().
        mElapsedAdsTime = 0;
        mElapsedProgramTime = getTvPlayer().getCurrentPosition();
        long elapsedProgramTimeAdjusted =
                mElapsedProgramTime + mCurrentProgram.getStartTimeUtcMillis();
        if (mCurrentProgram.getInternalProviderData() != null) {
            List<Advertisement> ads = mCurrentProgram.getInternalProviderData().getAds();
            // First, sort the ads in time order.
            TreeMap<Long, Long> scheduledAds = new TreeMap<>();
            for (Advertisement ad : ads) {
                scheduledAds.put(ad.getStartTimeUtcMillis(), ad.getStopTimeUtcMillis());
            }
            // Second, add up all ad times which should have played before the elapsed
            // program time.
            long programDurationPlayed = 0;
            long totalDurationPlayed = 0;
            for (Long adStartTime : scheduledAds.keySet()) {
                programDurationPlayed += adStartTime - totalDurationPlayed;
                if (programDurationPlayed < elapsedProgramTimeAdjusted) {
                    long adDuration = scheduledAds.get(adStartTime) - adStartTime;
                    mElapsedAdsTime += adDuration;
                    totalDurationPlayed = programDurationPlayed + adDuration;
                } else {
                    break;
                }
            }
        } else {
            Log.w(
                    TAG,
                    "Failed to get program provider data for "
                            + mCurrentProgram.getTitle()
                            + ". Try to do an EPG sync.");
        }

        mTimeShiftedPlaybackPosition = elapsedProgramTimeAdjusted + mElapsedAdsTime;

        scheduleNextAd();
        scheduleNextProgram();
    }

    if (getTvPlayer() != null) {
        getTvPlayer().play();
    }
    // Resume and make sure media is playing at regular speed.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        PlaybackParams normalParams = new PlaybackParams();
        normalParams.setSpeed(1);
        onTimeShiftSetPlaybackParams(normalParams);
    }
}