public void handlePrepareRequest() { mPendingAutoContinue = false; if (mMediaMetadata != null) { final MediaId id = MediaProvider.getInstance().getMediaId(mMediaMetadata.getDescription().getMediaId()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (id.type == MediaId.TYPE_AUDIO) mPlayback.setPlaybackParams(new PlaybackParameters(mServiceCallback.getAudioSpeed(), 1)); else mPlayback.setPlaybackParams(PlaybackParameters.DEFAULT); } mServiceCallback.onPlaybackPrepare(id); mPlayback.prepare(mMediaMetadata); mHandler.removeMessages(TIMER_COUNTDOWN); mHandler.removeMessages(TIMER_TIMING); if (mQueue != null && !mQueue.setMetadata(mMediaMetadata)) { mQueue = null; mServiceCallback.onQueue(null); } } }
@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 { 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); } } } }
@Override public PlaybackParameters setPlaybackParameters(PlaybackParameters playbackParameters) { // Store the current position as the new base, in case the playback speed has changed. if (started) { setPositionUs(getPositionUs()); } this.playbackParameters = playbackParameters; return playbackParameters; }
/** * @param audioCapabilities The audio capabilities for playback on this device. May be null if the * default capabilities (no encoded audio passthrough support) should be assumed. * @param audioProcessors An array of {@link AudioProcessor}s that will process PCM audio before * output. May be empty. * @param listener Listener for audio track events. */ public AudioTrack(AudioCapabilities audioCapabilities, AudioProcessor[] audioProcessors, Listener listener) { this.audioCapabilities = audioCapabilities; this.listener = listener; releasingConditionVariable = new ConditionVariable(true); if (Util.SDK_INT >= 18) { try { getLatencyMethod = android.media.AudioTrack.class.getMethod("getLatency", (Class<?>[]) null); } catch (NoSuchMethodException e) { // There's no guarantee this method exists. Do nothing. } } if (Util.SDK_INT >= 19) { audioTrackUtil = new AudioTrackUtilV19(); } else { audioTrackUtil = new AudioTrackUtil(); } channelMappingAudioProcessor = new ChannelMappingAudioProcessor(); sonicAudioProcessor = new SonicAudioProcessor(); availableAudioProcessors = new AudioProcessor[3 + audioProcessors.length]; availableAudioProcessors[0] = new ResamplingAudioProcessor(); availableAudioProcessors[1] = channelMappingAudioProcessor; System.arraycopy(audioProcessors, 0, availableAudioProcessors, 2, audioProcessors.length); availableAudioProcessors[2 + audioProcessors.length] = sonicAudioProcessor; playheadOffsets = new long[MAX_PLAYHEAD_OFFSET_COUNT]; volume = 1.0f; startMediaTimeState = START_NOT_SET; streamType = C.STREAM_TYPE_DEFAULT; audioSessionId = C.AUDIO_SESSION_ID_UNSET; playbackParameters = PlaybackParameters.DEFAULT; drainingAudioProcessorIndex = C.INDEX_UNSET; this.audioProcessors = new AudioProcessor[0]; outputBuffers = new ByteBuffer[0]; playbackParametersCheckpoints = new LinkedList<>(); }
public void handlePlayRequest() { mPendingAutoContinue = false; if (mMediaMetadata != null) { final MediaId id = MediaProvider.getInstance().getMediaId(mMediaMetadata.getDescription().getMediaId()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (id.type == MediaId.TYPE_AUDIO) mPlayback.setPlaybackParams(new PlaybackParameters(mServiceCallback.getAudioSpeed(), 1)); else mPlayback.setPlaybackParams(PlaybackParameters.DEFAULT); } mServiceCallback.onPlaybackStart(id); mServiceCallback.onNotificationRequired(); mPlayback.start(); mPlayback.play(mMediaMetadata); if (mTimer > -1) { mHandler.removeMessages(TIMER_COUNTDOWN); mHandler.sendEmptyMessageDelayed(TIMER_COUNTDOWN, ONE_SECOND); } if (mPlayback.getTiming() != null) { mHandler.removeMessages(TIMER_TIMING); mHandler.sendEmptyMessageDelayed(TIMER_TIMING, ONE_SECOND); } if (mQueue != null && !mQueue.setMetadata(mMediaMetadata)) { mQueue = null; mServiceCallback.onQueue(null); } } }
@Override public void onCustomAction(@NonNull String action, Bundle extras) { switch (action) { case MediaService.ACTION_SET_SURFACE: final long surfaceId = extras.getLong(MediaService.EXTRA_SURFACE_ID); if (!extras.containsKey(MediaService.EXTRA_SURFACE)) { mPlayback.setSurface(surfaceId, null); } else { final Surface surface = extras.getParcelable(MediaService.EXTRA_SURFACE); mPlayback.setSurface(surfaceId, surface); } break; case MediaService.ACTION_SET_SPEED: final float speed = extras.getFloat(MediaService.EXTRA_SPEED); mServiceCallback.onSpeedSet(speed); mPlayback.setPlaybackParams(new PlaybackParameters(speed, 1)); break; case MediaService.ACTION_SET_TIMER: mTimer = extras.getLong(MediaService.EXTRA_TIMER); mHandler.removeMessages(TIMER_COUNTDOWN); if (mTimer != -1) mHandler.sendEmptyMessageDelayed(TIMER_COUNTDOWN, ONE_SECOND); mServiceCallback.onTimerCount(mTimer); break; case MediaService.ACTION_SET_AUTO_CONTINUE: final boolean autoContinue = extras.getBoolean(MediaService.EXTRA_AUTO_CONTINUE); mServiceCallback.onAutoContinueSet(autoContinue); break; default: break; } }
@Override public void setPlaybackParams(PlaybackParameters playbackParams) { mPlaybackParams = playbackParams; if (mMediaPlayer != null) mMediaPlayer.setPlaybackParameters(playbackParams); if (mCallback != null) mCallback.onPlaybackStatusChanged(mState); }
/** * 倍速播放 * * @param speed 倍速播放,默认为1 * @param pitch 音量缩放,默认为1,修改会导致声音变调 */ public void setSpeed(@Size(min = 0) float speed, @Size(min = 0) float pitch) { PlaybackParameters playbackParameters = new PlaybackParameters(speed, pitch); mSpeedPlaybackParameters = playbackParameters; if (mInternalPlayer != null) { mInternalPlayer.setPlaybackParameters(playbackParameters); } }
@Override public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) { HashMap<String, String> callingMethodParameters = new HashMap<>(); callingMethodParameters.put("playbackParameters", String.valueOf(playbackParameters)); infoListener.onNewInfo("onPlaybackParametersChanged", callingMethodParameters); }
/** * @param audioCapabilities The audio capabilities for playback on this device. May be null if the * default capabilities (no encoded audio passthrough support) should be assumed. * @param audioProcessors An array of {@link AudioProcessor}s that will process PCM audio before * output. May be empty. */ public DefaultAudioSink(@Nullable AudioCapabilities audioCapabilities, AudioProcessor[] audioProcessors) { this.audioCapabilities = audioCapabilities; releasingConditionVariable = new ConditionVariable(true); if (Util.SDK_INT >= 18) { try { getLatencyMethod = AudioTrack.class.getMethod("getLatency", (Class<?>[]) null); } catch (NoSuchMethodException e) { // There's no guarantee this method exists. Do nothing. } } if (Util.SDK_INT >= 19) { audioTrackUtil = new AudioTrackUtilV19(); } else { audioTrackUtil = new AudioTrackUtil(); } channelMappingAudioProcessor = new ChannelMappingAudioProcessor(); trimmingAudioProcessor = new TrimmingAudioProcessor(); sonicAudioProcessor = new SonicAudioProcessor(); availableAudioProcessors = new AudioProcessor[4 + audioProcessors.length]; availableAudioProcessors[0] = new ResamplingAudioProcessor(); availableAudioProcessors[1] = channelMappingAudioProcessor; availableAudioProcessors[2] = trimmingAudioProcessor; System.arraycopy(audioProcessors, 0, availableAudioProcessors, 3, audioProcessors.length); availableAudioProcessors[3 + audioProcessors.length] = sonicAudioProcessor; playheadOffsets = new long[MAX_PLAYHEAD_OFFSET_COUNT]; volume = 1.0f; startMediaTimeState = START_NOT_SET; audioAttributes = AudioAttributes.DEFAULT; audioSessionId = C.AUDIO_SESSION_ID_UNSET; playbackParameters = PlaybackParameters.DEFAULT; drainingAudioProcessorIndex = C.INDEX_UNSET; this.audioProcessors = new AudioProcessor[0]; outputBuffers = new ByteBuffer[0]; playbackParametersCheckpoints = new ArrayDeque<>(); }
@Override public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) { }
@Override public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) { Timber.e("播放: onPlaybackParametersChanged "); }
@Override public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) { // Do nothing. }
/** * Initializes the player. */ public void Initialize(final BA ba, String EventName) { eventName = EventName.toLowerCase(BA.cul); BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); player = ExoPlayerFactory.newSimpleInstance(BA.applicationContext, trackSelector); player.addListener(new Player.EventListener() { @Override public void onLoadingChanged(boolean isLoading) { } @Override public void onPlayerError(ExoPlaybackException error) { ba.raiseEvent(SimpleExoPlayerWrapper.this, eventName + "_error", String.valueOf(error.getCause())); } @Override public void onPlayerStateChanged(boolean playWhenReady, int playbackState) { if (playbackState != currentState) { currentState = playbackState; if (currentState == Player.STATE_ENDED) ba.raiseEvent(SimpleExoPlayerWrapper.this, eventName + "_complete"); else if (currentState == Player.STATE_READY) ba.raiseEvent(SimpleExoPlayerWrapper.this, eventName + "_ready"); } } @Override public void onPositionDiscontinuity() { } @Override public void onTimelineChanged(Timeline timeline, Object manifest) { } @Override public void onPlaybackParametersChanged( PlaybackParameters playbackParameters) { // TODO Auto-generated method stub } @Override public void onRepeatModeChanged(int repeatMode) { } @Override public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) { ba.raiseEventFromUI(SimpleExoPlayerWrapper.this, eventName + "_trackchanged"); } }); }
/** * Creates a new standalone media clock. */ public StandaloneMediaClock() { playbackParameters = PlaybackParameters.DEFAULT; }
@Override public PlaybackParameters getPlaybackParameters() { return playbackParameters; }
@Override public PlaybackParameters setPlaybackParameters(PlaybackParameters playbackParameters) { return audioTrack.setPlaybackParameters(playbackParameters); }
@Override public PlaybackParameters getPlaybackParameters() { return audioTrack.getPlaybackParameters(); }
/** * Gets the {@link PlaybackParameters}. */ public PlaybackParameters getPlaybackParameters() { return playbackParameters; }
private PlaybackParametersCheckpoint(PlaybackParameters playbackParameters, long mediaTimeUs, long positionUs) { this.playbackParameters = playbackParameters; this.mediaTimeUs = mediaTimeUs; this.positionUs = positionUs; }
@Override public void setPlaybackParams(PlaybackParameters playbackParams) { if (mCallback != null) mCallback.onPlaybackStatusChanged(mState); }
@Override public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) { Log.d(TAG, "playbackParameters " + String.format( "[speed=%.2f, pitch=%.2f]", playbackParameters.speed, playbackParameters.pitch)); }
@Override public void setPlaybackParameters(PlaybackParameters playbackParameters) { player.setPlaybackParameters(playbackParameters); }
@Override public PlaybackParameters getPlaybackParameters() { return player.getPlaybackParameters(); }
@Override public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) { // Nothing to do. }
@Override public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) { // TODO: should we send? }
@Override public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) { for (Player.EventListener listener : listeners) { listener.onPlaybackParametersChanged(playbackParameters); } }
@Override public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) {}