1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-24 00:50:32 +00:00

-Updated ExoPlayer to 2.8.0

-Updated MediaSource contracts in ManagedMediaSource.
-Changed PlaceholderMediaSource and FailedMediaSource to use built-in BaseMediaSource implementation.
-Changed deprecated DynamicConcatenatingMediaSource to ConcatenatingMediaSource.
-Removed manual playlist media source disposal in favor of player built-in disposal.
This commit is contained in:
John Zhen Mo 2018-05-08 10:18:32 -07:00
parent f563bc4210
commit 7721098551
7 changed files with 46 additions and 40 deletions

View File

@ -42,7 +42,7 @@ android {
ext { ext {
supportLibVersion = '27.1.1' supportLibVersion = '27.1.1'
exoPlayerLibVersion = '2.7.3' exoPlayerLibVersion = '2.8.0'
roomDbLibVersion = '1.1.1' roomDbLibVersion = '1.1.1'
leakCanaryLibVersion = '1.5.4' leakCanaryLibVersion = '1.5.4'
okHttpLibVersion = '3.10.0' okHttpLibVersion = '3.10.0'

View File

@ -241,7 +241,6 @@ public class PlayerHelper {
public static TrackSelection.Factory getQualitySelector(@NonNull final Context context, public static TrackSelection.Factory getQualitySelector(@NonNull final Context context,
@NonNull final BandwidthMeter meter) { @NonNull final BandwidthMeter meter) {
return new AdaptiveTrackSelection.Factory(meter, return new AdaptiveTrackSelection.Factory(meter,
AdaptiveTrackSelection.DEFAULT_MAX_INITIAL_BITRATE,
/*bufferDurationRequiredForQualityIncrease=*/1000, /*bufferDurationRequiredForQualityIncrease=*/1000,
AdaptiveTrackSelection.DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS, AdaptiveTrackSelection.DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS,
AdaptiveTrackSelection.DEFAULT_MIN_DURATION_TO_RETAIN_AFTER_DISCARD_MS, AdaptiveTrackSelection.DEFAULT_MIN_DURATION_TO_RETAIN_AFTER_DISCARD_MS,

View File

@ -4,6 +4,7 @@ import android.support.annotation.NonNull;
import android.util.Log; import android.util.Log;
import com.google.android.exoplayer2.ExoPlayer; import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.source.BaseMediaSource;
import com.google.android.exoplayer2.source.MediaPeriod; import com.google.android.exoplayer2.source.MediaPeriod;
import com.google.android.exoplayer2.upstream.Allocator; import com.google.android.exoplayer2.upstream.Allocator;
@ -11,7 +12,7 @@ import org.schabi.newpipe.player.playqueue.PlayQueueItem;
import java.io.IOException; import java.io.IOException;
public class FailedMediaSource implements ManagedMediaSource { public class FailedMediaSource extends BaseMediaSource implements ManagedMediaSource {
private final String TAG = "FailedMediaSource@" + Integer.toHexString(hashCode()); private final String TAG = "FailedMediaSource@" + Integer.toHexString(hashCode());
public static class FailedMediaSourceException extends Exception { public static class FailedMediaSourceException extends Exception {
@ -72,11 +73,6 @@ public class FailedMediaSource implements ManagedMediaSource {
return System.currentTimeMillis() >= retryTimestamp; return System.currentTimeMillis() >= retryTimestamp;
} }
@Override
public void prepareSource(ExoPlayer player, boolean isTopLevelSource, Listener listener) {
Log.e(TAG, "Loading failed source: ", error);
}
@Override @Override
public void maybeThrowSourceInfoRefreshError() throws IOException { public void maybeThrowSourceInfoRefreshError() throws IOException {
throw new IOException(error); throw new IOException(error);
@ -90,8 +86,14 @@ public class FailedMediaSource implements ManagedMediaSource {
@Override @Override
public void releasePeriod(MediaPeriod mediaPeriod) {} public void releasePeriod(MediaPeriod mediaPeriod) {}
@Override @Override
public void releaseSource() {} protected void prepareSourceInternal(ExoPlayer player, boolean isTopLevelSource) {
Log.e(TAG, "Loading failed source: ", error);
}
@Override
protected void releaseSourceInternal() {}
@Override @Override
public boolean shouldBeReplacedWith(@NonNull final PlayQueueItem newIdentity, public boolean shouldBeReplacedWith(@NonNull final PlayQueueItem newIdentity,

View File

@ -1,10 +1,12 @@
package org.schabi.newpipe.player.mediasource; package org.schabi.newpipe.player.mediasource;
import android.os.Handler;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import com.google.android.exoplayer2.ExoPlayer; import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.source.MediaPeriod; import com.google.android.exoplayer2.source.MediaPeriod;
import com.google.android.exoplayer2.source.MediaSource; import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.MediaSourceEventListener;
import com.google.android.exoplayer2.upstream.Allocator; import com.google.android.exoplayer2.upstream.Allocator;
import org.schabi.newpipe.player.playqueue.PlayQueueItem; import org.schabi.newpipe.player.playqueue.PlayQueueItem;
@ -34,7 +36,8 @@ public class LoadedMediaSource implements ManagedMediaSource {
} }
@Override @Override
public void prepareSource(ExoPlayer player, boolean isTopLevelSource, Listener listener) { public void prepareSource(ExoPlayer player, boolean isTopLevelSource,
SourceInfoRefreshListener listener) {
source.prepareSource(player, isTopLevelSource, listener); source.prepareSource(player, isTopLevelSource, listener);
} }
@ -54,8 +57,18 @@ public class LoadedMediaSource implements ManagedMediaSource {
} }
@Override @Override
public void releaseSource() { public void releaseSource(SourceInfoRefreshListener listener) {
source.releaseSource(); source.releaseSource(listener);
}
@Override
public void addEventListener(Handler handler, MediaSourceEventListener eventListener) {
source.addEventListener(handler, eventListener);
}
@Override
public void removeEventListener(MediaSourceEventListener eventListener) {
source.removeEventListener(eventListener);
} }
@Override @Override

View File

@ -3,14 +3,14 @@ package org.schabi.newpipe.player.mediasource;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import com.google.android.exoplayer2.source.DynamicConcatenatingMediaSource; import com.google.android.exoplayer2.source.ConcatenatingMediaSource;
import com.google.android.exoplayer2.source.ShuffleOrder; import com.google.android.exoplayer2.source.ShuffleOrder;
public class ManagedMediaSourcePlaylist { public class ManagedMediaSourcePlaylist {
@NonNull private final DynamicConcatenatingMediaSource internalSource; @NonNull private final ConcatenatingMediaSource internalSource;
public ManagedMediaSourcePlaylist() { public ManagedMediaSourcePlaylist() {
internalSource = new DynamicConcatenatingMediaSource(/*isPlaylistAtomic=*/false, internalSource = new ConcatenatingMediaSource(/*isPlaylistAtomic=*/false,
new ShuffleOrder.UnshuffledShuffleOrder(0)); new ShuffleOrder.UnshuffledShuffleOrder(0));
} }
@ -32,12 +32,8 @@ public class ManagedMediaSourcePlaylist {
null : (ManagedMediaSource) internalSource.getMediaSource(index); null : (ManagedMediaSource) internalSource.getMediaSource(index);
} }
public void dispose() {
internalSource.releaseSource();
}
@NonNull @NonNull
public DynamicConcatenatingMediaSource getParentMediaSource() { public ConcatenatingMediaSource getParentMediaSource() {
return internalSource; return internalSource;
} }
@ -46,7 +42,7 @@ public class ManagedMediaSourcePlaylist {
//////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////*/
/** /**
* Expands the {@link DynamicConcatenatingMediaSource} by appending it with a * Expands the {@link ConcatenatingMediaSource} by appending it with a
* {@link PlaceholderMediaSource}. * {@link PlaceholderMediaSource}.
* *
* @see #append(ManagedMediaSource) * @see #append(ManagedMediaSource)
@ -56,17 +52,17 @@ public class ManagedMediaSourcePlaylist {
} }
/** /**
* Appends a {@link ManagedMediaSource} to the end of {@link DynamicConcatenatingMediaSource}. * Appends a {@link ManagedMediaSource} to the end of {@link ConcatenatingMediaSource}.
* @see DynamicConcatenatingMediaSource#addMediaSource * @see ConcatenatingMediaSource#addMediaSource
* */ * */
public synchronized void append(@NonNull final ManagedMediaSource source) { public synchronized void append(@NonNull final ManagedMediaSource source) {
internalSource.addMediaSource(source); internalSource.addMediaSource(source);
} }
/** /**
* Removes a {@link ManagedMediaSource} from {@link DynamicConcatenatingMediaSource} * Removes a {@link ManagedMediaSource} from {@link ConcatenatingMediaSource}
* at the given index. If this index is out of bound, then the removal is ignored. * at the given index. If this index is out of bound, then the removal is ignored.
* @see DynamicConcatenatingMediaSource#removeMediaSource(int) * @see ConcatenatingMediaSource#removeMediaSource(int)
* */ * */
public synchronized void remove(final int index) { public synchronized void remove(final int index) {
if (index < 0 || index > internalSource.getSize()) return; if (index < 0 || index > internalSource.getSize()) return;
@ -75,10 +71,10 @@ public class ManagedMediaSourcePlaylist {
} }
/** /**
* Moves a {@link ManagedMediaSource} in {@link DynamicConcatenatingMediaSource} * Moves a {@link ManagedMediaSource} in {@link ConcatenatingMediaSource}
* from the given source index to the target index. If either index is out of bound, * from the given source index to the target index. If either index is out of bound,
* then the call is ignored. * then the call is ignored.
* @see DynamicConcatenatingMediaSource#moveMediaSource(int, int) * @see ConcatenatingMediaSource#moveMediaSource(int, int)
* */ * */
public synchronized void move(final int source, final int target) { public synchronized void move(final int source, final int target) {
if (source < 0 || target < 0) return; if (source < 0 || target < 0) return;
@ -99,7 +95,7 @@ public class ManagedMediaSourcePlaylist {
} }
/** /**
* Updates the {@link ManagedMediaSource} in {@link DynamicConcatenatingMediaSource} * Updates the {@link ManagedMediaSource} in {@link ConcatenatingMediaSource}
* at the given index with a given {@link ManagedMediaSource}. * at the given index with a given {@link ManagedMediaSource}.
* @see #update(int, ManagedMediaSource, Runnable) * @see #update(int, ManagedMediaSource, Runnable)
* */ * */
@ -108,11 +104,11 @@ public class ManagedMediaSourcePlaylist {
} }
/** /**
* Updates the {@link ManagedMediaSource} in {@link DynamicConcatenatingMediaSource} * Updates the {@link ManagedMediaSource} in {@link ConcatenatingMediaSource}
* at the given index with a given {@link ManagedMediaSource}. If the index is out of bound, * at the given index with a given {@link ManagedMediaSource}. If the index is out of bound,
* then the replacement is ignored. * then the replacement is ignored.
* @see DynamicConcatenatingMediaSource#addMediaSource * @see ConcatenatingMediaSource#addMediaSource
* @see DynamicConcatenatingMediaSource#removeMediaSource(int, Runnable) * @see ConcatenatingMediaSource#removeMediaSource(int, Runnable)
* */ * */
public synchronized void update(final int index, @NonNull final ManagedMediaSource source, public synchronized void update(final int index, @NonNull final ManagedMediaSource source,
@Nullable final Runnable finalizingAction) { @Nullable final Runnable finalizingAction) {

View File

@ -3,20 +3,19 @@ package org.schabi.newpipe.player.mediasource;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import com.google.android.exoplayer2.ExoPlayer; import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.source.BaseMediaSource;
import com.google.android.exoplayer2.source.MediaPeriod; import com.google.android.exoplayer2.source.MediaPeriod;
import com.google.android.exoplayer2.upstream.Allocator; import com.google.android.exoplayer2.upstream.Allocator;
import org.schabi.newpipe.player.playqueue.PlayQueueItem; import org.schabi.newpipe.player.playqueue.PlayQueueItem;
import java.io.IOException; public class PlaceholderMediaSource extends BaseMediaSource implements ManagedMediaSource {
public class PlaceholderMediaSource implements ManagedMediaSource {
// Do nothing, so this will stall the playback // Do nothing, so this will stall the playback
@Override public void prepareSource(ExoPlayer player, boolean isTopLevelSource, Listener listener) {} @Override public void maybeThrowSourceInfoRefreshError() {}
@Override public void maybeThrowSourceInfoRefreshError() throws IOException {}
@Override public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator) { return null; } @Override public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator) { return null; }
@Override public void releasePeriod(MediaPeriod mediaPeriod) {} @Override public void releasePeriod(MediaPeriod mediaPeriod) {}
@Override public void releaseSource() {} @Override protected void prepareSourceInternal(ExoPlayer player, boolean isTopLevelSource) {}
@Override protected void releaseSourceInternal() {}
@Override @Override
public boolean shouldBeReplacedWith(@NonNull PlayQueueItem newIdentity, public boolean shouldBeReplacedWith(@NonNull PlayQueueItem newIdentity,

View File

@ -172,7 +172,6 @@ public class MediaSourceManager {
playQueueReactor.cancel(); playQueueReactor.cancel();
loaderReactor.dispose(); loaderReactor.dispose();
syncReactor.dispose(); syncReactor.dispose();
playlist.dispose();
} }
/*////////////////////////////////////////////////////////////////////////// /*//////////////////////////////////////////////////////////////////////////
@ -481,8 +480,6 @@ public class MediaSourceManager {
private void resetSources() { private void resetSources() {
if (DEBUG) Log.d(TAG, "resetSources() called."); if (DEBUG) Log.d(TAG, "resetSources() called.");
playlist.dispose();
playlist = new ManagedMediaSourcePlaylist(); playlist = new ManagedMediaSourcePlaylist();
} }