Java Code Examples for android.media.PlaybackParams

The following examples show how to use android.media.PlaybackParams. These examples are extracted from open source projects. 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 Project: android_9.0.0_r45   Source File: TvInputManagerService.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void timeShiftSetPlaybackParams(IBinder sessionToken, PlaybackParams params,
        int userId) {
    final int callingUid = Binder.getCallingUid();
    final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), callingUid,
            userId, "timeShiftSetPlaybackParams");
    final long identity = Binder.clearCallingIdentity();
    try {
        synchronized (mLock) {
            try {
                getSessionLocked(sessionToken, callingUid, resolvedUserId)
                        .timeShiftSetPlaybackParams(params);
            } catch (RemoteException | SessionNotFoundException e) {
                Slog.e(TAG, "error in timeShiftSetPlaybackParams", e);
            }
        }
    } finally {
        Binder.restoreCallingIdentity(identity);
    }
}
 
Example 2
Source Project: GSYVideoPlayer   Source File: SystemPlayerManager.java    License: 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 3
Source Project: K-Sonic   Source File: SimpleExoPlayer.java    License: MIT License 6 votes vote down vote up
/**
 * Sets the {@link PlaybackParams} governing audio playback.
 *
 * @param params The {@link PlaybackParams}, or null to clear any previously set parameters.
 */
@TargetApi(23)
public void setPlaybackParams(PlaybackParams params) {
  if (params != null) {
    // The audio renderers will call this on the playback thread to ensure they can query
    // parameters without failure. We do the same up front, which is redundant except that it
    // ensures an immediate call to getPlaybackParams will retrieve the instance with defaults
    // allowed, rather than this change becoming visible sometime later once the audio renderers
    // receive the parameters.
    params.allowDefaults();
    playbackParamsHolder = new PlaybackParamsHolder(params);
  } else {
    playbackParamsHolder = null;
  }
  ExoPlayerMessage[] messages = new ExoPlayerMessage[audioRendererCount];
  int count = 0;
  for (Renderer renderer : renderers) {
    if (renderer.getTrackType() == C.TRACK_TYPE_AUDIO) {
      messages[count++] = new ExoPlayerMessage(renderer, C.MSG_SET_PLAYBACK_PARAMS, params);
    }
  }
  player.sendMessages(messages);
}
 
Example 4
Source Project: K-Sonic   Source File: SimpleDecoderAudioRenderer.java    License: MIT License 6 votes vote down vote up
@Override
public void handleMessage(int messageType, Object message) throws ExoPlaybackException {
  switch (messageType) {
    case C.MSG_SET_VOLUME:
      audioTrack.setVolume((Float) message);
      break;
    case C.MSG_SET_PLAYBACK_PARAMS:
      audioTrack.setPlaybackParams((PlaybackParams) message);
      break;
    case C.MSG_SET_STREAM_TYPE:
      @C.StreamType int streamType = (Integer) message;
      audioTrack.setStreamType(streamType);
      break;
    default:
      super.handleMessage(messageType, message);
      break;
  }
}
 
Example 5
Source Project: K-Sonic   Source File: MediaCodecAudioRenderer.java    License: MIT License 6 votes vote down vote up
@Override
public void handleMessage(int messageType, Object message) throws ExoPlaybackException {
  switch (messageType) {
    case C.MSG_SET_VOLUME:
      audioTrack.setVolume((Float) message);
      break;
    case C.MSG_SET_PLAYBACK_PARAMS:
      audioTrack.setPlaybackParams((PlaybackParams) message);
      break;
    case C.MSG_SET_STREAM_TYPE:
      @C.StreamType int streamType = (Integer) message;
      audioTrack.setStreamType(streamType);
      break;
    default:
      super.handleMessage(messageType, message);
      break;
  }
}
 
Example 6
Source Project: MediaSDK   Source File: SimpleExoPlayer.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Sets the {@link PlaybackParams} governing audio playback.
 *
 * @deprecated Use {@link #setPlaybackParameters(PlaybackParameters)}.
 * @param params The {@link PlaybackParams}, or null to clear any previously set parameters.
 */
@Deprecated
@TargetApi(23)
public void setPlaybackParams(@Nullable PlaybackParams params) {
  PlaybackParameters playbackParameters;
  if (params != null) {
    params.allowDefaults();
    playbackParameters = new PlaybackParameters(params.getSpeed(), params.getPitch());
  } else {
    playbackParameters = null;
  }
  setPlaybackParameters(playbackParameters);
}
 
Example 7
Source Project: MediaSDK   Source File: MediaPlayerImpl.java    License: 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 8
/**
 * Sets the {@link PlaybackParams} governing audio playback.
 *
 * @deprecated Use {@link #setPlaybackParameters(PlaybackParameters)}.
 * @param params The {@link PlaybackParams}, or null to clear any previously set parameters.
 */
@Deprecated
@TargetApi(23)
public void setPlaybackParams(@Nullable PlaybackParams params) {
  PlaybackParameters playbackParameters;
  if (params != null) {
    params.allowDefaults();
    playbackParameters = new PlaybackParameters(params.getSpeed(), params.getPitch());
  } else {
    playbackParameters = null;
  }
  setPlaybackParameters(playbackParameters);
}
 
Example 9
Source Project: imsdk-android   Source File: JZMediaSystem.java    License: 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 10
Source Project: imsdk-android   Source File: JZMediaSystemAssertFolder.java    License: 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 11
/**
 * Sets the {@link PlaybackParams} governing audio playback.
 *
 * @deprecated Use {@link #setPlaybackParameters(PlaybackParameters)}.
 * @param params The {@link PlaybackParams}, or null to clear any previously set parameters.
 */
@Deprecated
@TargetApi(23)
public void setPlaybackParams(@Nullable PlaybackParams params) {
  PlaybackParameters playbackParameters;
  if (params != null) {
    params.allowDefaults();
    playbackParameters = new PlaybackParameters(params.getSpeed(), params.getPitch());
  } else {
    playbackParameters = null;
  }
  setPlaybackParameters(playbackParameters);
}
 
Example 12
Source Project: xipl   Source File: BaseTvInputService.java    License: Apache License 2.0 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
public void onTimeShiftSetPlaybackParams(PlaybackParams params) {
    if (params.getSpeed() != 1.0f) {
        mHandler.removeMessages(MSG_PLAY_AD);
        mDbHandler.removeCallbacks(mGetCurrentProgramRunnable);
    }

    if (DEBUG) {
        Log.d(TAG, "Set playback speed to " + params.getSpeed());
    }
    if (getTvPlayer() != null) {
        getTvPlayer().setPlaybackParams(params);
    }
}
 
Example 13
Source Project: K-Sonic   Source File: SimpleExoPlayer.java    License: 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 14
Source Project: K-Sonic   Source File: SimpleExoPlayer.java    License: MIT License 5 votes vote down vote up
public void setPlaybackPitch(float pitch) {
  this.pitch = pitch;
  if (Build.VERSION.SDK_INT >= 23) {
    PlaybackParams params = new PlaybackParams();
    params.setPitch(pitch);
    setPlaybackParams(params);
  } else if (sonicMediaCodecAudioRenderer != null) {
    sonicMediaCodecAudioRenderer.setSonicPitch(pitch);
  }
}
 
Example 15
Source Project: K-Sonic   Source File: AudioTrack.java    License: MIT License 5 votes vote down vote up
@Override
public void setPlaybackParams(PlaybackParams playbackParams) {
  playbackParams = (playbackParams != null ? playbackParams : new PlaybackParams())
      .allowDefaults();
  this.playbackParams = playbackParams;
  playbackSpeed = playbackParams.getSpeed();
  maybeApplyPlaybackParams();
}
 
Example 16
Source Project: ChannelSurfer   Source File: SimpleSessionImpl.java    License: MIT License 5 votes vote down vote up
@Override
public void onTimeShiftSetPlaybackParams(PlaybackParams params) {
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (tvInputProvider instanceof TimeShiftable) {
            ((TimeShiftable) tvInputProvider).onMediaSetPlaybackParams(params);
        }
    }
}
 
Example 17
Source Project: ExoMedia   Source File: NativeAudioPlayer.java    License: 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 18
Source Project: ExoMedia   Source File: NativeVideoDelegate.java    License: 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 19
Source Project: CumulusTV   Source File: CumulusTvPlayer.java    License: MIT License 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
public void setPlaybackParams(PlaybackParams params) {
    mSimpleExoPlayer.setPlaybackParams(params);
    mPlaybackSpeed = params.getSpeed();
    if (DEBUG) {
        Log.d(TAG, "Set params " + params.toString());
    }
}
 
Example 20
Source Project: Popeens-DSub   Source File: DownloadService.java    License: 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 21
Source Project: AntennaPod-AudioPlayer   Source File: AndroidAudioPlayer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void setPitchStepsAdjustment(float pitchSteps) {
    if (Build.VERSION.SDK_INT < 23) {
        return;
    }
    PlaybackParams params = mp.getPlaybackParams();
    params.setPitch(params.getPitch() + pitchSteps);
    mp.setPlaybackParams(params);
}
 
Example 22
Source Project: AntennaPod-AudioPlayer   Source File: AndroidAudioPlayer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void setPlaybackPitch(float f) {
    Log.d(AMP_TAG, "setPlaybackPitch(" + f + ")");
    if (Build.VERSION.SDK_INT < 23) {
        return;
    }
    PlaybackParams params = mp.getPlaybackParams();
    params.setPitch(f);
    mp.setPlaybackParams(params);
}
 
Example 23
Source Project: AntennaPod-AudioPlayer   Source File: AndroidAudioPlayer.java    License: 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 24
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
public void onTimeShiftSetPlaybackParams(PlaybackParams params) {
    if (params.getSpeed() != 1.0f) {
        mHandler.removeMessages(MSG_PLAY_AD);
        mDbHandler.removeCallbacks(mGetCurrentProgramRunnable);
    }

    if (DEBUG) {
        Log.d(TAG, "Set playback speed to " + params.getSpeed());
    }
    if (getTvPlayer() != null) {
        getTvPlayer().setPlaybackParams(params);
    }
}
 
Example 25
/**
 * Sets the {@link PlaybackParams} governing audio playback.
 *
 * @deprecated Use {@link #setPlaybackParameters(PlaybackParameters)}.
 * @param params The {@link PlaybackParams}, or null to clear any previously set parameters.
 */
@Deprecated
@TargetApi(23)
public void setPlaybackParams(@Nullable PlaybackParams params) {
  PlaybackParameters playbackParameters;
  if (params != null) {
    params.allowDefaults();
    playbackParameters = new PlaybackParameters(params.getSpeed(), params.getPitch());
  } else {
    playbackParameters = null;
  }
  setPlaybackParameters(playbackParameters);
}
 
Example 26
Source Project: Telegram   Source File: SimpleExoPlayer.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the {@link PlaybackParams} governing audio playback.
 *
 * @deprecated Use {@link #setPlaybackParameters(PlaybackParameters)}.
 * @param params The {@link PlaybackParams}, or null to clear any previously set parameters.
 */
@Deprecated
@TargetApi(23)
public void setPlaybackParams(@Nullable PlaybackParams params) {
  PlaybackParameters playbackParameters;
  if (params != null) {
    params.allowDefaults();
    playbackParameters = new PlaybackParameters(params.getSpeed(), params.getPitch());
  } else {
    playbackParameters = null;
  }
  setPlaybackParameters(playbackParameters);
}
 
Example 27
@TargetApi(Build.VERSION_CODES.M)
public void changePlaybackSpeed(float speed) {
    PlaybackParams playbackParams = new PlaybackParams();
    playbackParams.setSpeed(speed);
    setPlaybackParams(playbackParams);
}
 
Example 28
Source Project: xipl   Source File: BaseTvInputService.java    License: 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 29
Source Project: xipl   Source File: MockTvPlayer.java    License: Apache License 2.0 4 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
public void setPlaybackParams(PlaybackParams params) {
    mMediaPlayer.setPlaybackParams(params);
}
 
Example 30
Source Project: K-Sonic   Source File: SimpleExoPlayer.java    License: MIT License 4 votes vote down vote up
/**
 * Returns the {@link PlaybackParams} governing audio playback, or null if not set.
 */
@TargetApi(23)
public PlaybackParams getPlaybackParams() {
  return playbackParamsHolder == null ? null : playbackParamsHolder.params;
}