Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ ext {
androidxRoomVersion = '2.3.0-alpha03'

icepickVersion = '3.2.0'
exoPlayerVersion = '2.12.3'
exoPlayerVersion = '2.11.8'
googleAutoServiceVersion = '1.0-rc7'
groupieVersion = '2.8.1'
markwonVersion = '4.6.0'
Expand Down
28 changes: 11 additions & 17 deletions app/src/main/java/org/schabi/newpipe/player/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -614,8 +614,7 @@ public void handleIntent(@NonNull final Intent intent) {
final PlaybackParameters savedParameters = retrievePlaybackParametersFromPrefs(this);
final float playbackSpeed = savedParameters.speed;
final float playbackPitch = savedParameters.pitch;
final boolean playbackSkipSilence = getPrefs().getBoolean(getContext().getString(
R.string.playback_skip_silence_key), getPlaybackSkipSilence());
final boolean playbackSkipSilence = savedParameters.skipSilence;

final boolean samePlayQueue = playQueue != null && playQueue.equals(newQueue);
final int repeatMode = intent.getIntExtra(REPEAT_MODE, getRepeatMode());
Expand All @@ -640,7 +639,7 @@ public void handleIntent(@NonNull final Intent intent) {
// and we should retry in this case
if (simpleExoPlayer.getPlaybackState()
== com.google.android.exoplayer2.Player.STATE_IDLE) {
simpleExoPlayer.prepare();
simpleExoPlayer.retry();
}
simpleExoPlayer.seekTo(playQueue.getIndex(), newQueue.getItem().getRecoveryPosition());
simpleExoPlayer.setPlayWhenReady(playWhenReady);
Expand All @@ -654,7 +653,7 @@ public void handleIntent(@NonNull final Intent intent) {
// and we should retry in this case
if (simpleExoPlayer.getPlaybackState()
== com.google.android.exoplayer2.Player.STATE_IDLE) {
simpleExoPlayer.prepare();
simpleExoPlayer.retry();
}
simpleExoPlayer.setPlayWhenReady(playWhenReady);

Expand Down Expand Up @@ -1531,8 +1530,7 @@ public float getPlaybackPitch() {
}

public boolean getPlaybackSkipSilence() {
return !exoPlayerIsNull() && simpleExoPlayer.getAudioComponent() != null
&& simpleExoPlayer.getAudioComponent().getSkipSilenceEnabled();
return getPlaybackParameters().skipSilence;
}

public PlaybackParameters getPlaybackParameters() {
Expand All @@ -1557,10 +1555,7 @@ public void setPlaybackParameters(final float speed, final float pitch,

savePlaybackParametersToPrefs(this, roundedSpeed, roundedPitch, skipSilence);
simpleExoPlayer.setPlaybackParameters(
new PlaybackParameters(roundedSpeed, roundedPitch));
if (simpleExoPlayer.getAudioComponent() != null) {
simpleExoPlayer.getAudioComponent().setSkipSilenceEnabled(skipSilence);
}
new PlaybackParameters(roundedSpeed, roundedPitch, skipSilence));
}
//endregion

Expand Down Expand Up @@ -1684,7 +1679,7 @@ public void onStartTrackingTouch(final SeekBar seekBar) {

saveWasPlaying();
if (isPlaying()) {
simpleExoPlayer.pause();
simpleExoPlayer.setPlayWhenReady(false);
}

showControls(0);
Expand All @@ -1700,7 +1695,7 @@ public void onStopTrackingTouch(final SeekBar seekBar) {

seekTo(seekBar.getProgress());
if (wasPlaying || simpleExoPlayer.getDuration() == seekBar.getProgress()) {
simpleExoPlayer.play();
simpleExoPlayer.setPlayWhenReady(true);
}

binding.playbackCurrentTime.setText(getTimeString(seekBar.getProgress()));
Expand Down Expand Up @@ -1943,7 +1938,7 @@ public void onPlayerStateChanged(final boolean playWhenReady, final int playback
}

@Override // exoplayer listener
public void onIsLoadingChanged(final boolean isLoading) {
public void onLoadingChanged(final boolean isLoading) {
if (DEBUG) {
Log.d(TAG, "ExoPlayer - onLoadingChanged() called with: "
+ "isLoading = [" + isLoading + "]");
Expand Down Expand Up @@ -1987,8 +1982,7 @@ public void onPlaybackUnblock(final MediaSource mediaSource) {
if (currentState == STATE_BLOCKED) {
changeState(STATE_BUFFERING);
}
simpleExoPlayer.setMediaSource(mediaSource);
simpleExoPlayer.prepare();
simpleExoPlayer.prepare(mediaSource);
}

public void changeState(final int state) {
Expand Down Expand Up @@ -2691,7 +2685,7 @@ public void play() {
}
}

simpleExoPlayer.play();
simpleExoPlayer.setPlayWhenReady(true);
saveStreamProgressState();
}

Expand All @@ -2704,7 +2698,7 @@ public void pause() {
}

audioReactor.abandonAudioFocus();
simpleExoPlayer.pause();
simpleExoPlayer.setPlayWhenReady(false);
saveStreamProgressState();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ private void onAudioFocusGain() {
animateAudio(DUCK_AUDIO_TO, 1.0f);

if (PlayerHelper.isResumeAfterAudioFocusGain(context)) {
player.play();
player.setPlayWhenReady(true);
}
}

private void onAudioFocusLoss() {
Log.d(TAG, "onAudioFocusLoss() called");
player.pause();
player.setPlayWhenReady(false);
}

private void onAudioFocusLossCanDuck() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private LoadController(final int initialPlaybackBufferMs,
builder.setBufferDurationsMs(minimumPlaybackBufferMs, optimalPlaybackBufferMs,
initialPlaybackBufferMs,
DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS);
internalLoadControl = builder.build();
internalLoadControl = builder.createDefaultLoadControl();
}

/*//////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -81,14 +81,13 @@ public boolean retainBackBufferFromKeyframe() {
}

@Override
public boolean shouldContinueLoading(final long playbackPositionUs,
final long bufferedDurationUs,
public boolean shouldContinueLoading(final long bufferedDurationUs,
final float playbackSpeed) {
if (!preloadingEnabled) {
return false;
}
return internalLoadControl.shouldContinueLoading(
playbackPositionUs, bufferedDurationUs, playbackSpeed);
bufferedDurationUs, playbackSpeed);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,9 @@ public static PlaybackParameters retrievePlaybackParametersFromPrefs(final Playe
R.string.playback_speed_key), player.getPlaybackSpeed());
final float pitch = player.getPrefs().getFloat(player.getContext().getString(
R.string.playback_pitch_key), player.getPlaybackPitch());
return new PlaybackParameters(speed, pitch);
final boolean skipSilence = player.getPrefs().getBoolean(player.getContext().getString(
R.string.playback_skip_silence_key), player.getPlaybackSkipSilence());
return new PlaybackParameters(speed, pitch, skipSilence);
}

public static void savePlaybackParametersToPrefs(final Player player,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.source.BaseMediaSource;
import com.google.android.exoplayer2.source.MediaPeriod;
import com.google.android.exoplayer2.upstream.Allocator;
Expand Down Expand Up @@ -55,14 +54,6 @@ private boolean canRetry() {
return System.currentTimeMillis() >= retryTimestamp;
}

/**
* Returns the {@link MediaItem} whose media is provided by the source.
*/
@Override
public MediaItem getMediaItem() {
return MediaItem.fromUri(playQueueItem.getUrl());
}

@Override
public void maybeThrowSourceInfoRefreshError() throws IOException {
throw new IOException(error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.drm.DrmSessionEventListener;
import com.google.android.exoplayer2.source.MediaPeriod;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.MediaSourceEventListener;
Expand Down Expand Up @@ -85,38 +83,6 @@ public void removeEventListener(final MediaSourceEventListener eventListener) {
source.removeEventListener(eventListener);
}

/**
* Adds a {@link DrmSessionEventListener} to the list of listeners which are notified of DRM
* events for this media source.
*
* @param handler A handler on the which listener events will be posted.
* @param eventListener The listener to be added.
*/
@Override
public void addDrmEventListener(final Handler handler,
final DrmSessionEventListener eventListener) {
source.addDrmEventListener(handler, eventListener);
}

/**
* Removes a {@link DrmSessionEventListener} from the list of listeners which are notified of
* DRM events for this media source.
*
* @param eventListener The listener to be removed.
*/
@Override
public void removeDrmEventListener(final DrmSessionEventListener eventListener) {
source.removeDrmEventListener(eventListener);
}

/**
* Returns the {@link MediaItem} whose media is provided by the source.
*/
@Override
public MediaItem getMediaItem() {
return source.getMediaItem();
}

@Override
public boolean shouldBeReplacedWith(@NonNull final PlayQueueItem newIdentity,
final boolean isInterruptable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.source.BaseMediaSource;
import com.google.android.exoplayer2.source.MediaPeriod;
import com.google.android.exoplayer2.upstream.Allocator;
Expand All @@ -12,14 +11,6 @@
import org.schabi.newpipe.player.playqueue.PlayQueueItem;

public class PlaceholderMediaSource extends BaseMediaSource implements ManagedMediaSource {
/**
* Returns the {@link MediaItem} whose media is provided by the source.
*/
@Override
public MediaItem getMediaItem() {
return null;
}

// Do nothing, so this will stall the playback
@Override
public void maybeThrowSourceInfoRefreshError() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import androidx.annotation.Nullable;

import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.util.Util;

Expand Down Expand Up @@ -44,13 +43,13 @@ default MediaSource buildLiveMediaSource(@NonNull final PlayerDataSource dataSou
switch (type) {
case C.TYPE_SS:
return dataSource.getLiveSsMediaSourceFactory().setTag(metadata)
.createMediaSource(MediaItem.fromUri(uri));
.createMediaSource(uri);
case C.TYPE_DASH:
return dataSource.getLiveDashMediaSourceFactory().setTag(metadata)
.createMediaSource(MediaItem.fromUri(uri));
.createMediaSource(uri);
case C.TYPE_HLS:
return dataSource.getLiveHlsMediaSourceFactory().setTag(metadata)
.createMediaSource(MediaItem.fromUri(uri));
.createMediaSource(uri);
default:
throw new IllegalStateException("Unsupported type: " + type);
}
Expand All @@ -69,16 +68,16 @@ default MediaSource buildMediaSource(@NonNull final PlayerDataSource dataSource,
switch (type) {
case C.TYPE_SS:
return dataSource.getLiveSsMediaSourceFactory().setTag(metadata)
.createMediaSource(MediaItem.fromUri(uri));
.createMediaSource(uri);
case C.TYPE_DASH:
return dataSource.getDashMediaSourceFactory().setTag(metadata)
.createMediaSource(MediaItem.fromUri(uri));
.createMediaSource(uri);
case C.TYPE_HLS:
return dataSource.getHlsMediaSourceFactory().setTag(metadata)
.createMediaSource(MediaItem.fromUri(uri));
.createMediaSource(uri);
case C.TYPE_OTHER:
return dataSource.getExtractorMediaSourceFactory(cacheKey).setTag(metadata)
.createMediaSource(MediaItem.fromUri(uri));
.createMediaSource(uri);
default:
throw new IllegalStateException("Unsupported type: " + type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.MergingMediaSource;

Expand All @@ -22,6 +22,7 @@
import java.util.ArrayList;
import java.util.List;

import static com.google.android.exoplayer2.C.SELECTION_FLAG_AUTOSELECT;
import static com.google.android.exoplayer2.C.TIME_UNSET;

public class VideoPlaybackResolver implements PlaybackResolver {
Expand Down Expand Up @@ -100,12 +101,11 @@ public MediaSource resolve(@NonNull final StreamInfo info) {
if (mimeType == null) {
continue;
}
final Format textFormat = Format.createTextSampleFormat(null, mimeType,
SELECTION_FLAG_AUTOSELECT,
PlayerHelper.captionLanguageOf(context, subtitle));
final MediaSource textSource = dataSource.getSampleMediaSourceFactory()
.createMediaSource(
new MediaItem.Subtitle(Uri.parse(subtitle.getUrl()),
mimeType,
PlayerHelper.captionLanguageOf(context, subtitle)),
TIME_UNSET);
.createMediaSource(Uri.parse(subtitle.getUrl()), textFormat, TIME_UNSET);
mediaSources.add(textSource);
}
}
Expand Down