Merge pull request #1392 from karyogamy/exoplayer-2.8.0-update
ExoPlayer 2.8.2 Update
This commit is contained in:
commit
6b66f40bcb
29 changed files with 1043 additions and 644 deletions
|
@ -42,7 +42,7 @@ android {
|
||||||
|
|
||||||
ext {
|
ext {
|
||||||
supportLibVersion = '27.1.1'
|
supportLibVersion = '27.1.1'
|
||||||
exoPlayerLibVersion = '2.7.3'
|
exoPlayerLibVersion = '2.8.2'
|
||||||
roomDbLibVersion = '1.1.1'
|
roomDbLibVersion = '1.1.1'
|
||||||
leakCanaryLibVersion = '1.5.4'
|
leakCanaryLibVersion = '1.5.4'
|
||||||
okHttpLibVersion = '3.10.0'
|
okHttpLibVersion = '3.10.0'
|
||||||
|
|
|
@ -26,9 +26,7 @@ import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.os.Build;
|
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.support.annotation.IntRange;
|
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.app.NotificationCompat;
|
import android.support.v4.app.NotificationCompat;
|
||||||
|
@ -39,17 +37,16 @@ import android.widget.RemoteViews;
|
||||||
import com.google.android.exoplayer2.PlaybackParameters;
|
import com.google.android.exoplayer2.PlaybackParameters;
|
||||||
import com.google.android.exoplayer2.Player;
|
import com.google.android.exoplayer2.Player;
|
||||||
import com.google.android.exoplayer2.source.MediaSource;
|
import com.google.android.exoplayer2.source.MediaSource;
|
||||||
|
import com.nostra13.universalimageloader.core.assist.FailReason;
|
||||||
|
|
||||||
import org.schabi.newpipe.BuildConfig;
|
import org.schabi.newpipe.BuildConfig;
|
||||||
import org.schabi.newpipe.R;
|
import org.schabi.newpipe.R;
|
||||||
import org.schabi.newpipe.extractor.MediaFormat;
|
|
||||||
import org.schabi.newpipe.extractor.stream.AudioStream;
|
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
||||||
import org.schabi.newpipe.player.event.PlayerEventListener;
|
import org.schabi.newpipe.player.event.PlayerEventListener;
|
||||||
import org.schabi.newpipe.player.helper.LockManager;
|
import org.schabi.newpipe.player.helper.LockManager;
|
||||||
import org.schabi.newpipe.player.helper.PlayerHelper;
|
|
||||||
import org.schabi.newpipe.player.playqueue.PlayQueueItem;
|
import org.schabi.newpipe.player.playqueue.PlayQueueItem;
|
||||||
import org.schabi.newpipe.util.ListHelper;
|
import org.schabi.newpipe.player.resolver.AudioPlaybackResolver;
|
||||||
|
import org.schabi.newpipe.player.resolver.MediaSourceTag;
|
||||||
import org.schabi.newpipe.util.NavigationHelper;
|
import org.schabi.newpipe.util.NavigationHelper;
|
||||||
import org.schabi.newpipe.util.ThemeHelper;
|
import org.schabi.newpipe.util.ThemeHelper;
|
||||||
|
|
||||||
|
@ -94,7 +91,6 @@ public final class BackgroundPlayer extends Service {
|
||||||
private NotificationCompat.Builder notBuilder;
|
private NotificationCompat.Builder notBuilder;
|
||||||
private RemoteViews notRemoteView;
|
private RemoteViews notRemoteView;
|
||||||
private RemoteViews bigNotRemoteView;
|
private RemoteViews bigNotRemoteView;
|
||||||
private final String setAlphaMethodName = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) ? "setImageAlpha" : "setAlpha";
|
|
||||||
|
|
||||||
private boolean shouldUpdateOnProgress;
|
private boolean shouldUpdateOnProgress;
|
||||||
|
|
||||||
|
@ -192,7 +188,9 @@ public final class BackgroundPlayer extends Service {
|
||||||
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
||||||
.setCustomContentView(notRemoteView)
|
.setCustomContentView(notRemoteView)
|
||||||
.setCustomBigContentView(bigNotRemoteView);
|
.setCustomBigContentView(bigNotRemoteView);
|
||||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) builder.setPriority(NotificationCompat.PRIORITY_MAX);
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
|
||||||
|
builder.setPriority(NotificationCompat.PRIORITY_MAX);
|
||||||
|
}
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,15 +247,6 @@ public final class BackgroundPlayer extends Service {
|
||||||
notificationManager.notify(NOTIFICATION_ID, notBuilder.build());
|
notificationManager.notify(NOTIFICATION_ID, notBuilder.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setControlsOpacity(@IntRange(from = 0, to = 255) int opacity) {
|
|
||||||
if (notRemoteView != null) notRemoteView.setInt(R.id.notificationPlayPause, setAlphaMethodName, opacity);
|
|
||||||
if (bigNotRemoteView != null) bigNotRemoteView.setInt(R.id.notificationPlayPause, setAlphaMethodName, opacity);
|
|
||||||
if (notRemoteView != null) notRemoteView.setInt(R.id.notificationFForward, setAlphaMethodName, opacity);
|
|
||||||
if (bigNotRemoteView != null) bigNotRemoteView.setInt(R.id.notificationFForward, setAlphaMethodName, opacity);
|
|
||||||
if (notRemoteView != null) notRemoteView.setInt(R.id.notificationFRewind, setAlphaMethodName, opacity);
|
|
||||||
if (bigNotRemoteView != null) bigNotRemoteView.setInt(R.id.notificationFRewind, setAlphaMethodName, opacity);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
// Utils
|
// Utils
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
@ -279,8 +268,16 @@ public final class BackgroundPlayer extends Service {
|
||||||
|
|
||||||
protected class BasePlayerImpl extends BasePlayer {
|
protected class BasePlayerImpl extends BasePlayer {
|
||||||
|
|
||||||
|
@NonNull final private AudioPlaybackResolver resolver;
|
||||||
|
|
||||||
BasePlayerImpl(Context context) {
|
BasePlayerImpl(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
|
this.resolver = new AudioPlaybackResolver(context, dataSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initPlayer(boolean playOnReady) {
|
||||||
|
super.initPlayer(playOnReady);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -293,29 +290,40 @@ public final class BackgroundPlayer extends Service {
|
||||||
startForeground(NOTIFICATION_ID, notBuilder.build());
|
startForeground(NOTIFICATION_ID, notBuilder.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
public void initThumbnail(final String url) {
|
// Thumbnail Loading
|
||||||
resetNotification();
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
if (notRemoteView != null) notRemoteView.setImageViewResource(R.id.notificationCover, R.drawable.dummy_thumbnail);
|
|
||||||
if (bigNotRemoteView != null) bigNotRemoteView.setImageViewResource(R.id.notificationCover, R.drawable.dummy_thumbnail);
|
private void updateNotificationThumbnail() {
|
||||||
updateNotification(-1);
|
if (basePlayerImpl == null) return;
|
||||||
super.initThumbnail(url);
|
if (notRemoteView != null) {
|
||||||
|
notRemoteView.setImageViewBitmap(R.id.notificationCover,
|
||||||
|
basePlayerImpl.getThumbnail());
|
||||||
|
}
|
||||||
|
if (bigNotRemoteView != null) {
|
||||||
|
bigNotRemoteView.setImageViewBitmap(R.id.notificationCover,
|
||||||
|
basePlayerImpl.getThumbnail());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
|
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
|
||||||
super.onLoadingComplete(imageUri, view, loadedImage);
|
super.onLoadingComplete(imageUri, view, loadedImage);
|
||||||
|
|
||||||
if (loadedImage != null) {
|
|
||||||
// rebuild notification here since remote view does not release bitmaps, causing memory leaks
|
|
||||||
resetNotification();
|
resetNotification();
|
||||||
|
updateNotificationThumbnail();
|
||||||
if (notRemoteView != null) notRemoteView.setImageViewBitmap(R.id.notificationCover, loadedImage);
|
|
||||||
if (bigNotRemoteView != null) bigNotRemoteView.setImageViewBitmap(R.id.notificationCover, loadedImage);
|
|
||||||
|
|
||||||
updateNotification(-1);
|
updateNotification(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
|
||||||
|
super.onLoadingFailed(imageUri, view, failReason);
|
||||||
|
resetNotification();
|
||||||
|
updateNotificationThumbnail();
|
||||||
|
updateNotification(-1);
|
||||||
}
|
}
|
||||||
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
// States Implementation
|
||||||
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPrepared(boolean playWhenReady) {
|
public void onPrepared(boolean playWhenReady) {
|
||||||
|
@ -390,29 +398,18 @@ public final class BackgroundPlayer extends Service {
|
||||||
// Playback Listener
|
// Playback Listener
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
protected void onMetadataChanged(@NonNull final PlayQueueItem item,
|
protected void onMetadataChanged(@NonNull final MediaSourceTag tag) {
|
||||||
@Nullable final StreamInfo info,
|
super.onMetadataChanged(tag);
|
||||||
final int newPlayQueueIndex,
|
|
||||||
final boolean hasPlayQueueItemChanged) {
|
|
||||||
if (shouldUpdateOnProgress || hasPlayQueueItemChanged) {
|
|
||||||
resetNotification();
|
resetNotification();
|
||||||
|
updateNotificationThumbnail();
|
||||||
updateNotification(-1);
|
updateNotification(-1);
|
||||||
updateMetadata();
|
updateMetadata();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public MediaSource sourceOf(final PlayQueueItem item, final StreamInfo info) {
|
public MediaSource sourceOf(final PlayQueueItem item, final StreamInfo info) {
|
||||||
final MediaSource liveSource = super.sourceOf(item, info);
|
return resolver.resolve(info);
|
||||||
if (liveSource != null) return liveSource;
|
|
||||||
|
|
||||||
final int index = ListHelper.getDefaultAudioFormat(context, info.getAudioStreams());
|
|
||||||
if (index < 0 || index >= info.getAudioStreams().size()) return null;
|
|
||||||
|
|
||||||
final AudioStream audio = info.getAudioStreams().get(index);
|
|
||||||
return buildMediaSource(audio.getUrl(), PlayerHelper.cacheKeyOf(info, audio),
|
|
||||||
MediaFormat.getSuffixById(audio.getFormatId()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -439,8 +436,8 @@ public final class BackgroundPlayer extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateMetadata() {
|
private void updateMetadata() {
|
||||||
if (activityListener != null && currentInfo != null) {
|
if (activityListener != null && getCurrentMetadata() != null) {
|
||||||
activityListener.onMetadataUpdate(currentInfo);
|
activityListener.onMetadataUpdate(getCurrentMetadata().getMetadata());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -531,44 +528,36 @@ public final class BackgroundPlayer extends Service {
|
||||||
updatePlayback();
|
updatePlayback();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBlocked() {
|
|
||||||
super.onBlocked();
|
|
||||||
|
|
||||||
setControlsOpacity(77);
|
|
||||||
updateNotification(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlaying() {
|
public void onPlaying() {
|
||||||
super.onPlaying();
|
super.onPlaying();
|
||||||
|
resetNotification();
|
||||||
setControlsOpacity(255);
|
updateNotificationThumbnail();
|
||||||
updateNotification(R.drawable.ic_pause_white);
|
updateNotification(R.drawable.ic_pause_white);
|
||||||
|
|
||||||
lockManager.acquireWifiAndCpu();
|
lockManager.acquireWifiAndCpu();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPaused() {
|
public void onPaused() {
|
||||||
super.onPaused();
|
super.onPaused();
|
||||||
|
resetNotification();
|
||||||
|
updateNotificationThumbnail();
|
||||||
updateNotification(R.drawable.ic_play_arrow_white);
|
updateNotification(R.drawable.ic_play_arrow_white);
|
||||||
|
|
||||||
lockManager.releaseWifiAndCpu();
|
lockManager.releaseWifiAndCpu();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCompleted() {
|
public void onCompleted() {
|
||||||
super.onCompleted();
|
super.onCompleted();
|
||||||
|
|
||||||
setControlsOpacity(255);
|
|
||||||
|
|
||||||
resetNotification();
|
resetNotification();
|
||||||
if (bigNotRemoteView != null) bigNotRemoteView.setProgressBar(R.id.notificationProgressBar, 100, 100, false);
|
if (bigNotRemoteView != null) {
|
||||||
if (notRemoteView != null) notRemoteView.setProgressBar(R.id.notificationProgressBar, 100, 100, false);
|
bigNotRemoteView.setProgressBar(R.id.notificationProgressBar, 100, 100, false);
|
||||||
|
}
|
||||||
|
if (notRemoteView != null) {
|
||||||
|
notRemoteView.setProgressBar(R.id.notificationProgressBar, 100, 100, false);
|
||||||
|
}
|
||||||
|
updateNotificationThumbnail();
|
||||||
updateNotification(R.drawable.ic_replay_white);
|
updateNotification(R.drawable.ic_replay_white);
|
||||||
|
|
||||||
lockManager.releaseWifiAndCpu();
|
lockManager.releaseWifiAndCpu();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,16 +24,14 @@ import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.net.Uri;
|
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.google.android.exoplayer2.C;
|
|
||||||
import com.google.android.exoplayer2.DefaultRenderersFactory;
|
import com.google.android.exoplayer2.DefaultRenderersFactory;
|
||||||
import com.google.android.exoplayer2.ExoPlaybackException;
|
import com.google.android.exoplayer2.ExoPlaybackException;
|
||||||
import com.google.android.exoplayer2.ExoPlayerFactory;
|
import com.google.android.exoplayer2.ExoPlayerFactory;
|
||||||
|
@ -49,7 +47,6 @@ import com.google.android.exoplayer2.source.TrackGroupArray;
|
||||||
import com.google.android.exoplayer2.trackselection.TrackSelection;
|
import com.google.android.exoplayer2.trackselection.TrackSelection;
|
||||||
import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
|
import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
|
||||||
import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;
|
import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;
|
||||||
import com.google.android.exoplayer2.util.Util;
|
|
||||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||||
import com.nostra13.universalimageloader.core.assist.FailReason;
|
import com.nostra13.universalimageloader.core.assist.FailReason;
|
||||||
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
|
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
|
||||||
|
@ -57,7 +54,6 @@ import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
|
||||||
import org.schabi.newpipe.Downloader;
|
import org.schabi.newpipe.Downloader;
|
||||||
import org.schabi.newpipe.R;
|
import org.schabi.newpipe.R;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamType;
|
|
||||||
import org.schabi.newpipe.local.history.HistoryRecordManager;
|
import org.schabi.newpipe.local.history.HistoryRecordManager;
|
||||||
import org.schabi.newpipe.player.helper.AudioReactor;
|
import org.schabi.newpipe.player.helper.AudioReactor;
|
||||||
import org.schabi.newpipe.player.helper.LoadController;
|
import org.schabi.newpipe.player.helper.LoadController;
|
||||||
|
@ -72,6 +68,8 @@ import org.schabi.newpipe.player.playback.PlaybackListener;
|
||||||
import org.schabi.newpipe.player.playqueue.PlayQueue;
|
import org.schabi.newpipe.player.playqueue.PlayQueue;
|
||||||
import org.schabi.newpipe.player.playqueue.PlayQueueAdapter;
|
import org.schabi.newpipe.player.playqueue.PlayQueueAdapter;
|
||||||
import org.schabi.newpipe.player.playqueue.PlayQueueItem;
|
import org.schabi.newpipe.player.playqueue.PlayQueueItem;
|
||||||
|
import org.schabi.newpipe.player.resolver.MediaSourceTag;
|
||||||
|
import org.schabi.newpipe.util.ImageDisplayConstants;
|
||||||
import org.schabi.newpipe.util.SerializedCache;
|
import org.schabi.newpipe.util.SerializedCache;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -82,12 +80,12 @@ import io.reactivex.Observable;
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
import io.reactivex.disposables.CompositeDisposable;
|
import io.reactivex.disposables.CompositeDisposable;
|
||||||
import io.reactivex.disposables.Disposable;
|
import io.reactivex.disposables.Disposable;
|
||||||
|
import io.reactivex.disposables.SerialDisposable;
|
||||||
|
|
||||||
import static com.google.android.exoplayer2.Player.DISCONTINUITY_REASON_INTERNAL;
|
import static com.google.android.exoplayer2.Player.DISCONTINUITY_REASON_INTERNAL;
|
||||||
import static com.google.android.exoplayer2.Player.DISCONTINUITY_REASON_PERIOD_TRANSITION;
|
import static com.google.android.exoplayer2.Player.DISCONTINUITY_REASON_PERIOD_TRANSITION;
|
||||||
import static com.google.android.exoplayer2.Player.DISCONTINUITY_REASON_SEEK;
|
import static com.google.android.exoplayer2.Player.DISCONTINUITY_REASON_SEEK;
|
||||||
import static com.google.android.exoplayer2.Player.DISCONTINUITY_REASON_SEEK_ADJUSTMENT;
|
import static com.google.android.exoplayer2.Player.DISCONTINUITY_REASON_SEEK_ADJUSTMENT;
|
||||||
import static org.schabi.newpipe.player.helper.PlayerHelper.getTimeString;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base for the players, joining the common properties
|
* Base for the players, joining the common properties
|
||||||
|
@ -108,17 +106,26 @@ public abstract class BasePlayer implements
|
||||||
|
|
||||||
@NonNull final protected HistoryRecordManager recordManager;
|
@NonNull final protected HistoryRecordManager recordManager;
|
||||||
|
|
||||||
|
@NonNull final protected CustomTrackSelector trackSelector;
|
||||||
|
@NonNull final protected PlayerDataSource dataSource;
|
||||||
|
|
||||||
|
@NonNull final private LoadControl loadControl;
|
||||||
|
@NonNull final private RenderersFactory renderFactory;
|
||||||
|
|
||||||
|
@NonNull final private SerialDisposable progressUpdateReactor;
|
||||||
|
@NonNull final private CompositeDisposable databaseUpdateReactor;
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
// Intent
|
// Intent
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
public static final String REPEAT_MODE = "repeat_mode";
|
@NonNull public static final String REPEAT_MODE = "repeat_mode";
|
||||||
public static final String PLAYBACK_PITCH = "playback_pitch";
|
@NonNull public static final String PLAYBACK_PITCH = "playback_pitch";
|
||||||
public static final String PLAYBACK_SPEED = "playback_speed";
|
@NonNull public static final String PLAYBACK_SPEED = "playback_speed";
|
||||||
public static final String PLAYBACK_QUALITY = "playback_quality";
|
@NonNull public static final String PLAYBACK_SKIP_SILENCE = "playback_skip_silence";
|
||||||
public static final String PLAY_QUEUE_KEY = "play_queue_key";
|
@NonNull public static final String PLAYBACK_QUALITY = "playback_quality";
|
||||||
public static final String APPEND_ONLY = "append_only";
|
@NonNull public static final String PLAY_QUEUE_KEY = "play_queue_key";
|
||||||
public static final String SELECT_ON_APPEND = "select_on_append";
|
@NonNull public static final String APPEND_ONLY = "append_only";
|
||||||
|
@NonNull public static final String SELECT_ON_APPEND = "select_on_append";
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
// Playback
|
// Playback
|
||||||
|
@ -129,12 +136,13 @@ public abstract class BasePlayer implements
|
||||||
protected PlayQueue playQueue;
|
protected PlayQueue playQueue;
|
||||||
protected PlayQueueAdapter playQueueAdapter;
|
protected PlayQueueAdapter playQueueAdapter;
|
||||||
|
|
||||||
protected MediaSourceManager playbackManager;
|
@Nullable protected MediaSourceManager playbackManager;
|
||||||
|
|
||||||
protected StreamInfo currentInfo;
|
@Nullable private PlayQueueItem currentItem;
|
||||||
protected PlayQueueItem currentItem;
|
@Nullable private MediaSourceTag currentMetadata;
|
||||||
|
@Nullable private Bitmap currentThumbnail;
|
||||||
|
|
||||||
protected Toast errorToast;
|
@Nullable protected Toast errorToast;
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
// Player
|
// Player
|
||||||
|
@ -145,18 +153,11 @@ public abstract class BasePlayer implements
|
||||||
protected final static int PROGRESS_LOOP_INTERVAL_MILLIS = 500;
|
protected final static int PROGRESS_LOOP_INTERVAL_MILLIS = 500;
|
||||||
protected final static int RECOVERY_SKIP_THRESHOLD_MILLIS = 3000; // 3 seconds
|
protected final static int RECOVERY_SKIP_THRESHOLD_MILLIS = 3000; // 3 seconds
|
||||||
|
|
||||||
protected CustomTrackSelector trackSelector;
|
|
||||||
protected PlayerDataSource dataSource;
|
|
||||||
|
|
||||||
protected SimpleExoPlayer simpleExoPlayer;
|
protected SimpleExoPlayer simpleExoPlayer;
|
||||||
protected AudioReactor audioReactor;
|
protected AudioReactor audioReactor;
|
||||||
protected MediaSessionManager mediaSessionManager;
|
protected MediaSessionManager mediaSessionManager;
|
||||||
|
|
||||||
private boolean isPrepared = false;
|
private boolean isPrepared = false;
|
||||||
private boolean isSynchronizing = false;
|
|
||||||
|
|
||||||
protected Disposable progressUpdateReactor;
|
|
||||||
protected CompositeDisposable databaseUpdateReactor;
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
@ -174,29 +175,32 @@ public abstract class BasePlayer implements
|
||||||
context.registerReceiver(broadcastReceiver, intentFilter);
|
context.registerReceiver(broadcastReceiver, intentFilter);
|
||||||
|
|
||||||
this.recordManager = new HistoryRecordManager(context);
|
this.recordManager = new HistoryRecordManager(context);
|
||||||
|
|
||||||
|
this.progressUpdateReactor = new SerialDisposable();
|
||||||
|
this.databaseUpdateReactor = new CompositeDisposable();
|
||||||
|
|
||||||
|
final String userAgent = Downloader.USER_AGENT;
|
||||||
|
final DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
|
||||||
|
this.dataSource = new PlayerDataSource(context, userAgent, bandwidthMeter);
|
||||||
|
|
||||||
|
final TrackSelection.Factory trackSelectionFactory =
|
||||||
|
PlayerHelper.getQualitySelector(context, bandwidthMeter);
|
||||||
|
this.trackSelector = new CustomTrackSelector(trackSelectionFactory);
|
||||||
|
|
||||||
|
this.loadControl = new LoadController(context);
|
||||||
|
this.renderFactory = new DefaultRenderersFactory(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setup() {
|
public void setup() {
|
||||||
if (simpleExoPlayer == null) initPlayer(/*playOnInit=*/true);
|
if (simpleExoPlayer == null) {
|
||||||
|
initPlayer(/*playOnInit=*/true);
|
||||||
|
}
|
||||||
initListeners();
|
initListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initPlayer(final boolean playOnReady) {
|
public void initPlayer(final boolean playOnReady) {
|
||||||
if (DEBUG) Log.d(TAG, "initPlayer() called with: context = [" + context + "]");
|
if (DEBUG) Log.d(TAG, "initPlayer() called with: context = [" + context + "]");
|
||||||
|
|
||||||
if (databaseUpdateReactor != null) databaseUpdateReactor.dispose();
|
|
||||||
databaseUpdateReactor = new CompositeDisposable();
|
|
||||||
|
|
||||||
final String userAgent = Downloader.USER_AGENT;
|
|
||||||
final DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
|
|
||||||
dataSource = new PlayerDataSource(context, userAgent, bandwidthMeter);
|
|
||||||
|
|
||||||
final TrackSelection.Factory trackSelectionFactory =
|
|
||||||
PlayerHelper.getQualitySelector(context, bandwidthMeter);
|
|
||||||
trackSelector = new CustomTrackSelector(trackSelectionFactory);
|
|
||||||
|
|
||||||
final LoadControl loadControl = new LoadController(context);
|
|
||||||
final RenderersFactory renderFactory = new DefaultRenderersFactory(context);
|
|
||||||
simpleExoPlayer = ExoPlayerFactory.newSimpleInstance(renderFactory, trackSelector, loadControl);
|
simpleExoPlayer = ExoPlayerFactory.newSimpleInstance(renderFactory, trackSelector, loadControl);
|
||||||
simpleExoPlayer.addListener(this);
|
simpleExoPlayer.addListener(this);
|
||||||
simpleExoPlayer.setPlayWhenReady(playOnReady);
|
simpleExoPlayer.setPlayWhenReady(playOnReady);
|
||||||
|
@ -235,20 +239,24 @@ public abstract class BasePlayer implements
|
||||||
final int repeatMode = intent.getIntExtra(REPEAT_MODE, getRepeatMode());
|
final int repeatMode = intent.getIntExtra(REPEAT_MODE, getRepeatMode());
|
||||||
final float playbackSpeed = intent.getFloatExtra(PLAYBACK_SPEED, getPlaybackSpeed());
|
final float playbackSpeed = intent.getFloatExtra(PLAYBACK_SPEED, getPlaybackSpeed());
|
||||||
final float playbackPitch = intent.getFloatExtra(PLAYBACK_PITCH, getPlaybackPitch());
|
final float playbackPitch = intent.getFloatExtra(PLAYBACK_PITCH, getPlaybackPitch());
|
||||||
|
final boolean playbackSkipSilence = intent.getBooleanExtra(PLAYBACK_SKIP_SILENCE,
|
||||||
|
getPlaybackSkipSilence());
|
||||||
|
|
||||||
// Good to go...
|
// Good to go...
|
||||||
initPlayback(queue, repeatMode, playbackSpeed, playbackPitch, /*playOnInit=*/true);
|
initPlayback(queue, repeatMode, playbackSpeed, playbackPitch, playbackSkipSilence,
|
||||||
|
/*playOnInit=*/true);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void initPlayback(@NonNull final PlayQueue queue,
|
protected void initPlayback(@NonNull final PlayQueue queue,
|
||||||
@Player.RepeatMode final int repeatMode,
|
@Player.RepeatMode final int repeatMode,
|
||||||
final float playbackSpeed,
|
final float playbackSpeed,
|
||||||
final float playbackPitch,
|
final float playbackPitch,
|
||||||
|
final boolean playbackSkipSilence,
|
||||||
final boolean playOnReady) {
|
final boolean playOnReady) {
|
||||||
destroyPlayer();
|
destroyPlayer();
|
||||||
initPlayer(playOnReady);
|
initPlayer(playOnReady);
|
||||||
setRepeatMode(repeatMode);
|
setRepeatMode(repeatMode);
|
||||||
setPlaybackParameters(playbackSpeed, playbackPitch);
|
setPlaybackParameters(playbackSpeed, playbackPitch, playbackSkipSilence);
|
||||||
|
|
||||||
playQueue = queue;
|
playQueue = queue;
|
||||||
playQueue.init();
|
playQueue.init();
|
||||||
|
@ -270,7 +278,6 @@ public abstract class BasePlayer implements
|
||||||
if (playQueue != null) playQueue.dispose();
|
if (playQueue != null) playQueue.dispose();
|
||||||
if (audioReactor != null) audioReactor.dispose();
|
if (audioReactor != null) audioReactor.dispose();
|
||||||
if (playbackManager != null) playbackManager.dispose();
|
if (playbackManager != null) playbackManager.dispose();
|
||||||
if (databaseUpdateReactor != null) databaseUpdateReactor.dispose();
|
|
||||||
if (mediaSessionManager != null) mediaSessionManager.dispose();
|
if (mediaSessionManager != null) mediaSessionManager.dispose();
|
||||||
|
|
||||||
if (playQueueAdapter != null) {
|
if (playQueueAdapter != null) {
|
||||||
|
@ -284,20 +291,22 @@ public abstract class BasePlayer implements
|
||||||
destroyPlayer();
|
destroyPlayer();
|
||||||
unregisterBroadcastReceiver();
|
unregisterBroadcastReceiver();
|
||||||
|
|
||||||
trackSelector = null;
|
databaseUpdateReactor.clear();
|
||||||
|
progressUpdateReactor.set(null);
|
||||||
|
|
||||||
simpleExoPlayer = null;
|
simpleExoPlayer = null;
|
||||||
mediaSessionManager = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
// Thumbnail Loading
|
// Thumbnail Loading
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
public void initThumbnail(final String url) {
|
private void initThumbnail(final String url) {
|
||||||
if (DEBUG) Log.d(TAG, "Thumbnail - initThumbnail() called");
|
if (DEBUG) Log.d(TAG, "Thumbnail - initThumbnail() called");
|
||||||
if (url == null || url.isEmpty()) return;
|
if (url == null || url.isEmpty()) return;
|
||||||
ImageLoader.getInstance().resume();
|
ImageLoader.getInstance().resume();
|
||||||
ImageLoader.getInstance().loadImage(url, this);
|
ImageLoader.getInstance().loadImage(url, ImageDisplayConstants.DISPLAY_THUMBNAIL_OPTIONS,
|
||||||
|
this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -310,6 +319,7 @@ public abstract class BasePlayer implements
|
||||||
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
|
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
|
||||||
Log.e(TAG, "Thumbnail - onLoadingFailed() called on imageUri = [" + imageUri + "]",
|
Log.e(TAG, "Thumbnail - onLoadingFailed() called on imageUri = [" + imageUri + "]",
|
||||||
failReason.getCause());
|
failReason.getCause());
|
||||||
|
currentThumbnail = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -317,64 +327,14 @@ public abstract class BasePlayer implements
|
||||||
if (DEBUG) Log.d(TAG, "Thumbnail - onLoadingComplete() called with: " +
|
if (DEBUG) Log.d(TAG, "Thumbnail - onLoadingComplete() called with: " +
|
||||||
"imageUri = [" + imageUri + "], view = [" + view + "], " +
|
"imageUri = [" + imageUri + "], view = [" + view + "], " +
|
||||||
"loadedImage = [" + loadedImage + "]");
|
"loadedImage = [" + loadedImage + "]");
|
||||||
|
currentThumbnail = loadedImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoadingCancelled(String imageUri, View view) {
|
public void onLoadingCancelled(String imageUri, View view) {
|
||||||
if (DEBUG) Log.d(TAG, "Thumbnail - onLoadingCancelled() called with: " +
|
if (DEBUG) Log.d(TAG, "Thumbnail - onLoadingCancelled() called with: " +
|
||||||
"imageUri = [" + imageUri + "], view = [" + view + "]");
|
"imageUri = [" + imageUri + "], view = [" + view + "]");
|
||||||
}
|
currentThumbnail = null;
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
|
||||||
// MediaSource Building
|
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
|
||||||
|
|
||||||
public MediaSource buildLiveMediaSource(@NonNull final String sourceUrl,
|
|
||||||
@C.ContentType final int type) {
|
|
||||||
if (DEBUG) {
|
|
||||||
Log.d(TAG, "buildLiveMediaSource() called with: url = [" + sourceUrl +
|
|
||||||
"], content type = [" + type + "]");
|
|
||||||
}
|
|
||||||
if (dataSource == null) return null;
|
|
||||||
|
|
||||||
final Uri uri = Uri.parse(sourceUrl);
|
|
||||||
switch (type) {
|
|
||||||
case C.TYPE_SS:
|
|
||||||
return dataSource.getLiveSsMediaSourceFactory().createMediaSource(uri);
|
|
||||||
case C.TYPE_DASH:
|
|
||||||
return dataSource.getLiveDashMediaSourceFactory().createMediaSource(uri);
|
|
||||||
case C.TYPE_HLS:
|
|
||||||
return dataSource.getLiveHlsMediaSourceFactory().createMediaSource(uri);
|
|
||||||
default:
|
|
||||||
throw new IllegalStateException("Unsupported type: " + type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public MediaSource buildMediaSource(@NonNull final String sourceUrl,
|
|
||||||
@NonNull final String cacheKey,
|
|
||||||
@NonNull final String overrideExtension) {
|
|
||||||
if (DEBUG) {
|
|
||||||
Log.d(TAG, "buildMediaSource() called with: url = [" + sourceUrl +
|
|
||||||
"], cacheKey = [" + cacheKey + "]" +
|
|
||||||
"], overrideExtension = [" + overrideExtension + "]");
|
|
||||||
}
|
|
||||||
if (dataSource == null) return null;
|
|
||||||
|
|
||||||
final Uri uri = Uri.parse(sourceUrl);
|
|
||||||
@C.ContentType final int type = TextUtils.isEmpty(overrideExtension) ?
|
|
||||||
Util.inferContentType(uri) : Util.inferContentType("." + overrideExtension);
|
|
||||||
|
|
||||||
switch (type) {
|
|
||||||
case C.TYPE_SS:
|
|
||||||
return dataSource.getLiveSsMediaSourceFactory().createMediaSource(uri);
|
|
||||||
case C.TYPE_DASH:
|
|
||||||
return dataSource.getDashMediaSourceFactory().createMediaSource(uri);
|
|
||||||
case C.TYPE_HLS:
|
|
||||||
return dataSource.getHlsMediaSourceFactory().createMediaSource(uri);
|
|
||||||
case C.TYPE_OTHER:
|
|
||||||
return dataSource.getExtractorMediaSourceFactory(cacheKey).createMediaSource(uri);
|
|
||||||
default:
|
|
||||||
throw new IllegalStateException("Unsupported type: " + type);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -510,13 +470,11 @@ public abstract class BasePlayer implements
|
||||||
public abstract void onUpdateProgress(int currentProgress, int duration, int bufferPercent);
|
public abstract void onUpdateProgress(int currentProgress, int duration, int bufferPercent);
|
||||||
|
|
||||||
protected void startProgressLoop() {
|
protected void startProgressLoop() {
|
||||||
if (progressUpdateReactor != null) progressUpdateReactor.dispose();
|
progressUpdateReactor.set(getProgressReactor());
|
||||||
progressUpdateReactor = getProgressReactor();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void stopProgressLoop() {
|
protected void stopProgressLoop() {
|
||||||
if (progressUpdateReactor != null) progressUpdateReactor.dispose();
|
progressUpdateReactor.set(null);
|
||||||
progressUpdateReactor = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void triggerProgressUpdate() {
|
public void triggerProgressUpdate() {
|
||||||
|
@ -531,7 +489,8 @@ public abstract class BasePlayer implements
|
||||||
private Disposable getProgressReactor() {
|
private Disposable getProgressReactor() {
|
||||||
return Observable.interval(PROGRESS_LOOP_INTERVAL_MILLIS, TimeUnit.MILLISECONDS)
|
return Observable.interval(PROGRESS_LOOP_INTERVAL_MILLIS, TimeUnit.MILLISECONDS)
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(ignored -> triggerProgressUpdate());
|
.subscribe(ignored -> triggerProgressUpdate(),
|
||||||
|
error -> Log.e(TAG, "Progress update failure: ", error));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -545,28 +504,16 @@ public abstract class BasePlayer implements
|
||||||
(manifest == null ? "no manifest" : "available manifest") + ", " +
|
(manifest == null ? "no manifest" : "available manifest") + ", " +
|
||||||
"timeline size = [" + timeline.getWindowCount() + "], " +
|
"timeline size = [" + timeline.getWindowCount() + "], " +
|
||||||
"reason = [" + reason + "]");
|
"reason = [" + reason + "]");
|
||||||
if (playQueue == null) return;
|
|
||||||
|
|
||||||
switch (reason) {
|
maybeUpdateCurrentMetadata();
|
||||||
case Player.TIMELINE_CHANGE_REASON_RESET: // called after #block
|
|
||||||
case Player.TIMELINE_CHANGE_REASON_PREPARED: // called after #unblock
|
|
||||||
case Player.TIMELINE_CHANGE_REASON_DYNAMIC: // called after playlist changes
|
|
||||||
// Ensures MediaSourceManager#update is complete
|
|
||||||
final boolean isPlaylistStable = timeline.getWindowCount() == playQueue.size();
|
|
||||||
// Ensure dynamic/livestream timeline changes does not cause negative position
|
|
||||||
if (isPlaylistStable && !isCurrentWindowValid() && !isSynchronizing) {
|
|
||||||
if (DEBUG) Log.d(TAG, "Playback - negative time position reached, " +
|
|
||||||
"clamping to default position.");
|
|
||||||
seekToDefault();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
|
public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
|
||||||
if (DEBUG) Log.d(TAG, "ExoPlayer - onTracksChanged(), " +
|
if (DEBUG) Log.d(TAG, "ExoPlayer - onTracksChanged(), " +
|
||||||
"track group size = " + trackGroups.length);
|
"track group size = " + trackGroups.length);
|
||||||
|
|
||||||
|
maybeUpdateCurrentMetadata();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -586,6 +533,8 @@ public abstract class BasePlayer implements
|
||||||
} else if (isLoading && !isProgressLoopRunning()) {
|
} else if (isLoading && !isProgressLoopRunning()) {
|
||||||
startProgressLoop();
|
startProgressLoop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
maybeUpdateCurrentMetadata();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -609,6 +558,7 @@ public abstract class BasePlayer implements
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Player.STATE_READY: //3
|
case Player.STATE_READY: //3
|
||||||
|
maybeUpdateCurrentMetadata();
|
||||||
maybeCorrectSeekPosition();
|
maybeCorrectSeekPosition();
|
||||||
if (!isPrepared) {
|
if (!isPrepared) {
|
||||||
isPrepared = true;
|
isPrepared = true;
|
||||||
|
@ -625,38 +575,19 @@ public abstract class BasePlayer implements
|
||||||
}
|
}
|
||||||
|
|
||||||
private void maybeCorrectSeekPosition() {
|
private void maybeCorrectSeekPosition() {
|
||||||
if (playQueue == null || simpleExoPlayer == null || currentInfo == null) return;
|
if (playQueue == null || simpleExoPlayer == null || currentMetadata == null) return;
|
||||||
|
|
||||||
final int currentSourceIndex = playQueue.getIndex();
|
|
||||||
final PlayQueueItem currentSourceItem = playQueue.getItem();
|
final PlayQueueItem currentSourceItem = playQueue.getItem();
|
||||||
if (currentSourceItem == null) return;
|
if (currentSourceItem == null) return;
|
||||||
|
|
||||||
final long recoveryPositionMillis = currentSourceItem.getRecoveryPosition();
|
final StreamInfo currentInfo = currentMetadata.getMetadata();
|
||||||
final boolean isCurrentWindowCorrect =
|
|
||||||
simpleExoPlayer.getCurrentPeriodIndex() == currentSourceIndex;
|
|
||||||
final long presetStartPositionMillis = currentInfo.getStartPosition() * 1000;
|
final long presetStartPositionMillis = currentInfo.getStartPosition() * 1000;
|
||||||
|
if (presetStartPositionMillis > 0L) {
|
||||||
if (recoveryPositionMillis != PlayQueueItem.RECOVERY_UNSET && isCurrentWindowCorrect) {
|
// Has another start position?
|
||||||
// Is recovering previous playback?
|
|
||||||
if (DEBUG) Log.d(TAG, "Playback - Rewinding to recovery time=" +
|
|
||||||
"[" + getTimeString((int)recoveryPositionMillis) + "]");
|
|
||||||
seekTo(recoveryPositionMillis);
|
|
||||||
playQueue.unsetRecovery(currentSourceIndex);
|
|
||||||
|
|
||||||
} else if (isSynchronizing && isLive()) {
|
|
||||||
if (DEBUG) Log.d(TAG, "Playback - Synchronizing livestream to default time");
|
|
||||||
// Is still synchronizing?
|
|
||||||
seekToDefault();
|
|
||||||
|
|
||||||
} else if (isSynchronizing && presetStartPositionMillis > 0L) {
|
|
||||||
if (DEBUG) Log.d(TAG, "Playback - Seeking to preset start " +
|
if (DEBUG) Log.d(TAG, "Playback - Seeking to preset start " +
|
||||||
"position=[" + presetStartPositionMillis + "]");
|
"position=[" + presetStartPositionMillis + "]");
|
||||||
// Has another start position?
|
|
||||||
seekTo(presetStartPositionMillis);
|
seekTo(presetStartPositionMillis);
|
||||||
currentInfo.setStartPosition(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
isSynchronizing = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -708,7 +639,7 @@ public abstract class BasePlayer implements
|
||||||
setRecovery();
|
setRecovery();
|
||||||
|
|
||||||
final Throwable cause = error.getCause();
|
final Throwable cause = error.getCause();
|
||||||
if (cause instanceof BehindLiveWindowException) {
|
if (error instanceof BehindLiveWindowException) {
|
||||||
reload();
|
reload();
|
||||||
} else if (cause instanceof UnknownHostException) {
|
} else if (cause instanceof UnknownHostException) {
|
||||||
playQueue.error(/*isNetworkProblem=*/true);
|
playQueue.error(/*isNetworkProblem=*/true);
|
||||||
|
@ -727,22 +658,29 @@ public abstract class BasePlayer implements
|
||||||
public void onPositionDiscontinuity(@Player.DiscontinuityReason final int reason) {
|
public void onPositionDiscontinuity(@Player.DiscontinuityReason final int reason) {
|
||||||
if (DEBUG) Log.d(TAG, "ExoPlayer - onPositionDiscontinuity() called with " +
|
if (DEBUG) Log.d(TAG, "ExoPlayer - onPositionDiscontinuity() called with " +
|
||||||
"reason = [" + reason + "]");
|
"reason = [" + reason + "]");
|
||||||
// Refresh the playback if there is a transition to the next video
|
if (playQueue == null) return;
|
||||||
final int newPeriodIndex = simpleExoPlayer.getCurrentPeriodIndex();
|
|
||||||
|
|
||||||
/* Discontinuity reasons!! Thank you ExoPlayer lords */
|
// Refresh the playback if there is a transition to the next video
|
||||||
|
final int newWindowIndex = simpleExoPlayer.getCurrentWindowIndex();
|
||||||
switch (reason) {
|
switch (reason) {
|
||||||
case DISCONTINUITY_REASON_PERIOD_TRANSITION:
|
case DISCONTINUITY_REASON_PERIOD_TRANSITION:
|
||||||
if (newPeriodIndex == playQueue.getIndex()) {
|
// When player is in single repeat mode and a period transition occurs,
|
||||||
|
// we need to register a view count here since no metadata has changed
|
||||||
|
if (getRepeatMode() == Player.REPEAT_MODE_ONE &&
|
||||||
|
newWindowIndex == playQueue.getIndex()) {
|
||||||
registerView();
|
registerView();
|
||||||
} else {
|
break;
|
||||||
playQueue.offsetIndex(+1);
|
|
||||||
}
|
}
|
||||||
case DISCONTINUITY_REASON_SEEK:
|
case DISCONTINUITY_REASON_SEEK:
|
||||||
case DISCONTINUITY_REASON_SEEK_ADJUSTMENT:
|
case DISCONTINUITY_REASON_SEEK_ADJUSTMENT:
|
||||||
case DISCONTINUITY_REASON_INTERNAL:
|
case DISCONTINUITY_REASON_INTERNAL:
|
||||||
|
if (playQueue.getIndex() != newWindowIndex) {
|
||||||
|
playQueue.setIndex(newWindowIndex);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
maybeUpdateCurrentMetadata();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -788,7 +726,7 @@ public abstract class BasePlayer implements
|
||||||
if (DEBUG) Log.d(TAG, "Playback - onPlaybackBlock() called");
|
if (DEBUG) Log.d(TAG, "Playback - onPlaybackBlock() called");
|
||||||
|
|
||||||
currentItem = null;
|
currentItem = null;
|
||||||
currentInfo = null;
|
currentMetadata = null;
|
||||||
simpleExoPlayer.stop();
|
simpleExoPlayer.stop();
|
||||||
isPrepared = false;
|
isPrepared = false;
|
||||||
|
|
||||||
|
@ -805,42 +743,21 @@ public abstract class BasePlayer implements
|
||||||
simpleExoPlayer.prepare(mediaSource);
|
simpleExoPlayer.prepare(mediaSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void onPlaybackSynchronize(@NonNull final PlayQueueItem item) {
|
||||||
public void onPlaybackSynchronize(@NonNull final PlayQueueItem item,
|
|
||||||
@Nullable final StreamInfo info) {
|
|
||||||
if (DEBUG) Log.d(TAG, "Playback - onPlaybackSynchronize() called with " +
|
if (DEBUG) Log.d(TAG, "Playback - onPlaybackSynchronize() called with " +
|
||||||
(info != null ? "available" : "null") + " info, " +
|
|
||||||
"item=[" + item.getTitle() + "], url=[" + item.getUrl() + "]");
|
"item=[" + item.getTitle() + "], url=[" + item.getUrl() + "]");
|
||||||
if (simpleExoPlayer == null || playQueue == null) return;
|
if (simpleExoPlayer == null || playQueue == null) return;
|
||||||
|
|
||||||
final boolean onPlaybackInitial = currentItem == null;
|
final boolean onPlaybackInitial = currentItem == null;
|
||||||
final boolean hasPlayQueueItemChanged = currentItem != item;
|
final boolean hasPlayQueueItemChanged = currentItem != item;
|
||||||
final boolean hasStreamInfoChanged = currentInfo != info;
|
|
||||||
|
|
||||||
final int currentPlayQueueIndex = playQueue.indexOf(item);
|
final int currentPlayQueueIndex = playQueue.indexOf(item);
|
||||||
final int currentPlaylistIndex = simpleExoPlayer.getCurrentWindowIndex();
|
final int currentPlaylistIndex = simpleExoPlayer.getCurrentWindowIndex();
|
||||||
final int currentPlaylistSize = simpleExoPlayer.getCurrentTimeline().getWindowCount();
|
final int currentPlaylistSize = simpleExoPlayer.getCurrentTimeline().getWindowCount();
|
||||||
|
|
||||||
// when starting playback on the last item when not repeating, maybe auto queue
|
|
||||||
if (info != null && currentPlayQueueIndex == playQueue.size() - 1 &&
|
|
||||||
getRepeatMode() == Player.REPEAT_MODE_OFF &&
|
|
||||||
PlayerHelper.isAutoQueueEnabled(context)) {
|
|
||||||
final PlayQueue autoQueue = PlayerHelper.autoQueueOf(info, playQueue.getStreams());
|
|
||||||
if (autoQueue != null) playQueue.append(autoQueue.getStreams());
|
|
||||||
}
|
|
||||||
// If nothing to synchronize
|
// If nothing to synchronize
|
||||||
if (!hasPlayQueueItemChanged && !hasStreamInfoChanged) {
|
if (!hasPlayQueueItemChanged) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
currentItem = item;
|
currentItem = item;
|
||||||
currentInfo = info;
|
|
||||||
if (hasPlayQueueItemChanged) {
|
|
||||||
// updates only to the stream info should not trigger another view count
|
|
||||||
registerView();
|
|
||||||
initThumbnail(info == null ? item.getThumbnailUrl() : info.getThumbnailUrl());
|
|
||||||
}
|
|
||||||
onMetadataChanged(item, info, currentPlayQueueIndex, hasPlayQueueItemChanged);
|
|
||||||
|
|
||||||
// Check if on wrong window
|
// Check if on wrong window
|
||||||
if (currentPlayQueueIndex != playQueue.getIndex()) {
|
if (currentPlayQueueIndex != playQueue.getIndex()) {
|
||||||
|
@ -855,39 +772,29 @@ public abstract class BasePlayer implements
|
||||||
"index=[" + currentPlayQueueIndex + "] with " +
|
"index=[" + currentPlayQueueIndex + "] with " +
|
||||||
"playlist length=[" + currentPlaylistSize + "]");
|
"playlist length=[" + currentPlaylistSize + "]");
|
||||||
|
|
||||||
// If not playing correct stream, change window position and sets flag
|
|
||||||
// for synchronizing once window position is corrected
|
|
||||||
// @see maybeCorrectSeekPosition()
|
|
||||||
} else if (currentPlaylistIndex != currentPlayQueueIndex || onPlaybackInitial ||
|
} else if (currentPlaylistIndex != currentPlayQueueIndex || onPlaybackInitial ||
|
||||||
!isPlaying()) {
|
!isPlaying()) {
|
||||||
if (DEBUG) Log.d(TAG, "Playback - Rewinding to correct" +
|
if (DEBUG) Log.d(TAG, "Playback - Rewinding to correct" +
|
||||||
" index=[" + currentPlayQueueIndex + "]," +
|
" index=[" + currentPlayQueueIndex + "]," +
|
||||||
" from=[" + currentPlaylistIndex + "], size=[" + currentPlaylistSize + "].");
|
" from=[" + currentPlaylistIndex + "], size=[" + currentPlaylistSize + "].");
|
||||||
isSynchronizing = true;
|
|
||||||
|
if (item.getRecoveryPosition() != PlayQueueItem.RECOVERY_UNSET) {
|
||||||
|
simpleExoPlayer.seekTo(currentPlayQueueIndex, item.getRecoveryPosition());
|
||||||
|
playQueue.unsetRecovery(currentPlayQueueIndex);
|
||||||
|
} else {
|
||||||
simpleExoPlayer.seekToDefaultPosition(currentPlayQueueIndex);
|
simpleExoPlayer.seekToDefaultPosition(currentPlayQueueIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract protected void onMetadataChanged(@NonNull final PlayQueueItem item,
|
|
||||||
@Nullable final StreamInfo info,
|
|
||||||
final int newPlayQueueIndex,
|
|
||||||
final boolean hasPlayQueueItemChanged);
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public MediaSource sourceOf(PlayQueueItem item, StreamInfo info) {
|
|
||||||
final StreamType streamType = info.getStreamType();
|
|
||||||
if (!(streamType == StreamType.AUDIO_LIVE_STREAM || streamType == StreamType.LIVE_STREAM)) {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!info.getHlsUrl().isEmpty()) {
|
protected void onMetadataChanged(@NonNull final MediaSourceTag tag) {
|
||||||
return buildLiveMediaSource(info.getHlsUrl(), C.TYPE_HLS);
|
final StreamInfo info = tag.getMetadata();
|
||||||
} else if (!info.getDashMpdUrl().isEmpty()) {
|
if (DEBUG) {
|
||||||
return buildLiveMediaSource(info.getDashMpdUrl(), C.TYPE_DASH);
|
Log.d(TAG, "Playback - onMetadataChanged() called, playing: " + info.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
initThumbnail(info.getThumbnailUrl());
|
||||||
|
registerView();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1020,9 +927,7 @@ public abstract class BasePlayer implements
|
||||||
|
|
||||||
public void seekTo(long positionMillis) {
|
public void seekTo(long positionMillis) {
|
||||||
if (DEBUG) Log.d(TAG, "seekBy() called with: position = [" + positionMillis + "]");
|
if (DEBUG) Log.d(TAG, "seekBy() called with: position = [" + positionMillis + "]");
|
||||||
if (simpleExoPlayer == null || positionMillis < 0 ||
|
if (simpleExoPlayer != null) simpleExoPlayer.seekTo(positionMillis);
|
||||||
positionMillis > simpleExoPlayer.getDuration()) return;
|
|
||||||
simpleExoPlayer.seekTo(positionMillis);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void seekBy(long offsetMillis) {
|
public void seekBy(long offsetMillis) {
|
||||||
|
@ -1046,12 +951,14 @@ public abstract class BasePlayer implements
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
private void registerView() {
|
private void registerView() {
|
||||||
if (databaseUpdateReactor == null || currentInfo == null) return;
|
if (currentMetadata == null) return;
|
||||||
databaseUpdateReactor.add(recordManager.onViewed(currentInfo).onErrorComplete()
|
final StreamInfo currentInfo = currentMetadata.getMetadata();
|
||||||
|
final Disposable viewRegister = recordManager.onViewed(currentInfo).onErrorComplete()
|
||||||
.subscribe(
|
.subscribe(
|
||||||
ignored -> {/* successful */},
|
ignored -> {/* successful */},
|
||||||
error -> Log.e(TAG, "Player onViewed() failure: ", error)
|
error -> Log.e(TAG, "Player onViewed() failure: ", error)
|
||||||
));
|
);
|
||||||
|
databaseUpdateReactor.add(viewRegister);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void reload() {
|
protected void reload() {
|
||||||
|
@ -1065,7 +972,7 @@ public abstract class BasePlayer implements
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void savePlaybackState(final StreamInfo info, final long progress) {
|
protected void savePlaybackState(final StreamInfo info, final long progress) {
|
||||||
if (info == null || databaseUpdateReactor == null) return;
|
if (info == null) return;
|
||||||
final Disposable stateSaver = recordManager.saveStreamState(info, progress)
|
final Disposable stateSaver = recordManager.saveStreamState(info, progress)
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.onErrorComplete()
|
.onErrorComplete()
|
||||||
|
@ -1077,7 +984,8 @@ public abstract class BasePlayer implements
|
||||||
}
|
}
|
||||||
|
|
||||||
private void savePlaybackState() {
|
private void savePlaybackState() {
|
||||||
if (simpleExoPlayer == null || currentInfo == null) return;
|
if (simpleExoPlayer == null || currentMetadata == null) return;
|
||||||
|
final StreamInfo currentInfo = currentMetadata.getMetadata();
|
||||||
|
|
||||||
if (simpleExoPlayer.getCurrentPosition() > RECOVERY_SKIP_THRESHOLD_MILLIS &&
|
if (simpleExoPlayer.getCurrentPosition() > RECOVERY_SKIP_THRESHOLD_MILLIS &&
|
||||||
simpleExoPlayer.getCurrentPosition() <
|
simpleExoPlayer.getCurrentPosition() <
|
||||||
|
@ -1085,6 +993,34 @@ public abstract class BasePlayer implements
|
||||||
savePlaybackState(currentInfo, simpleExoPlayer.getCurrentPosition());
|
savePlaybackState(currentInfo, simpleExoPlayer.getCurrentPosition());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void maybeUpdateCurrentMetadata() {
|
||||||
|
if (simpleExoPlayer == null) return;
|
||||||
|
|
||||||
|
final MediaSourceTag metadata;
|
||||||
|
try {
|
||||||
|
metadata = (MediaSourceTag) simpleExoPlayer.getCurrentTag();
|
||||||
|
} catch (IndexOutOfBoundsException | ClassCastException error) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (metadata == null) return;
|
||||||
|
maybeAutoQueueNextStream(metadata);
|
||||||
|
|
||||||
|
if (currentMetadata == metadata) return;
|
||||||
|
currentMetadata = metadata;
|
||||||
|
onMetadataChanged(metadata);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void maybeAutoQueueNextStream(@NonNull final MediaSourceTag currentMetadata) {
|
||||||
|
if (playQueue == null || playQueue.getIndex() != playQueue.size() - 1 ||
|
||||||
|
getRepeatMode() != Player.REPEAT_MODE_OFF ||
|
||||||
|
!PlayerHelper.isAutoQueueEnabled(context)) return;
|
||||||
|
// auto queue when starting playback on the last item when not repeating
|
||||||
|
final PlayQueue autoQueue = PlayerHelper.autoQueueOf(currentMetadata.getMetadata(),
|
||||||
|
playQueue.getStreams());
|
||||||
|
if (autoQueue != null) playQueue.append(autoQueue.getStreams());
|
||||||
|
}
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
// Getters and Setters
|
// Getters and Setters
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
@ -1101,19 +1037,35 @@ public abstract class BasePlayer implements
|
||||||
return currentState;
|
return currentState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public MediaSourceTag getCurrentMetadata() {
|
||||||
|
return currentMetadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public String getVideoUrl() {
|
public String getVideoUrl() {
|
||||||
return currentItem == null ? context.getString(R.string.unknown_content) : currentItem.getUrl();
|
return currentMetadata == null ? context.getString(R.string.unknown_content) : currentMetadata.getMetadata().getUrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public String getVideoTitle() {
|
public String getVideoTitle() {
|
||||||
return currentItem == null ? context.getString(R.string.unknown_content) : currentItem.getTitle();
|
return currentMetadata == null ? context.getString(R.string.unknown_content) : currentMetadata.getMetadata().getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public String getUploaderName() {
|
public String getUploaderName() {
|
||||||
return currentItem == null ? context.getString(R.string.unknown_content) : currentItem.getUploader();
|
return currentMetadata == null ? context.getString(R.string.unknown_content) : currentMetadata.getMetadata().getUploaderName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public Bitmap getThumbnail() {
|
||||||
|
return currentThumbnail == null ?
|
||||||
|
BitmapFactory.decodeResource(context.getResources(), R.drawable.dummy_thumbnail) :
|
||||||
|
currentThumbnail;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Checks if the current playback is a livestream AND is playing at or beyond the live edge */
|
/** Checks if the current playback is a livestream AND is playing at or beyond the live edge */
|
||||||
|
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
|
||||||
public boolean isLiveEdge() {
|
public boolean isLiveEdge() {
|
||||||
if (simpleExoPlayer == null || !isLive()) return false;
|
if (simpleExoPlayer == null || !isLive()) return false;
|
||||||
|
|
||||||
|
@ -1162,19 +1114,22 @@ public abstract class BasePlayer implements
|
||||||
return getPlaybackParameters().pitch;
|
return getPlaybackParameters().pitch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getPlaybackSkipSilence() {
|
||||||
|
return getPlaybackParameters().skipSilence;
|
||||||
|
}
|
||||||
|
|
||||||
public void setPlaybackSpeed(float speed) {
|
public void setPlaybackSpeed(float speed) {
|
||||||
setPlaybackParameters(speed, getPlaybackPitch());
|
setPlaybackParameters(speed, getPlaybackPitch(), getPlaybackSkipSilence());
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlaybackParameters getPlaybackParameters() {
|
public PlaybackParameters getPlaybackParameters() {
|
||||||
final PlaybackParameters defaultParameters = new PlaybackParameters(1f, 1f);
|
if (simpleExoPlayer == null) return PlaybackParameters.DEFAULT;
|
||||||
if (simpleExoPlayer == null) return defaultParameters;
|
|
||||||
final PlaybackParameters parameters = simpleExoPlayer.getPlaybackParameters();
|
final PlaybackParameters parameters = simpleExoPlayer.getPlaybackParameters();
|
||||||
return parameters == null ? defaultParameters : parameters;
|
return parameters == null ? PlaybackParameters.DEFAULT : parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPlaybackParameters(float speed, float pitch) {
|
public void setPlaybackParameters(float speed, float pitch, boolean skipSilence) {
|
||||||
simpleExoPlayer.setPlaybackParameters(new PlaybackParameters(speed, pitch));
|
simpleExoPlayer.setPlaybackParameters(new PlaybackParameters(speed, pitch, skipSilence));
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayQueue getPlayQueue() {
|
public PlayQueue getPlayQueue() {
|
||||||
|
@ -1190,7 +1145,7 @@ public abstract class BasePlayer implements
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isProgressLoopRunning() {
|
public boolean isProgressLoopRunning() {
|
||||||
return progressUpdateReactor != null && !progressUpdateReactor.isDisposed();
|
return progressUpdateReactor.get() != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRecovery() {
|
public void setRecovery() {
|
||||||
|
|
|
@ -58,7 +58,6 @@ import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
|
||||||
import com.google.android.exoplayer2.ui.SubtitleView;
|
import com.google.android.exoplayer2.ui.SubtitleView;
|
||||||
|
|
||||||
import org.schabi.newpipe.R;
|
import org.schabi.newpipe.R;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
|
||||||
import org.schabi.newpipe.extractor.stream.VideoStream;
|
import org.schabi.newpipe.extractor.stream.VideoStream;
|
||||||
import org.schabi.newpipe.fragments.OnScrollBelowItemsListener;
|
import org.schabi.newpipe.fragments.OnScrollBelowItemsListener;
|
||||||
import org.schabi.newpipe.player.helper.PlaybackParameterDialog;
|
import org.schabi.newpipe.player.helper.PlaybackParameterDialog;
|
||||||
|
@ -67,6 +66,8 @@ import org.schabi.newpipe.player.playqueue.PlayQueueItem;
|
||||||
import org.schabi.newpipe.player.playqueue.PlayQueueItemBuilder;
|
import org.schabi.newpipe.player.playqueue.PlayQueueItemBuilder;
|
||||||
import org.schabi.newpipe.player.playqueue.PlayQueueItemHolder;
|
import org.schabi.newpipe.player.playqueue.PlayQueueItemHolder;
|
||||||
import org.schabi.newpipe.player.playqueue.PlayQueueItemTouchCallback;
|
import org.schabi.newpipe.player.playqueue.PlayQueueItemTouchCallback;
|
||||||
|
import org.schabi.newpipe.player.resolver.MediaSourceTag;
|
||||||
|
import org.schabi.newpipe.player.resolver.VideoPlaybackResolver;
|
||||||
import org.schabi.newpipe.util.AnimationUtils;
|
import org.schabi.newpipe.util.AnimationUtils;
|
||||||
import org.schabi.newpipe.util.ListHelper;
|
import org.schabi.newpipe.util.ListHelper;
|
||||||
import org.schabi.newpipe.util.NavigationHelper;
|
import org.schabi.newpipe.util.NavigationHelper;
|
||||||
|
@ -181,7 +182,7 @@ public final class MainVideoPlayer extends AppCompatActivity
|
||||||
playerImpl.setPlaybackQuality(playerState.getPlaybackQuality());
|
playerImpl.setPlaybackQuality(playerState.getPlaybackQuality());
|
||||||
playerImpl.initPlayback(playerState.getPlayQueue(), playerState.getRepeatMode(),
|
playerImpl.initPlayback(playerState.getPlayQueue(), playerState.getRepeatMode(),
|
||||||
playerState.getPlaybackSpeed(), playerState.getPlaybackPitch(),
|
playerState.getPlaybackSpeed(), playerState.getPlaybackPitch(),
|
||||||
playerState.wasPlaying());
|
playerState.isPlaybackSkipSilence(), playerState.wasPlaying());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,7 +211,8 @@ public final class MainVideoPlayer extends AppCompatActivity
|
||||||
playerImpl.setRecovery();
|
playerImpl.setRecovery();
|
||||||
playerState = new PlayerState(playerImpl.getPlayQueue(), playerImpl.getRepeatMode(),
|
playerState = new PlayerState(playerImpl.getPlayQueue(), playerImpl.getRepeatMode(),
|
||||||
playerImpl.getPlaybackSpeed(), playerImpl.getPlaybackPitch(),
|
playerImpl.getPlaybackSpeed(), playerImpl.getPlaybackPitch(),
|
||||||
playerImpl.getPlaybackQuality(), playerImpl.isPlaying());
|
playerImpl.getPlaybackQuality(), playerImpl.getPlaybackSkipSilence(),
|
||||||
|
playerImpl.isPlaying());
|
||||||
StateSaver.tryToSave(isChangingConfigurations(), null, outState, this);
|
StateSaver.tryToSave(isChangingConfigurations(), null, outState, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -352,8 +354,11 @@ public final class MainVideoPlayer extends AppCompatActivity
|
||||||
////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlaybackParameterChanged(float playbackTempo, float playbackPitch) {
|
public void onPlaybackParameterChanged(float playbackTempo, float playbackPitch,
|
||||||
if (playerImpl != null) playerImpl.setPlaybackParameters(playbackTempo, playbackPitch);
|
boolean playbackSkipSilence) {
|
||||||
|
if (playerImpl != null) {
|
||||||
|
playerImpl.setPlaybackParameters(playbackTempo, playbackPitch, playbackSkipSilence);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -493,14 +498,11 @@ public final class MainVideoPlayer extends AppCompatActivity
|
||||||
// Playback Listener
|
// Playback Listener
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
protected void onMetadataChanged(@NonNull final PlayQueueItem item,
|
protected void onMetadataChanged(@NonNull final MediaSourceTag tag) {
|
||||||
@Nullable final StreamInfo info,
|
super.onMetadataChanged(tag);
|
||||||
final int newPlayQueueIndex,
|
|
||||||
final boolean hasPlayQueueItemChanged) {
|
|
||||||
super.onMetadataChanged(item, info, newPlayQueueIndex, false);
|
|
||||||
|
|
||||||
titleTextView.setText(getVideoTitle());
|
titleTextView.setText(tag.getMetadata().getName());
|
||||||
channelTextView.setText(getUploaderName());
|
channelTextView.setText(tag.getMetadata().getUploaderName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -533,6 +535,7 @@ public final class MainVideoPlayer extends AppCompatActivity
|
||||||
this.getRepeatMode(),
|
this.getRepeatMode(),
|
||||||
this.getPlaybackSpeed(),
|
this.getPlaybackSpeed(),
|
||||||
this.getPlaybackPitch(),
|
this.getPlaybackPitch(),
|
||||||
|
this.getPlaybackSkipSilence(),
|
||||||
this.getPlaybackQuality()
|
this.getPlaybackQuality()
|
||||||
);
|
);
|
||||||
context.startService(intent);
|
context.startService(intent);
|
||||||
|
@ -554,6 +557,7 @@ public final class MainVideoPlayer extends AppCompatActivity
|
||||||
this.getRepeatMode(),
|
this.getRepeatMode(),
|
||||||
this.getPlaybackSpeed(),
|
this.getPlaybackSpeed(),
|
||||||
this.getPlaybackPitch(),
|
this.getPlaybackPitch(),
|
||||||
|
this.getPlaybackSkipSilence(),
|
||||||
this.getPlaybackQuality()
|
this.getPlaybackQuality()
|
||||||
);
|
);
|
||||||
context.startService(intent);
|
context.startService(intent);
|
||||||
|
@ -649,7 +653,8 @@ public final class MainVideoPlayer extends AppCompatActivity
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlaybackSpeedClicked() {
|
public void onPlaybackSpeedClicked() {
|
||||||
PlaybackParameterDialog.newInstance(getPlaybackSpeed(), getPlaybackPitch())
|
PlaybackParameterDialog
|
||||||
|
.newInstance(getPlaybackSpeed(), getPlaybackPitch(), getPlaybackSkipSilence())
|
||||||
.show(getSupportFragmentManager(), TAG);
|
.show(getSupportFragmentManager(), TAG);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -679,15 +684,20 @@ public final class MainVideoPlayer extends AppCompatActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getDefaultResolutionIndex(final List<VideoStream> sortedVideos) {
|
protected VideoPlaybackResolver.QualityResolver getQualityResolver() {
|
||||||
|
return new VideoPlaybackResolver.QualityResolver() {
|
||||||
|
@Override
|
||||||
|
public int getDefaultResolutionIndex(List<VideoStream> sortedVideos) {
|
||||||
return ListHelper.getDefaultResolutionIndex(context, sortedVideos);
|
return ListHelper.getDefaultResolutionIndex(context, sortedVideos);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getOverrideResolutionIndex(final List<VideoStream> sortedVideos,
|
public int getOverrideResolutionIndex(List<VideoStream> sortedVideos,
|
||||||
final String playbackQuality) {
|
String playbackQuality) {
|
||||||
return ListHelper.getResolutionIndex(context, sortedVideos, playbackQuality);
|
return ListHelper.getResolutionIndex(context, sortedVideos, playbackQuality);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
// States
|
// States
|
||||||
|
@ -710,7 +720,6 @@ public final class MainVideoPlayer extends AppCompatActivity
|
||||||
@Override
|
@Override
|
||||||
public void onBuffering() {
|
public void onBuffering() {
|
||||||
super.onBuffering();
|
super.onBuffering();
|
||||||
animatePlayButtons(false, 100);
|
|
||||||
getRootView().setKeepScreenOn(true);
|
getRootView().setKeepScreenOn(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -886,7 +895,6 @@ public final class MainVideoPlayer extends AppCompatActivity
|
||||||
@Override
|
@Override
|
||||||
public boolean onDoubleTap(MotionEvent e) {
|
public boolean onDoubleTap(MotionEvent e) {
|
||||||
if (DEBUG) Log.d(TAG, "onDoubleTap() called with: e = [" + e + "]" + "rawXy = " + e.getRawX() + ", " + e.getRawY() + ", xy = " + e.getX() + ", " + e.getY());
|
if (DEBUG) Log.d(TAG, "onDoubleTap() called with: e = [" + e + "]" + "rawXy = " + e.getRawX() + ", " + e.getRawY() + ", xy = " + e.getX() + ", " + e.getY());
|
||||||
if (!playerImpl.isPlaying()) return false;
|
|
||||||
|
|
||||||
if (e.getX() > playerImpl.getRootView().getWidth() * 2 / 3) {
|
if (e.getX() > playerImpl.getRootView().getWidth() * 2 / 3) {
|
||||||
playerImpl.onFastForward();
|
playerImpl.onFastForward();
|
||||||
|
|
|
@ -14,21 +14,26 @@ public class PlayerState implements Serializable {
|
||||||
private final float playbackSpeed;
|
private final float playbackSpeed;
|
||||||
private final float playbackPitch;
|
private final float playbackPitch;
|
||||||
@Nullable private final String playbackQuality;
|
@Nullable private final String playbackQuality;
|
||||||
|
private final boolean playbackSkipSilence;
|
||||||
private final boolean wasPlaying;
|
private final boolean wasPlaying;
|
||||||
|
|
||||||
PlayerState(@NonNull final PlayQueue playQueue, final int repeatMode,
|
PlayerState(@NonNull final PlayQueue playQueue, final int repeatMode,
|
||||||
final float playbackSpeed, final float playbackPitch, final boolean wasPlaying) {
|
final float playbackSpeed, final float playbackPitch,
|
||||||
this(playQueue, repeatMode, playbackSpeed, playbackPitch, null, wasPlaying);
|
final boolean playbackSkipSilence, final boolean wasPlaying) {
|
||||||
|
this(playQueue, repeatMode, playbackSpeed, playbackPitch, null,
|
||||||
|
playbackSkipSilence, wasPlaying);
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerState(@NonNull final PlayQueue playQueue, final int repeatMode,
|
PlayerState(@NonNull final PlayQueue playQueue, final int repeatMode,
|
||||||
final float playbackSpeed, final float playbackPitch,
|
final float playbackSpeed, final float playbackPitch,
|
||||||
@Nullable final String playbackQuality, final boolean wasPlaying) {
|
@Nullable final String playbackQuality, final boolean playbackSkipSilence,
|
||||||
|
final boolean wasPlaying) {
|
||||||
this.playQueue = playQueue;
|
this.playQueue = playQueue;
|
||||||
this.repeatMode = repeatMode;
|
this.repeatMode = repeatMode;
|
||||||
this.playbackSpeed = playbackSpeed;
|
this.playbackSpeed = playbackSpeed;
|
||||||
this.playbackPitch = playbackPitch;
|
this.playbackPitch = playbackPitch;
|
||||||
this.playbackQuality = playbackQuality;
|
this.playbackQuality = playbackQuality;
|
||||||
|
this.playbackSkipSilence = playbackSkipSilence;
|
||||||
this.wasPlaying = wasPlaying;
|
this.wasPlaying = wasPlaying;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,6 +67,10 @@ public class PlayerState implements Serializable {
|
||||||
return playbackQuality;
|
return playbackQuality;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isPlaybackSkipSilence() {
|
||||||
|
return playbackSkipSilence;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean wasPlaying() {
|
public boolean wasPlaying() {
|
||||||
return wasPlaying;
|
return wasPlaying;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,6 @@ import android.os.Build;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
|
||||||
import android.support.v4.app.NotificationCompat;
|
import android.support.v4.app.NotificationCompat;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
@ -56,16 +55,17 @@ import com.google.android.exoplayer2.Player;
|
||||||
import com.google.android.exoplayer2.text.CaptionStyleCompat;
|
import com.google.android.exoplayer2.text.CaptionStyleCompat;
|
||||||
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
|
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
|
||||||
import com.google.android.exoplayer2.ui.SubtitleView;
|
import com.google.android.exoplayer2.ui.SubtitleView;
|
||||||
|
import com.nostra13.universalimageloader.core.assist.FailReason;
|
||||||
|
|
||||||
import org.schabi.newpipe.BuildConfig;
|
import org.schabi.newpipe.BuildConfig;
|
||||||
import org.schabi.newpipe.R;
|
import org.schabi.newpipe.R;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
|
||||||
import org.schabi.newpipe.extractor.stream.VideoStream;
|
import org.schabi.newpipe.extractor.stream.VideoStream;
|
||||||
import org.schabi.newpipe.player.event.PlayerEventListener;
|
import org.schabi.newpipe.player.event.PlayerEventListener;
|
||||||
import org.schabi.newpipe.player.helper.LockManager;
|
import org.schabi.newpipe.player.helper.LockManager;
|
||||||
import org.schabi.newpipe.player.helper.PlayerHelper;
|
import org.schabi.newpipe.player.helper.PlayerHelper;
|
||||||
import org.schabi.newpipe.player.old.PlayVideoActivity;
|
import org.schabi.newpipe.player.old.PlayVideoActivity;
|
||||||
import org.schabi.newpipe.player.playqueue.PlayQueueItem;
|
import org.schabi.newpipe.player.resolver.MediaSourceTag;
|
||||||
|
import org.schabi.newpipe.player.resolver.VideoPlaybackResolver;
|
||||||
import org.schabi.newpipe.util.ListHelper;
|
import org.schabi.newpipe.util.ListHelper;
|
||||||
import org.schabi.newpipe.util.NavigationHelper;
|
import org.schabi.newpipe.util.NavigationHelper;
|
||||||
import org.schabi.newpipe.util.ThemeHelper;
|
import org.schabi.newpipe.util.ThemeHelper;
|
||||||
|
@ -98,6 +98,11 @@ public final class PopupVideoPlayer extends Service {
|
||||||
|
|
||||||
private static final int MINIMUM_SHOW_EXTRA_WIDTH_DP = 300;
|
private static final int MINIMUM_SHOW_EXTRA_WIDTH_DP = 300;
|
||||||
|
|
||||||
|
private static final int IDLE_WINDOW_FLAGS = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
|
||||||
|
WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
|
||||||
|
private static final int ONGOING_PLAYBACK_WINDOW_FLAGS = IDLE_WINDOW_FLAGS |
|
||||||
|
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
|
||||||
|
|
||||||
private WindowManager windowManager;
|
private WindowManager windowManager;
|
||||||
private WindowManager.LayoutParams windowLayoutParams;
|
private WindowManager.LayoutParams windowLayoutParams;
|
||||||
private GestureDetector gestureDetector;
|
private GestureDetector gestureDetector;
|
||||||
|
@ -191,14 +196,17 @@ public final class PopupVideoPlayer extends Service {
|
||||||
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
popupWidth = popupRememberSizeAndPos ? sharedPreferences.getFloat(POPUP_SAVED_WIDTH, defaultSize) : defaultSize;
|
popupWidth = popupRememberSizeAndPos ? sharedPreferences.getFloat(POPUP_SAVED_WIDTH, defaultSize) : defaultSize;
|
||||||
|
|
||||||
final int layoutParamType = Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.O ? WindowManager.LayoutParams.TYPE_PHONE : WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
|
final int layoutParamType = Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.O ?
|
||||||
|
WindowManager.LayoutParams.TYPE_PHONE :
|
||||||
|
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
|
||||||
|
|
||||||
windowLayoutParams = new WindowManager.LayoutParams(
|
windowLayoutParams = new WindowManager.LayoutParams(
|
||||||
(int) popupWidth, (int) getMinimumVideoHeight(popupWidth),
|
(int) popupWidth, (int) getMinimumVideoHeight(popupWidth),
|
||||||
layoutParamType,
|
layoutParamType,
|
||||||
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
|
IDLE_WINDOW_FLAGS,
|
||||||
PixelFormat.TRANSLUCENT);
|
PixelFormat.TRANSLUCENT);
|
||||||
windowLayoutParams.gravity = Gravity.LEFT | Gravity.TOP;
|
windowLayoutParams.gravity = Gravity.LEFT | Gravity.TOP;
|
||||||
|
windowLayoutParams.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
|
||||||
|
|
||||||
int centerX = (int) (screenWidth / 2f - popupWidth / 2f);
|
int centerX = (int) (screenWidth / 2f - popupWidth / 2f);
|
||||||
int centerY = (int) (screenHeight / 2f - popupHeight / 2f);
|
int centerY = (int) (screenHeight / 2f - popupHeight / 2f);
|
||||||
|
@ -228,6 +236,7 @@ public final class PopupVideoPlayer extends Service {
|
||||||
|
|
||||||
notRemoteView.setTextViewText(R.id.notificationSongName, playerImpl.getVideoTitle());
|
notRemoteView.setTextViewText(R.id.notificationSongName, playerImpl.getVideoTitle());
|
||||||
notRemoteView.setTextViewText(R.id.notificationArtist, playerImpl.getUploaderName());
|
notRemoteView.setTextViewText(R.id.notificationArtist, playerImpl.getUploaderName());
|
||||||
|
notRemoteView.setImageViewBitmap(R.id.notificationCover, playerImpl.getThumbnail());
|
||||||
|
|
||||||
notRemoteView.setOnClickPendingIntent(R.id.notificationPlayPause,
|
notRemoteView.setOnClickPendingIntent(R.id.notificationPlayPause,
|
||||||
PendingIntent.getBroadcast(this, NOTIFICATION_ID, new Intent(ACTION_PLAY_PAUSE), PendingIntent.FLAG_UPDATE_CURRENT));
|
PendingIntent.getBroadcast(this, NOTIFICATION_ID, new Intent(ACTION_PLAY_PAUSE), PendingIntent.FLAG_UPDATE_CURRENT));
|
||||||
|
@ -243,11 +252,15 @@ public final class PopupVideoPlayer extends Service {
|
||||||
|
|
||||||
setRepeatModeRemote(notRemoteView, playerImpl.getRepeatMode());
|
setRepeatModeRemote(notRemoteView, playerImpl.getRepeatMode());
|
||||||
|
|
||||||
return new NotificationCompat.Builder(this, getString(R.string.notification_channel_id))
|
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, getString(R.string.notification_channel_id))
|
||||||
.setOngoing(true)
|
.setOngoing(true)
|
||||||
.setSmallIcon(R.drawable.ic_newpipe_triangle_white)
|
.setSmallIcon(R.drawable.ic_newpipe_triangle_white)
|
||||||
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
||||||
.setContent(notRemoteView);
|
.setContent(notRemoteView);
|
||||||
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
|
||||||
|
builder.setPriority(NotificationCompat.PRIORITY_MAX);
|
||||||
|
}
|
||||||
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -366,6 +379,12 @@ public final class PopupVideoPlayer extends Service {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateWindowFlags(final int flags) {
|
||||||
|
if (windowLayoutParams == null || windowManager == null || playerImpl == null) return;
|
||||||
|
|
||||||
|
windowLayoutParams.flags = flags;
|
||||||
|
windowManager.updateViewLayout(playerImpl.getRootView(), windowLayoutParams);
|
||||||
|
}
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
protected class VideoPlayerImpl extends VideoPlayer implements View.OnLayoutChangeListener {
|
protected class VideoPlayerImpl extends VideoPlayer implements View.OnLayoutChangeListener {
|
||||||
|
@ -428,21 +447,6 @@ public final class PopupVideoPlayer extends Service {
|
||||||
super.destroy();
|
super.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
|
|
||||||
super.onLoadingComplete(imageUri, view, loadedImage);
|
|
||||||
if (loadedImage != null) {
|
|
||||||
// rebuild notification here since remote view does not release bitmaps, causing memory leaks
|
|
||||||
notBuilder = createNotification();
|
|
||||||
|
|
||||||
if (notRemoteView != null) {
|
|
||||||
notRemoteView.setImageViewBitmap(R.id.notificationCover, loadedImage);
|
|
||||||
}
|
|
||||||
|
|
||||||
updateNotification(-1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFullScreenButtonClicked() {
|
public void onFullScreenButtonClicked() {
|
||||||
super.onFullScreenButtonClicked();
|
super.onFullScreenButtonClicked();
|
||||||
|
@ -459,6 +463,7 @@ public final class PopupVideoPlayer extends Service {
|
||||||
this.getRepeatMode(),
|
this.getRepeatMode(),
|
||||||
this.getPlaybackSpeed(),
|
this.getPlaybackSpeed(),
|
||||||
this.getPlaybackPitch(),
|
this.getPlaybackPitch(),
|
||||||
|
this.getPlaybackSkipSilence(),
|
||||||
this.getPlaybackQuality()
|
this.getPlaybackQuality()
|
||||||
);
|
);
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
@ -510,14 +515,47 @@ public final class PopupVideoPlayer extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getDefaultResolutionIndex(final List<VideoStream> sortedVideos) {
|
protected VideoPlaybackResolver.QualityResolver getQualityResolver() {
|
||||||
|
return new VideoPlaybackResolver.QualityResolver() {
|
||||||
|
@Override
|
||||||
|
public int getDefaultResolutionIndex(List<VideoStream> sortedVideos) {
|
||||||
return ListHelper.getPopupDefaultResolutionIndex(context, sortedVideos);
|
return ListHelper.getPopupDefaultResolutionIndex(context, sortedVideos);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getOverrideResolutionIndex(final List<VideoStream> sortedVideos,
|
public int getOverrideResolutionIndex(List<VideoStream> sortedVideos,
|
||||||
final String playbackQuality) {
|
String playbackQuality) {
|
||||||
return ListHelper.getPopupResolutionIndex(context, sortedVideos, playbackQuality);
|
return ListHelper.getPopupResolutionIndex(context, sortedVideos,
|
||||||
|
playbackQuality);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
// Thumbnail Loading
|
||||||
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
|
||||||
|
super.onLoadingComplete(imageUri, view, loadedImage);
|
||||||
|
// rebuild notification here since remote view does not release bitmaps,
|
||||||
|
// causing memory leaks
|
||||||
|
resetNotification();
|
||||||
|
updateNotification(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
|
||||||
|
super.onLoadingFailed(imageUri, view, failReason);
|
||||||
|
resetNotification();
|
||||||
|
updateNotification(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLoadingCancelled(String imageUri, View view) {
|
||||||
|
super.onLoadingCancelled(imageUri, view);
|
||||||
|
resetNotification();
|
||||||
|
updateNotification(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -538,8 +576,8 @@ public final class PopupVideoPlayer extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateMetadata() {
|
private void updateMetadata() {
|
||||||
if (activityListener != null && currentInfo != null) {
|
if (activityListener != null && getCurrentMetadata() != null) {
|
||||||
activityListener.onMetadataUpdate(currentInfo);
|
activityListener.onMetadataUpdate(getCurrentMetadata().getMetadata());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -571,8 +609,9 @@ public final class PopupVideoPlayer extends Service {
|
||||||
public void onRepeatModeChanged(int i) {
|
public void onRepeatModeChanged(int i) {
|
||||||
super.onRepeatModeChanged(i);
|
super.onRepeatModeChanged(i);
|
||||||
setRepeatModeRemote(notRemoteView, i);
|
setRepeatModeRemote(notRemoteView, i);
|
||||||
updateNotification(-1);
|
|
||||||
updatePlayback();
|
updatePlayback();
|
||||||
|
resetNotification();
|
||||||
|
updateNotification(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -585,11 +624,10 @@ public final class PopupVideoPlayer extends Service {
|
||||||
// Playback Listener
|
// Playback Listener
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
protected void onMetadataChanged(@NonNull final PlayQueueItem item,
|
protected void onMetadataChanged(@NonNull final MediaSourceTag tag) {
|
||||||
@Nullable final StreamInfo info,
|
super.onMetadataChanged(tag);
|
||||||
final int newPlayQueueIndex,
|
resetNotification();
|
||||||
final boolean hasPlayQueueItemChanged) {
|
updateNotification(-1);
|
||||||
super.onMetadataChanged(item, info, newPlayQueueIndex, false);
|
|
||||||
updateMetadata();
|
updateMetadata();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -652,56 +690,70 @@ public final class PopupVideoPlayer extends Service {
|
||||||
@Override
|
@Override
|
||||||
public void onBlocked() {
|
public void onBlocked() {
|
||||||
super.onBlocked();
|
super.onBlocked();
|
||||||
|
resetNotification();
|
||||||
updateNotification(R.drawable.ic_play_arrow_white);
|
updateNotification(R.drawable.ic_play_arrow_white);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlaying() {
|
public void onPlaying() {
|
||||||
super.onPlaying();
|
super.onPlaying();
|
||||||
updateNotification(R.drawable.ic_pause_white);
|
|
||||||
videoPlayPause.setBackgroundResource(R.drawable.ic_pause_white);
|
|
||||||
lockManager.acquireWifiAndCpu();
|
|
||||||
|
|
||||||
|
updateWindowFlags(ONGOING_PLAYBACK_WINDOW_FLAGS);
|
||||||
|
|
||||||
|
resetNotification();
|
||||||
|
updateNotification(R.drawable.ic_pause_white);
|
||||||
|
|
||||||
|
videoPlayPause.setBackgroundResource(R.drawable.ic_pause_white);
|
||||||
hideControls(DEFAULT_CONTROLS_DURATION, DEFAULT_CONTROLS_HIDE_TIME);
|
hideControls(DEFAULT_CONTROLS_DURATION, DEFAULT_CONTROLS_HIDE_TIME);
|
||||||
|
|
||||||
windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
|
startForeground(NOTIFICATION_ID, notBuilder.build());
|
||||||
| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
|
lockManager.acquireWifiAndCpu();
|
||||||
windowManager.updateViewLayout(playerImpl.getRootView(), windowLayoutParams);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBuffering() {
|
public void onBuffering() {
|
||||||
super.onBuffering();
|
super.onBuffering();
|
||||||
|
resetNotification();
|
||||||
updateNotification(R.drawable.ic_play_arrow_white);
|
updateNotification(R.drawable.ic_play_arrow_white);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPaused() {
|
public void onPaused() {
|
||||||
super.onPaused();
|
super.onPaused();
|
||||||
|
|
||||||
|
updateWindowFlags(IDLE_WINDOW_FLAGS);
|
||||||
|
|
||||||
|
resetNotification();
|
||||||
updateNotification(R.drawable.ic_play_arrow_white);
|
updateNotification(R.drawable.ic_play_arrow_white);
|
||||||
|
|
||||||
videoPlayPause.setBackgroundResource(R.drawable.ic_play_arrow_white);
|
videoPlayPause.setBackgroundResource(R.drawable.ic_play_arrow_white);
|
||||||
lockManager.releaseWifiAndCpu();
|
lockManager.releaseWifiAndCpu();
|
||||||
|
|
||||||
windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
|
stopForeground(false);
|
||||||
windowManager.updateViewLayout(playerImpl.getRootView(), windowLayoutParams);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPausedSeek() {
|
public void onPausedSeek() {
|
||||||
super.onPausedSeek();
|
super.onPausedSeek();
|
||||||
videoPlayPause.setBackgroundResource(R.drawable.ic_pause_white);
|
resetNotification();
|
||||||
updateNotification(R.drawable.ic_play_arrow_white);
|
updateNotification(R.drawable.ic_play_arrow_white);
|
||||||
|
|
||||||
|
videoPlayPause.setBackgroundResource(R.drawable.ic_pause_white);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCompleted() {
|
public void onCompleted() {
|
||||||
super.onCompleted();
|
super.onCompleted();
|
||||||
|
|
||||||
|
updateWindowFlags(IDLE_WINDOW_FLAGS);
|
||||||
|
|
||||||
|
resetNotification();
|
||||||
updateNotification(R.drawable.ic_replay_white);
|
updateNotification(R.drawable.ic_replay_white);
|
||||||
|
|
||||||
videoPlayPause.setBackgroundResource(R.drawable.ic_replay_white);
|
videoPlayPause.setBackgroundResource(R.drawable.ic_replay_white);
|
||||||
lockManager.releaseWifiAndCpu();
|
lockManager.releaseWifiAndCpu();
|
||||||
|
|
||||||
windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
|
stopForeground(false);
|
||||||
windowManager.updateViewLayout(playerImpl.getRootView(), windowLayoutParams);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -719,16 +771,15 @@ public final class PopupVideoPlayer extends Service {
|
||||||
super.hideControlsAndButton(duration, delay, videoPlayPause);
|
super.hideControlsAndButton(duration, delay, videoPlayPause);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
// Utils
|
// Utils
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
/*package-private*/ void enableVideoRenderer(final boolean enable) {
|
/*package-private*/ void enableVideoRenderer(final boolean enable) {
|
||||||
final int videoRendererIndex = getRendererIndex(C.TRACK_TYPE_VIDEO);
|
final int videoRendererIndex = getRendererIndex(C.TRACK_TYPE_VIDEO);
|
||||||
if (trackSelector != null && videoRendererIndex != RENDERER_UNAVAILABLE) {
|
if (videoRendererIndex != RENDERER_UNAVAILABLE) {
|
||||||
trackSelector.setRendererDisabled(videoRendererIndex, !enable);
|
trackSelector.setParameters(trackSelector.buildUponParameters()
|
||||||
|
.setRendererDisabled(videoRendererIndex, !enable));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -187,6 +187,7 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
|
||||||
this.player.getRepeatMode(),
|
this.player.getRepeatMode(),
|
||||||
this.player.getPlaybackSpeed(),
|
this.player.getPlaybackSpeed(),
|
||||||
this.player.getPlaybackPitch(),
|
this.player.getPlaybackPitch(),
|
||||||
|
this.player.getPlaybackSkipSilence(),
|
||||||
null
|
null
|
||||||
).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
}
|
}
|
||||||
|
@ -466,13 +467,16 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
|
||||||
|
|
||||||
private void openPlaybackParameterDialog() {
|
private void openPlaybackParameterDialog() {
|
||||||
if (player == null) return;
|
if (player == null) return;
|
||||||
PlaybackParameterDialog.newInstance(player.getPlaybackSpeed(),
|
PlaybackParameterDialog.newInstance(player.getPlaybackSpeed(), player.getPlaybackPitch(),
|
||||||
player.getPlaybackPitch()).show(getSupportFragmentManager(), getTag());
|
player.getPlaybackSkipSilence()).show(getSupportFragmentManager(), getTag());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlaybackParameterChanged(float playbackTempo, float playbackPitch) {
|
public void onPlaybackParameterChanged(float playbackTempo, float playbackPitch,
|
||||||
if (player != null) player.setPlaybackParameters(playbackTempo, playbackPitch);
|
boolean playbackSkipSilence) {
|
||||||
|
if (player != null) {
|
||||||
|
player.setPlaybackParameters(playbackTempo, playbackPitch, playbackSkipSilence);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -29,7 +29,6 @@ import android.content.Intent;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.PorterDuff;
|
import android.graphics.PorterDuff;
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
@ -47,11 +46,9 @@ import android.widget.SeekBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
import com.google.android.exoplayer2.Format;
|
|
||||||
import com.google.android.exoplayer2.PlaybackParameters;
|
import com.google.android.exoplayer2.PlaybackParameters;
|
||||||
import com.google.android.exoplayer2.Player;
|
import com.google.android.exoplayer2.Player;
|
||||||
import com.google.android.exoplayer2.source.MediaSource;
|
import com.google.android.exoplayer2.source.MediaSource;
|
||||||
import com.google.android.exoplayer2.source.MergingMediaSource;
|
|
||||||
import com.google.android.exoplayer2.source.TrackGroup;
|
import com.google.android.exoplayer2.source.TrackGroup;
|
||||||
import com.google.android.exoplayer2.source.TrackGroupArray;
|
import com.google.android.exoplayer2.source.TrackGroupArray;
|
||||||
import com.google.android.exoplayer2.text.CaptionStyleCompat;
|
import com.google.android.exoplayer2.text.CaptionStyleCompat;
|
||||||
|
@ -62,21 +59,17 @@ import com.google.android.exoplayer2.video.VideoListener;
|
||||||
|
|
||||||
import org.schabi.newpipe.R;
|
import org.schabi.newpipe.R;
|
||||||
import org.schabi.newpipe.extractor.MediaFormat;
|
import org.schabi.newpipe.extractor.MediaFormat;
|
||||||
import org.schabi.newpipe.extractor.Subtitles;
|
|
||||||
import org.schabi.newpipe.extractor.stream.AudioStream;
|
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamType;
|
|
||||||
import org.schabi.newpipe.extractor.stream.VideoStream;
|
import org.schabi.newpipe.extractor.stream.VideoStream;
|
||||||
import org.schabi.newpipe.player.helper.PlayerHelper;
|
import org.schabi.newpipe.player.helper.PlayerHelper;
|
||||||
import org.schabi.newpipe.player.playqueue.PlayQueueItem;
|
import org.schabi.newpipe.player.playqueue.PlayQueueItem;
|
||||||
|
import org.schabi.newpipe.player.resolver.MediaSourceTag;
|
||||||
|
import org.schabi.newpipe.player.resolver.VideoPlaybackResolver;
|
||||||
import org.schabi.newpipe.util.AnimationUtils;
|
import org.schabi.newpipe.util.AnimationUtils;
|
||||||
import org.schabi.newpipe.util.ListHelper;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static com.google.android.exoplayer2.C.SELECTION_FLAG_AUTOSELECT;
|
|
||||||
import static com.google.android.exoplayer2.C.TIME_UNSET;
|
|
||||||
import static org.schabi.newpipe.player.helper.PlayerHelper.formatSpeed;
|
import static org.schabi.newpipe.player.helper.PlayerHelper.formatSpeed;
|
||||||
import static org.schabi.newpipe.player.helper.PlayerHelper.getTimeString;
|
import static org.schabi.newpipe.player.helper.PlayerHelper.getTimeString;
|
||||||
import static org.schabi.newpipe.util.AnimationUtils.animateView;
|
import static org.schabi.newpipe.util.AnimationUtils.animateView;
|
||||||
|
@ -105,13 +98,12 @@ public abstract class VideoPlayer extends BasePlayer
|
||||||
public static final int DEFAULT_CONTROLS_DURATION = 300; // 300 millis
|
public static final int DEFAULT_CONTROLS_DURATION = 300; // 300 millis
|
||||||
public static final int DEFAULT_CONTROLS_HIDE_TIME = 2000; // 2 Seconds
|
public static final int DEFAULT_CONTROLS_HIDE_TIME = 2000; // 2 Seconds
|
||||||
|
|
||||||
private ArrayList<VideoStream> availableStreams;
|
private List<VideoStream> availableStreams;
|
||||||
private int selectedStreamIndex;
|
private int selectedStreamIndex;
|
||||||
|
|
||||||
protected String playbackQuality;
|
|
||||||
|
|
||||||
protected boolean wasPlaying = false;
|
protected boolean wasPlaying = false;
|
||||||
|
|
||||||
|
@NonNull final private VideoPlaybackResolver resolver;
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
// Views
|
// Views
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
@ -162,6 +154,7 @@ public abstract class VideoPlayer extends BasePlayer
|
||||||
public VideoPlayer(String debugTag, Context context) {
|
public VideoPlayer(String debugTag, Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
this.TAG = debugTag;
|
this.TAG = debugTag;
|
||||||
|
this.resolver = new VideoPlaybackResolver(context, dataSource, getQualityResolver());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setup(View rootView) {
|
public void setup(View rootView) {
|
||||||
|
@ -241,7 +234,8 @@ public abstract class VideoPlayer extends BasePlayer
|
||||||
|
|
||||||
// Setup audio session with onboard equalizer
|
// Setup audio session with onboard equalizer
|
||||||
if (Build.VERSION.SDK_INT >= 21) {
|
if (Build.VERSION.SDK_INT >= 21) {
|
||||||
trackSelector.setTunnelingAudioSessionId(C.generateAudioSessionIdV21(context));
|
trackSelector.setParameters(trackSelector.buildUponParameters()
|
||||||
|
.setTunnelingAudioSessionId(C.generateAudioSessionIdV21(context)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -297,8 +291,9 @@ public abstract class VideoPlayer extends BasePlayer
|
||||||
0, Menu.NONE, R.string.caption_none);
|
0, Menu.NONE, R.string.caption_none);
|
||||||
captionOffItem.setOnMenuItemClickListener(menuItem -> {
|
captionOffItem.setOnMenuItemClickListener(menuItem -> {
|
||||||
final int textRendererIndex = getRendererIndex(C.TRACK_TYPE_TEXT);
|
final int textRendererIndex = getRendererIndex(C.TRACK_TYPE_TEXT);
|
||||||
if (trackSelector != null && textRendererIndex != RENDERER_UNAVAILABLE) {
|
if (textRendererIndex != RENDERER_UNAVAILABLE) {
|
||||||
trackSelector.setRendererDisabled(textRendererIndex, true);
|
trackSelector.setParameters(trackSelector.buildUponParameters()
|
||||||
|
.setRendererDisabled(textRendererIndex, true));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
@ -310,68 +305,61 @@ public abstract class VideoPlayer extends BasePlayer
|
||||||
i + 1, Menu.NONE, captionLanguage);
|
i + 1, Menu.NONE, captionLanguage);
|
||||||
captionItem.setOnMenuItemClickListener(menuItem -> {
|
captionItem.setOnMenuItemClickListener(menuItem -> {
|
||||||
final int textRendererIndex = getRendererIndex(C.TRACK_TYPE_TEXT);
|
final int textRendererIndex = getRendererIndex(C.TRACK_TYPE_TEXT);
|
||||||
if (trackSelector != null && textRendererIndex != RENDERER_UNAVAILABLE) {
|
if (textRendererIndex != RENDERER_UNAVAILABLE) {
|
||||||
trackSelector.setPreferredTextLanguage(captionLanguage);
|
trackSelector.setPreferredTextLanguage(captionLanguage);
|
||||||
trackSelector.setRendererDisabled(textRendererIndex, false);
|
trackSelector.setParameters(trackSelector.buildUponParameters()
|
||||||
|
.setRendererDisabled(textRendererIndex, false));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
captionPopupMenu.setOnDismissListener(this);
|
captionPopupMenu.setOnDismissListener(this);
|
||||||
}
|
}
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
|
||||||
// Playback Listener
|
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
|
||||||
|
|
||||||
protected abstract int getDefaultResolutionIndex(final List<VideoStream> sortedVideos);
|
|
||||||
|
|
||||||
protected abstract int getOverrideResolutionIndex(final List<VideoStream> sortedVideos, final String playbackQuality);
|
private void updateStreamRelatedViews() {
|
||||||
|
if (getCurrentMetadata() == null) return;
|
||||||
|
|
||||||
|
final MediaSourceTag tag = getCurrentMetadata();
|
||||||
|
final StreamInfo metadata = tag.getMetadata();
|
||||||
|
|
||||||
protected void onMetadataChanged(@NonNull final PlayQueueItem item,
|
|
||||||
@Nullable final StreamInfo info,
|
|
||||||
final int newPlayQueueIndex,
|
|
||||||
final boolean hasPlayQueueItemChanged) {
|
|
||||||
qualityTextView.setVisibility(View.GONE);
|
qualityTextView.setVisibility(View.GONE);
|
||||||
playbackSpeedTextView.setVisibility(View.GONE);
|
playbackSpeedTextView.setVisibility(View.GONE);
|
||||||
|
|
||||||
playbackEndTime.setVisibility(View.GONE);
|
playbackEndTime.setVisibility(View.GONE);
|
||||||
playbackLiveSync.setVisibility(View.GONE);
|
playbackLiveSync.setVisibility(View.GONE);
|
||||||
|
|
||||||
final StreamType streamType = info == null ? StreamType.NONE : info.getStreamType();
|
switch (metadata.getStreamType()) {
|
||||||
|
|
||||||
switch (streamType) {
|
|
||||||
case AUDIO_STREAM:
|
case AUDIO_STREAM:
|
||||||
surfaceView.setVisibility(View.GONE);
|
surfaceView.setVisibility(View.GONE);
|
||||||
|
endScreen.setVisibility(View.VISIBLE);
|
||||||
playbackEndTime.setVisibility(View.VISIBLE);
|
playbackEndTime.setVisibility(View.VISIBLE);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AUDIO_LIVE_STREAM:
|
case AUDIO_LIVE_STREAM:
|
||||||
surfaceView.setVisibility(View.GONE);
|
surfaceView.setVisibility(View.GONE);
|
||||||
|
endScreen.setVisibility(View.VISIBLE);
|
||||||
playbackLiveSync.setVisibility(View.VISIBLE);
|
playbackLiveSync.setVisibility(View.VISIBLE);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LIVE_STREAM:
|
case LIVE_STREAM:
|
||||||
surfaceView.setVisibility(View.VISIBLE);
|
surfaceView.setVisibility(View.VISIBLE);
|
||||||
|
endScreen.setVisibility(View.GONE);
|
||||||
playbackLiveSync.setVisibility(View.VISIBLE);
|
playbackLiveSync.setVisibility(View.VISIBLE);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VIDEO_STREAM:
|
case VIDEO_STREAM:
|
||||||
if (info.getVideoStreams().size() + info.getVideoOnlyStreams().size() == 0) break;
|
if (metadata.getVideoStreams().size() + metadata.getVideoOnlyStreams().size() == 0)
|
||||||
|
break;
|
||||||
final List<VideoStream> videos = ListHelper.getSortedStreamVideosList(context,
|
|
||||||
info.getVideoStreams(), info.getVideoOnlyStreams(), false);
|
|
||||||
availableStreams = new ArrayList<>(videos);
|
|
||||||
if (playbackQuality == null) {
|
|
||||||
selectedStreamIndex = getDefaultResolutionIndex(videos);
|
|
||||||
} else {
|
|
||||||
selectedStreamIndex = getOverrideResolutionIndex(videos, getPlaybackQuality());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
availableStreams = tag.getSortedAvailableVideoStreams();
|
||||||
|
selectedStreamIndex = tag.getSelectedVideoStreamIndex();
|
||||||
buildQualityMenu();
|
buildQualityMenu();
|
||||||
qualityTextView.setVisibility(View.VISIBLE);
|
|
||||||
|
|
||||||
|
qualityTextView.setVisibility(View.VISIBLE);
|
||||||
surfaceView.setVisibility(View.VISIBLE);
|
surfaceView.setVisibility(View.VISIBLE);
|
||||||
default:
|
default:
|
||||||
|
endScreen.setVisibility(View.GONE);
|
||||||
playbackEndTime.setVisibility(View.VISIBLE);
|
playbackEndTime.setVisibility(View.VISIBLE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -379,69 +367,21 @@ public abstract class VideoPlayer extends BasePlayer
|
||||||
buildPlaybackSpeedMenu();
|
buildPlaybackSpeedMenu();
|
||||||
playbackSpeedTextView.setVisibility(View.VISIBLE);
|
playbackSpeedTextView.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
// Playback Listener
|
||||||
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
protected abstract VideoPlaybackResolver.QualityResolver getQualityResolver();
|
||||||
|
|
||||||
|
protected void onMetadataChanged(@NonNull final MediaSourceTag tag) {
|
||||||
|
super.onMetadataChanged(tag);
|
||||||
|
updateStreamRelatedViews();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public MediaSource sourceOf(final PlayQueueItem item, final StreamInfo info) {
|
public MediaSource sourceOf(final PlayQueueItem item, final StreamInfo info) {
|
||||||
final MediaSource liveSource = super.sourceOf(item, info);
|
return resolver.resolve(info);
|
||||||
if (liveSource != null) return liveSource;
|
|
||||||
|
|
||||||
List<MediaSource> mediaSources = new ArrayList<>();
|
|
||||||
|
|
||||||
// Create video stream source
|
|
||||||
final List<VideoStream> videos = ListHelper.getSortedStreamVideosList(context,
|
|
||||||
info.getVideoStreams(), info.getVideoOnlyStreams(), false);
|
|
||||||
final int index;
|
|
||||||
if (videos.isEmpty()) {
|
|
||||||
index = -1;
|
|
||||||
} else if (playbackQuality == null) {
|
|
||||||
index = getDefaultResolutionIndex(videos);
|
|
||||||
} else {
|
|
||||||
index = getOverrideResolutionIndex(videos, getPlaybackQuality());
|
|
||||||
}
|
|
||||||
final VideoStream video = index >= 0 && index < videos.size() ? videos.get(index) : null;
|
|
||||||
if (video != null) {
|
|
||||||
final MediaSource streamSource = buildMediaSource(video.getUrl(),
|
|
||||||
PlayerHelper.cacheKeyOf(info, video),
|
|
||||||
MediaFormat.getSuffixById(video.getFormatId()));
|
|
||||||
mediaSources.add(streamSource);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create optional audio stream source
|
|
||||||
final List<AudioStream> audioStreams = info.getAudioStreams();
|
|
||||||
final AudioStream audio = audioStreams.isEmpty() ? null : audioStreams.get(
|
|
||||||
ListHelper.getDefaultAudioFormat(context, audioStreams));
|
|
||||||
// Use the audio stream if there is no video stream, or
|
|
||||||
// Merge with audio stream in case if video does not contain audio
|
|
||||||
if (audio != null && ((video != null && video.isVideoOnly) || video == null)) {
|
|
||||||
final MediaSource audioSource = buildMediaSource(audio.getUrl(),
|
|
||||||
PlayerHelper.cacheKeyOf(info, audio),
|
|
||||||
MediaFormat.getSuffixById(audio.getFormatId()));
|
|
||||||
mediaSources.add(audioSource);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If there is no audio or video sources, then this media source cannot be played back
|
|
||||||
if (mediaSources.isEmpty()) return null;
|
|
||||||
// Below are auxiliary media sources
|
|
||||||
|
|
||||||
// Create subtitle sources
|
|
||||||
for (final Subtitles subtitle : info.getSubtitles()) {
|
|
||||||
final String mimeType = PlayerHelper.mimeTypesOf(subtitle.getFileType());
|
|
||||||
if (mimeType == null) continue;
|
|
||||||
|
|
||||||
final Format textFormat = Format.createTextSampleFormat(null, mimeType,
|
|
||||||
SELECTION_FLAG_AUTOSELECT, PlayerHelper.captionLanguageOf(context, subtitle));
|
|
||||||
final MediaSource textSource = dataSource.getSampleMediaSourceFactory()
|
|
||||||
.createMediaSource(Uri.parse(subtitle.getURL()), textFormat, TIME_UNSET);
|
|
||||||
mediaSources.add(textSource);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mediaSources.size() == 1) {
|
|
||||||
return mediaSources.get(0);
|
|
||||||
} else {
|
|
||||||
return new MergingMediaSource(mediaSources.toArray(
|
|
||||||
new MediaSource[mediaSources.size()]));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -460,7 +400,6 @@ public abstract class VideoPlayer extends BasePlayer
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
|
||||||
playbackSeekBar.getThumb().setColorFilter(Color.RED, PorterDuff.Mode.SRC_IN);
|
playbackSeekBar.getThumb().setColorFilter(Color.RED, PorterDuff.Mode.SRC_IN);
|
||||||
|
|
||||||
animateView(endScreen, false, 0);
|
|
||||||
loadingPanel.setBackgroundColor(Color.BLACK);
|
loadingPanel.setBackgroundColor(Color.BLACK);
|
||||||
animateView(loadingPanel, true, 0);
|
animateView(loadingPanel, true, 0);
|
||||||
animateView(surfaceForeground, true, 100);
|
animateView(surfaceForeground, true, 100);
|
||||||
|
@ -470,6 +409,8 @@ public abstract class VideoPlayer extends BasePlayer
|
||||||
public void onPlaying() {
|
public void onPlaying() {
|
||||||
super.onPlaying();
|
super.onPlaying();
|
||||||
|
|
||||||
|
updateStreamRelatedViews();
|
||||||
|
|
||||||
showAndAnimateControl(-1, true);
|
showAndAnimateControl(-1, true);
|
||||||
|
|
||||||
playbackSeekBar.setEnabled(true);
|
playbackSeekBar.setEnabled(true);
|
||||||
|
@ -480,14 +421,12 @@ public abstract class VideoPlayer extends BasePlayer
|
||||||
loadingPanel.setVisibility(View.GONE);
|
loadingPanel.setVisibility(View.GONE);
|
||||||
|
|
||||||
animateView(currentDisplaySeek, AnimationUtils.Type.SCALE_AND_ALPHA, false, 200);
|
animateView(currentDisplaySeek, AnimationUtils.Type.SCALE_AND_ALPHA, false, 200);
|
||||||
animateView(endScreen, false, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBuffering() {
|
public void onBuffering() {
|
||||||
if (DEBUG) Log.d(TAG, "onBuffering() called");
|
if (DEBUG) Log.d(TAG, "onBuffering() called");
|
||||||
loadingPanel.setBackgroundColor(Color.TRANSPARENT);
|
loadingPanel.setBackgroundColor(Color.TRANSPARENT);
|
||||||
animateView(loadingPanel, true, 500);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -552,8 +491,7 @@ public abstract class VideoPlayer extends BasePlayer
|
||||||
final int textRenderer = getRendererIndex(C.TRACK_TYPE_TEXT);
|
final int textRenderer = getRendererIndex(C.TRACK_TYPE_TEXT);
|
||||||
|
|
||||||
if (captionTextView == null) return;
|
if (captionTextView == null) return;
|
||||||
if (trackSelector == null || trackSelector.getCurrentMappedTrackInfo() == null ||
|
if (trackSelector.getCurrentMappedTrackInfo() == null || textRenderer == RENDERER_UNAVAILABLE) {
|
||||||
textRenderer == RENDERER_UNAVAILABLE) {
|
|
||||||
captionTextView.setVisibility(View.GONE);
|
captionTextView.setVisibility(View.GONE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -575,8 +513,8 @@ public abstract class VideoPlayer extends BasePlayer
|
||||||
|
|
||||||
// Build UI
|
// Build UI
|
||||||
buildCaptionMenu(availableLanguages);
|
buildCaptionMenu(availableLanguages);
|
||||||
if (trackSelector.getRendererDisabled(textRenderer) || preferredLanguage == null ||
|
if (trackSelector.getParameters().getRendererDisabled(textRenderer) ||
|
||||||
!availableLanguages.contains(preferredLanguage)) {
|
preferredLanguage == null || !availableLanguages.contains(preferredLanguage)) {
|
||||||
captionTextView.setText(R.string.caption_none);
|
captionTextView.setText(R.string.caption_none);
|
||||||
} else {
|
} else {
|
||||||
captionTextView.setText(preferredLanguage);
|
captionTextView.setText(preferredLanguage);
|
||||||
|
@ -905,11 +843,12 @@ public abstract class VideoPlayer extends BasePlayer
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
public void setPlaybackQuality(final String quality) {
|
public void setPlaybackQuality(final String quality) {
|
||||||
this.playbackQuality = quality;
|
this.resolver.setPlaybackQuality(quality);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public String getPlaybackQuality() {
|
public String getPlaybackQuality() {
|
||||||
return playbackQuality;
|
return resolver.getPlaybackQuality();
|
||||||
}
|
}
|
||||||
|
|
||||||
public AspectRatioFrameLayout getAspectRatioFrameLayout() {
|
public AspectRatioFrameLayout getAspectRatioFrameLayout() {
|
||||||
|
|
|
@ -39,6 +39,9 @@ public class MediaSessionManager {
|
||||||
return MediaButtonReceiver.handleIntent(mediaSession, intent);
|
return MediaButtonReceiver.handleIntent(mediaSession, intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should be called on player destruction to prevent leakage.
|
||||||
|
* */
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
this.sessionConnector.setPlayer(null, null);
|
this.sessionConnector.setPlayer(null, null);
|
||||||
this.sessionConnector.setQueueNavigator(null);
|
this.sessionConnector.setQueueNavigator(null);
|
||||||
|
|
|
@ -21,25 +21,34 @@ import static org.schabi.newpipe.player.BasePlayer.DEBUG;
|
||||||
public class PlaybackParameterDialog extends DialogFragment {
|
public class PlaybackParameterDialog extends DialogFragment {
|
||||||
@NonNull private static final String TAG = "PlaybackParameterDialog";
|
@NonNull private static final String TAG = "PlaybackParameterDialog";
|
||||||
|
|
||||||
public static final double MINIMUM_PLAYBACK_VALUE = 0.25f;
|
// Minimum allowable range in ExoPlayer
|
||||||
|
public static final double MINIMUM_PLAYBACK_VALUE = 0.10f;
|
||||||
public static final double MAXIMUM_PLAYBACK_VALUE = 3.00f;
|
public static final double MAXIMUM_PLAYBACK_VALUE = 3.00f;
|
||||||
|
|
||||||
public static final char STEP_UP_SIGN = '+';
|
public static final char STEP_UP_SIGN = '+';
|
||||||
public static final char STEP_DOWN_SIGN = '-';
|
public static final char STEP_DOWN_SIGN = '-';
|
||||||
public static final double PLAYBACK_STEP_VALUE = 0.05f;
|
|
||||||
|
|
||||||
public static final double NIGHTCORE_TEMPO = 1.20f;
|
public static final double STEP_ONE_PERCENT_VALUE = 0.01f;
|
||||||
public static final double NIGHTCORE_PITCH_LOWER = 1.15f;
|
public static final double STEP_FIVE_PERCENT_VALUE = 0.05f;
|
||||||
public static final double NIGHTCORE_PITCH_UPPER = 1.25f;
|
public static final double STEP_TEN_PERCENT_VALUE = 0.10f;
|
||||||
|
public static final double STEP_TWENTY_FIVE_PERCENT_VALUE = 0.25f;
|
||||||
|
public static final double STEP_ONE_HUNDRED_PERCENT_VALUE = 1.00f;
|
||||||
|
|
||||||
public static final double DEFAULT_TEMPO = 1.00f;
|
public static final double DEFAULT_TEMPO = 1.00f;
|
||||||
public static final double DEFAULT_PITCH = 1.00f;
|
public static final double DEFAULT_PITCH = 1.00f;
|
||||||
|
public static final double DEFAULT_STEP = STEP_TWENTY_FIVE_PERCENT_VALUE;
|
||||||
|
public static final boolean DEFAULT_SKIP_SILENCE = false;
|
||||||
|
|
||||||
@NonNull private static final String INITIAL_TEMPO_KEY = "initial_tempo_key";
|
@NonNull private static final String INITIAL_TEMPO_KEY = "initial_tempo_key";
|
||||||
@NonNull private static final String INITIAL_PITCH_KEY = "initial_pitch_key";
|
@NonNull private static final String INITIAL_PITCH_KEY = "initial_pitch_key";
|
||||||
|
|
||||||
|
@NonNull private static final String TEMPO_KEY = "tempo_key";
|
||||||
|
@NonNull private static final String PITCH_KEY = "pitch_key";
|
||||||
|
@NonNull private static final String STEP_SIZE_KEY = "step_size_key";
|
||||||
|
|
||||||
public interface Callback {
|
public interface Callback {
|
||||||
void onPlaybackParameterChanged(final float playbackTempo, final float playbackPitch);
|
void onPlaybackParameterChanged(final float playbackTempo, final float playbackPitch,
|
||||||
|
final boolean playbackSkipSilence);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable private Callback callback;
|
@Nullable private Callback callback;
|
||||||
|
@ -50,6 +59,11 @@ public class PlaybackParameterDialog extends DialogFragment {
|
||||||
|
|
||||||
private double initialTempo = DEFAULT_TEMPO;
|
private double initialTempo = DEFAULT_TEMPO;
|
||||||
private double initialPitch = DEFAULT_PITCH;
|
private double initialPitch = DEFAULT_PITCH;
|
||||||
|
private boolean initialSkipSilence = DEFAULT_SKIP_SILENCE;
|
||||||
|
|
||||||
|
private double tempo = DEFAULT_TEMPO;
|
||||||
|
private double pitch = DEFAULT_PITCH;
|
||||||
|
private double stepSize = DEFAULT_STEP;
|
||||||
|
|
||||||
@Nullable private SeekBar tempoSlider;
|
@Nullable private SeekBar tempoSlider;
|
||||||
@Nullable private TextView tempoMinimumText;
|
@Nullable private TextView tempoMinimumText;
|
||||||
|
@ -65,16 +79,26 @@ public class PlaybackParameterDialog extends DialogFragment {
|
||||||
@Nullable private TextView pitchStepDownText;
|
@Nullable private TextView pitchStepDownText;
|
||||||
@Nullable private TextView pitchStepUpText;
|
@Nullable private TextView pitchStepUpText;
|
||||||
|
|
||||||
@Nullable private CheckBox unhookingCheckbox;
|
@Nullable private TextView stepSizeOnePercentText;
|
||||||
|
@Nullable private TextView stepSizeFivePercentText;
|
||||||
|
@Nullable private TextView stepSizeTenPercentText;
|
||||||
|
@Nullable private TextView stepSizeTwentyFivePercentText;
|
||||||
|
@Nullable private TextView stepSizeOneHundredPercentText;
|
||||||
|
|
||||||
@Nullable private TextView nightCorePresetText;
|
@Nullable private CheckBox unhookingCheckbox;
|
||||||
@Nullable private TextView resetPresetText;
|
@Nullable private CheckBox skipSilenceCheckbox;
|
||||||
|
|
||||||
public static PlaybackParameterDialog newInstance(final double playbackTempo,
|
public static PlaybackParameterDialog newInstance(final double playbackTempo,
|
||||||
final double playbackPitch) {
|
final double playbackPitch,
|
||||||
|
final boolean playbackSkipSilence) {
|
||||||
PlaybackParameterDialog dialog = new PlaybackParameterDialog();
|
PlaybackParameterDialog dialog = new PlaybackParameterDialog();
|
||||||
dialog.initialTempo = playbackTempo;
|
dialog.initialTempo = playbackTempo;
|
||||||
dialog.initialPitch = playbackPitch;
|
dialog.initialPitch = playbackPitch;
|
||||||
|
|
||||||
|
dialog.tempo = playbackTempo;
|
||||||
|
dialog.pitch = playbackPitch;
|
||||||
|
|
||||||
|
dialog.initialSkipSilence = playbackSkipSilence;
|
||||||
return dialog;
|
return dialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,6 +122,10 @@ public class PlaybackParameterDialog extends DialogFragment {
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
initialTempo = savedInstanceState.getDouble(INITIAL_TEMPO_KEY, DEFAULT_TEMPO);
|
initialTempo = savedInstanceState.getDouble(INITIAL_TEMPO_KEY, DEFAULT_TEMPO);
|
||||||
initialPitch = savedInstanceState.getDouble(INITIAL_PITCH_KEY, DEFAULT_PITCH);
|
initialPitch = savedInstanceState.getDouble(INITIAL_PITCH_KEY, DEFAULT_PITCH);
|
||||||
|
|
||||||
|
tempo = savedInstanceState.getDouble(TEMPO_KEY, DEFAULT_TEMPO);
|
||||||
|
pitch = savedInstanceState.getDouble(PITCH_KEY, DEFAULT_PITCH);
|
||||||
|
stepSize = savedInstanceState.getDouble(STEP_SIZE_KEY, DEFAULT_STEP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,6 +134,10 @@ public class PlaybackParameterDialog extends DialogFragment {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
outState.putDouble(INITIAL_TEMPO_KEY, initialTempo);
|
outState.putDouble(INITIAL_TEMPO_KEY, initialTempo);
|
||||||
outState.putDouble(INITIAL_PITCH_KEY, initialPitch);
|
outState.putDouble(INITIAL_PITCH_KEY, initialPitch);
|
||||||
|
|
||||||
|
outState.putDouble(TEMPO_KEY, getCurrentTempo());
|
||||||
|
outState.putDouble(PITCH_KEY, getCurrentPitch());
|
||||||
|
outState.putDouble(STEP_SIZE_KEY, getCurrentStepSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -123,7 +155,9 @@ public class PlaybackParameterDialog extends DialogFragment {
|
||||||
.setView(view)
|
.setView(view)
|
||||||
.setCancelable(true)
|
.setCancelable(true)
|
||||||
.setNegativeButton(R.string.cancel, (dialogInterface, i) ->
|
.setNegativeButton(R.string.cancel, (dialogInterface, i) ->
|
||||||
setPlaybackParameters(initialTempo, initialPitch))
|
setPlaybackParameters(initialTempo, initialPitch, initialSkipSilence))
|
||||||
|
.setNeutralButton(R.string.playback_reset, (dialogInterface, i) ->
|
||||||
|
setPlaybackParameters(DEFAULT_TEMPO, DEFAULT_PITCH, DEFAULT_SKIP_SILENCE))
|
||||||
.setPositiveButton(R.string.finish, (dialogInterface, i) ->
|
.setPositiveButton(R.string.finish, (dialogInterface, i) ->
|
||||||
setCurrentPlaybackParameters());
|
setCurrentPlaybackParameters());
|
||||||
|
|
||||||
|
@ -136,9 +170,13 @@ public class PlaybackParameterDialog extends DialogFragment {
|
||||||
|
|
||||||
private void setupControlViews(@NonNull View rootView) {
|
private void setupControlViews(@NonNull View rootView) {
|
||||||
setupHookingControl(rootView);
|
setupHookingControl(rootView);
|
||||||
|
setupSkipSilenceControl(rootView);
|
||||||
|
|
||||||
setupTempoControl(rootView);
|
setupTempoControl(rootView);
|
||||||
setupPitchControl(rootView);
|
setupPitchControl(rootView);
|
||||||
setupPresetControl(rootView);
|
|
||||||
|
changeStepSize(stepSize);
|
||||||
|
setupStepSizeSelector(rootView);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupTempoControl(@NonNull View rootView) {
|
private void setupTempoControl(@NonNull View rootView) {
|
||||||
|
@ -150,31 +188,15 @@ public class PlaybackParameterDialog extends DialogFragment {
|
||||||
tempoStepDownText = rootView.findViewById(R.id.tempoStepDown);
|
tempoStepDownText = rootView.findViewById(R.id.tempoStepDown);
|
||||||
|
|
||||||
if (tempoCurrentText != null)
|
if (tempoCurrentText != null)
|
||||||
tempoCurrentText.setText(PlayerHelper.formatSpeed(initialTempo));
|
tempoCurrentText.setText(PlayerHelper.formatSpeed(tempo));
|
||||||
if (tempoMaximumText != null)
|
if (tempoMaximumText != null)
|
||||||
tempoMaximumText.setText(PlayerHelper.formatSpeed(MAXIMUM_PLAYBACK_VALUE));
|
tempoMaximumText.setText(PlayerHelper.formatSpeed(MAXIMUM_PLAYBACK_VALUE));
|
||||||
if (tempoMinimumText != null)
|
if (tempoMinimumText != null)
|
||||||
tempoMinimumText.setText(PlayerHelper.formatSpeed(MINIMUM_PLAYBACK_VALUE));
|
tempoMinimumText.setText(PlayerHelper.formatSpeed(MINIMUM_PLAYBACK_VALUE));
|
||||||
|
|
||||||
if (tempoStepUpText != null) {
|
|
||||||
tempoStepUpText.setText(getStepUpPercentString(PLAYBACK_STEP_VALUE));
|
|
||||||
tempoStepUpText.setOnClickListener(view -> {
|
|
||||||
onTempoSliderUpdated(getCurrentTempo() + PLAYBACK_STEP_VALUE);
|
|
||||||
setCurrentPlaybackParameters();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tempoStepDownText != null) {
|
|
||||||
tempoStepDownText.setText(getStepDownPercentString(PLAYBACK_STEP_VALUE));
|
|
||||||
tempoStepDownText.setOnClickListener(view -> {
|
|
||||||
onTempoSliderUpdated(getCurrentTempo() - PLAYBACK_STEP_VALUE);
|
|
||||||
setCurrentPlaybackParameters();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tempoSlider != null) {
|
if (tempoSlider != null) {
|
||||||
tempoSlider.setMax(strategy.progressOf(MAXIMUM_PLAYBACK_VALUE));
|
tempoSlider.setMax(strategy.progressOf(MAXIMUM_PLAYBACK_VALUE));
|
||||||
tempoSlider.setProgress(strategy.progressOf(initialTempo));
|
tempoSlider.setProgress(strategy.progressOf(tempo));
|
||||||
tempoSlider.setOnSeekBarChangeListener(getOnTempoChangedListener());
|
tempoSlider.setOnSeekBarChangeListener(getOnTempoChangedListener());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -188,31 +210,15 @@ public class PlaybackParameterDialog extends DialogFragment {
|
||||||
pitchStepUpText = rootView.findViewById(R.id.pitchStepUp);
|
pitchStepUpText = rootView.findViewById(R.id.pitchStepUp);
|
||||||
|
|
||||||
if (pitchCurrentText != null)
|
if (pitchCurrentText != null)
|
||||||
pitchCurrentText.setText(PlayerHelper.formatPitch(initialPitch));
|
pitchCurrentText.setText(PlayerHelper.formatPitch(pitch));
|
||||||
if (pitchMaximumText != null)
|
if (pitchMaximumText != null)
|
||||||
pitchMaximumText.setText(PlayerHelper.formatPitch(MAXIMUM_PLAYBACK_VALUE));
|
pitchMaximumText.setText(PlayerHelper.formatPitch(MAXIMUM_PLAYBACK_VALUE));
|
||||||
if (pitchMinimumText != null)
|
if (pitchMinimumText != null)
|
||||||
pitchMinimumText.setText(PlayerHelper.formatPitch(MINIMUM_PLAYBACK_VALUE));
|
pitchMinimumText.setText(PlayerHelper.formatPitch(MINIMUM_PLAYBACK_VALUE));
|
||||||
|
|
||||||
if (pitchStepUpText != null) {
|
|
||||||
pitchStepUpText.setText(getStepUpPercentString(PLAYBACK_STEP_VALUE));
|
|
||||||
pitchStepUpText.setOnClickListener(view -> {
|
|
||||||
onPitchSliderUpdated(getCurrentPitch() + PLAYBACK_STEP_VALUE);
|
|
||||||
setCurrentPlaybackParameters();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pitchStepDownText != null) {
|
|
||||||
pitchStepDownText.setText(getStepDownPercentString(PLAYBACK_STEP_VALUE));
|
|
||||||
pitchStepDownText.setOnClickListener(view -> {
|
|
||||||
onPitchSliderUpdated(getCurrentPitch() - PLAYBACK_STEP_VALUE);
|
|
||||||
setCurrentPlaybackParameters();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pitchSlider != null) {
|
if (pitchSlider != null) {
|
||||||
pitchSlider.setMax(strategy.progressOf(MAXIMUM_PLAYBACK_VALUE));
|
pitchSlider.setMax(strategy.progressOf(MAXIMUM_PLAYBACK_VALUE));
|
||||||
pitchSlider.setProgress(strategy.progressOf(initialPitch));
|
pitchSlider.setProgress(strategy.progressOf(pitch));
|
||||||
pitchSlider.setOnSeekBarChangeListener(getOnPitchChangedListener());
|
pitchSlider.setOnSeekBarChangeListener(getOnPitchChangedListener());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -220,7 +226,7 @@ public class PlaybackParameterDialog extends DialogFragment {
|
||||||
private void setupHookingControl(@NonNull View rootView) {
|
private void setupHookingControl(@NonNull View rootView) {
|
||||||
unhookingCheckbox = rootView.findViewById(R.id.unhookCheckbox);
|
unhookingCheckbox = rootView.findViewById(R.id.unhookCheckbox);
|
||||||
if (unhookingCheckbox != null) {
|
if (unhookingCheckbox != null) {
|
||||||
unhookingCheckbox.setChecked(initialPitch != initialTempo);
|
unhookingCheckbox.setChecked(pitch != tempo);
|
||||||
unhookingCheckbox.setOnCheckedChangeListener((compoundButton, isChecked) -> {
|
unhookingCheckbox.setOnCheckedChangeListener((compoundButton, isChecked) -> {
|
||||||
if (isChecked) return;
|
if (isChecked) return;
|
||||||
// When unchecked, slide back to the minimum of current tempo or pitch
|
// When unchecked, slide back to the minimum of current tempo or pitch
|
||||||
|
@ -231,24 +237,84 @@ public class PlaybackParameterDialog extends DialogFragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupPresetControl(@NonNull View rootView) {
|
private void setupSkipSilenceControl(@NonNull View rootView) {
|
||||||
nightCorePresetText = rootView.findViewById(R.id.presetNightcore);
|
skipSilenceCheckbox = rootView.findViewById(R.id.skipSilenceCheckbox);
|
||||||
if (nightCorePresetText != null) {
|
if (skipSilenceCheckbox != null) {
|
||||||
nightCorePresetText.setOnClickListener(view -> {
|
skipSilenceCheckbox.setChecked(initialSkipSilence);
|
||||||
final double randomPitch = NIGHTCORE_PITCH_LOWER +
|
skipSilenceCheckbox.setOnCheckedChangeListener((compoundButton, isChecked) ->
|
||||||
Math.random() * (NIGHTCORE_PITCH_UPPER - NIGHTCORE_PITCH_LOWER);
|
setCurrentPlaybackParameters());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
setTempoSlider(NIGHTCORE_TEMPO);
|
private void setupStepSizeSelector(@NonNull final View rootView) {
|
||||||
setPitchSlider(randomPitch);
|
stepSizeOnePercentText = rootView.findViewById(R.id.stepSizeOnePercent);
|
||||||
|
stepSizeFivePercentText = rootView.findViewById(R.id.stepSizeFivePercent);
|
||||||
|
stepSizeTenPercentText = rootView.findViewById(R.id.stepSizeTenPercent);
|
||||||
|
stepSizeTwentyFivePercentText = rootView.findViewById(R.id.stepSizeTwentyFivePercent);
|
||||||
|
stepSizeOneHundredPercentText = rootView.findViewById(R.id.stepSizeOneHundredPercent);
|
||||||
|
|
||||||
|
if (stepSizeOnePercentText != null) {
|
||||||
|
stepSizeOnePercentText.setText(getPercentString(STEP_ONE_PERCENT_VALUE));
|
||||||
|
stepSizeOnePercentText.setOnClickListener(view ->
|
||||||
|
changeStepSize(STEP_ONE_PERCENT_VALUE));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stepSizeFivePercentText != null) {
|
||||||
|
stepSizeFivePercentText.setText(getPercentString(STEP_FIVE_PERCENT_VALUE));
|
||||||
|
stepSizeFivePercentText.setOnClickListener(view ->
|
||||||
|
changeStepSize(STEP_FIVE_PERCENT_VALUE));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stepSizeTenPercentText != null) {
|
||||||
|
stepSizeTenPercentText.setText(getPercentString(STEP_TEN_PERCENT_VALUE));
|
||||||
|
stepSizeTenPercentText.setOnClickListener(view ->
|
||||||
|
changeStepSize(STEP_TEN_PERCENT_VALUE));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stepSizeTwentyFivePercentText != null) {
|
||||||
|
stepSizeTwentyFivePercentText.setText(getPercentString(STEP_TWENTY_FIVE_PERCENT_VALUE));
|
||||||
|
stepSizeTwentyFivePercentText.setOnClickListener(view ->
|
||||||
|
changeStepSize(STEP_TWENTY_FIVE_PERCENT_VALUE));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stepSizeOneHundredPercentText != null) {
|
||||||
|
stepSizeOneHundredPercentText.setText(getPercentString(STEP_ONE_HUNDRED_PERCENT_VALUE));
|
||||||
|
stepSizeOneHundredPercentText.setOnClickListener(view ->
|
||||||
|
changeStepSize(STEP_ONE_HUNDRED_PERCENT_VALUE));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void changeStepSize(final double stepSize) {
|
||||||
|
this.stepSize = stepSize;
|
||||||
|
|
||||||
|
if (tempoStepUpText != null) {
|
||||||
|
tempoStepUpText.setText(getStepUpPercentString(stepSize));
|
||||||
|
tempoStepUpText.setOnClickListener(view -> {
|
||||||
|
onTempoSliderUpdated(getCurrentTempo() + stepSize);
|
||||||
setCurrentPlaybackParameters();
|
setCurrentPlaybackParameters();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
resetPresetText = rootView.findViewById(R.id.presetReset);
|
if (tempoStepDownText != null) {
|
||||||
if (resetPresetText != null) {
|
tempoStepDownText.setText(getStepDownPercentString(stepSize));
|
||||||
resetPresetText.setOnClickListener(view -> {
|
tempoStepDownText.setOnClickListener(view -> {
|
||||||
setTempoSlider(DEFAULT_TEMPO);
|
onTempoSliderUpdated(getCurrentTempo() - stepSize);
|
||||||
setPitchSlider(DEFAULT_PITCH);
|
setCurrentPlaybackParameters();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pitchStepUpText != null) {
|
||||||
|
pitchStepUpText.setText(getStepUpPercentString(stepSize));
|
||||||
|
pitchStepUpText.setOnClickListener(view -> {
|
||||||
|
onPitchSliderUpdated(getCurrentPitch() + stepSize);
|
||||||
|
setCurrentPlaybackParameters();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pitchStepDownText != null) {
|
||||||
|
pitchStepDownText.setText(getStepDownPercentString(stepSize));
|
||||||
|
pitchStepDownText.setOnClickListener(view -> {
|
||||||
|
onPitchSliderUpdated(getCurrentPitch() - stepSize);
|
||||||
setCurrentPlaybackParameters();
|
setCurrentPlaybackParameters();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -342,10 +408,11 @@ public class PlaybackParameterDialog extends DialogFragment {
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
private void setCurrentPlaybackParameters() {
|
private void setCurrentPlaybackParameters() {
|
||||||
setPlaybackParameters(getCurrentTempo(), getCurrentPitch());
|
setPlaybackParameters(getCurrentTempo(), getCurrentPitch(), getCurrentSkipSilence());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setPlaybackParameters(final double tempo, final double pitch) {
|
private void setPlaybackParameters(final double tempo, final double pitch,
|
||||||
|
final boolean skipSilence) {
|
||||||
if (callback != null && tempoCurrentText != null && pitchCurrentText != null) {
|
if (callback != null && tempoCurrentText != null && pitchCurrentText != null) {
|
||||||
if (DEBUG) Log.d(TAG, "Setting playback parameters to " +
|
if (DEBUG) Log.d(TAG, "Setting playback parameters to " +
|
||||||
"tempo=[" + tempo + "], " +
|
"tempo=[" + tempo + "], " +
|
||||||
|
@ -353,27 +420,40 @@ public class PlaybackParameterDialog extends DialogFragment {
|
||||||
|
|
||||||
tempoCurrentText.setText(PlayerHelper.formatSpeed(tempo));
|
tempoCurrentText.setText(PlayerHelper.formatSpeed(tempo));
|
||||||
pitchCurrentText.setText(PlayerHelper.formatPitch(pitch));
|
pitchCurrentText.setText(PlayerHelper.formatPitch(pitch));
|
||||||
callback.onPlaybackParameterChanged((float) tempo, (float) pitch);
|
callback.onPlaybackParameterChanged((float) tempo, (float) pitch, skipSilence);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private double getCurrentTempo() {
|
private double getCurrentTempo() {
|
||||||
return tempoSlider == null ? initialTempo : strategy.valueOf(
|
return tempoSlider == null ? tempo : strategy.valueOf(
|
||||||
tempoSlider.getProgress());
|
tempoSlider.getProgress());
|
||||||
}
|
}
|
||||||
|
|
||||||
private double getCurrentPitch() {
|
private double getCurrentPitch() {
|
||||||
return pitchSlider == null ? initialPitch : strategy.valueOf(
|
return pitchSlider == null ? pitch : strategy.valueOf(
|
||||||
pitchSlider.getProgress());
|
pitchSlider.getProgress());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private double getCurrentStepSize() {
|
||||||
|
return stepSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean getCurrentSkipSilence() {
|
||||||
|
return skipSilenceCheckbox != null && skipSilenceCheckbox.isChecked();
|
||||||
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private static String getStepUpPercentString(final double percent) {
|
private static String getStepUpPercentString(final double percent) {
|
||||||
return STEP_UP_SIGN + PlayerHelper.formatPitch(percent);
|
return STEP_UP_SIGN + getPercentString(percent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private static String getStepDownPercentString(final double percent) {
|
private static String getStepDownPercentString(final double percent) {
|
||||||
return STEP_DOWN_SIGN + PlayerHelper.formatPitch(percent);
|
return STEP_DOWN_SIGN + getPercentString(percent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private static String getPercentString(final double percent) {
|
||||||
|
return PlayerHelper.formatPitch(percent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,
|
||||||
|
@ -253,7 +252,7 @@ public class PlayerHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getShutdownFlingVelocity(@NonNull final Context context) {
|
public static int getShutdownFlingVelocity(@NonNull final Context context) {
|
||||||
return 10000;
|
return 6000;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getTossFlingVelocity(@NonNull final Context context) {
|
public static int getTossFlingVelocity(@NonNull final Context context) {
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -5,12 +5,10 @@ import android.support.annotation.Nullable;
|
||||||
import android.support.v4.util.ArraySet;
|
import android.support.v4.util.ArraySet;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.google.android.exoplayer2.source.DynamicConcatenatingMediaSource;
|
|
||||||
import com.google.android.exoplayer2.source.MediaSource;
|
import com.google.android.exoplayer2.source.MediaSource;
|
||||||
|
|
||||||
import org.reactivestreams.Subscriber;
|
import org.reactivestreams.Subscriber;
|
||||||
import org.reactivestreams.Subscription;
|
import org.reactivestreams.Subscription;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
|
||||||
import org.schabi.newpipe.player.mediasource.FailedMediaSource;
|
import org.schabi.newpipe.player.mediasource.FailedMediaSource;
|
||||||
import org.schabi.newpipe.player.mediasource.LoadedMediaSource;
|
import org.schabi.newpipe.player.mediasource.LoadedMediaSource;
|
||||||
import org.schabi.newpipe.player.mediasource.ManagedMediaSource;
|
import org.schabi.newpipe.player.mediasource.ManagedMediaSource;
|
||||||
|
@ -24,10 +22,8 @@ import org.schabi.newpipe.player.playqueue.events.RemoveEvent;
|
||||||
import org.schabi.newpipe.player.playqueue.events.ReorderEvent;
|
import org.schabi.newpipe.player.playqueue.events.ReorderEvent;
|
||||||
import org.schabi.newpipe.util.ServiceHelper;
|
import org.schabi.newpipe.util.ServiceHelper;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
@ -37,8 +33,6 @@ import io.reactivex.Single;
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
import io.reactivex.disposables.CompositeDisposable;
|
import io.reactivex.disposables.CompositeDisposable;
|
||||||
import io.reactivex.disposables.Disposable;
|
import io.reactivex.disposables.Disposable;
|
||||||
import io.reactivex.disposables.SerialDisposable;
|
|
||||||
import io.reactivex.functions.Consumer;
|
|
||||||
import io.reactivex.internal.subscriptions.EmptySubscription;
|
import io.reactivex.internal.subscriptions.EmptySubscription;
|
||||||
import io.reactivex.schedulers.Schedulers;
|
import io.reactivex.schedulers.Schedulers;
|
||||||
import io.reactivex.subjects.PublishSubject;
|
import io.reactivex.subjects.PublishSubject;
|
||||||
|
@ -104,7 +98,6 @@ public class MediaSourceManager {
|
||||||
private final static int MAXIMUM_LOADER_SIZE = WINDOW_SIZE * 2 + 1;
|
private final static int MAXIMUM_LOADER_SIZE = WINDOW_SIZE * 2 + 1;
|
||||||
@NonNull private final CompositeDisposable loaderReactor;
|
@NonNull private final CompositeDisposable loaderReactor;
|
||||||
@NonNull private final Set<PlayQueueItem> loadingItems;
|
@NonNull private final Set<PlayQueueItem> loadingItems;
|
||||||
@NonNull private final SerialDisposable syncReactor;
|
|
||||||
|
|
||||||
@NonNull private final AtomicBoolean isBlocked;
|
@NonNull private final AtomicBoolean isBlocked;
|
||||||
|
|
||||||
|
@ -144,7 +137,6 @@ public class MediaSourceManager {
|
||||||
|
|
||||||
this.playQueueReactor = EmptySubscription.INSTANCE;
|
this.playQueueReactor = EmptySubscription.INSTANCE;
|
||||||
this.loaderReactor = new CompositeDisposable();
|
this.loaderReactor = new CompositeDisposable();
|
||||||
this.syncReactor = new SerialDisposable();
|
|
||||||
|
|
||||||
this.isBlocked = new AtomicBoolean(false);
|
this.isBlocked = new AtomicBoolean(false);
|
||||||
|
|
||||||
|
@ -171,8 +163,6 @@ public class MediaSourceManager {
|
||||||
|
|
||||||
playQueueReactor.cancel();
|
playQueueReactor.cancel();
|
||||||
loaderReactor.dispose();
|
loaderReactor.dispose();
|
||||||
syncReactor.dispose();
|
|
||||||
playlist.dispose();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -311,21 +301,7 @@ public class MediaSourceManager {
|
||||||
final PlayQueueItem currentItem = playQueue.getItem();
|
final PlayQueueItem currentItem = playQueue.getItem();
|
||||||
if (isBlocked.get() || currentItem == null) return;
|
if (isBlocked.get() || currentItem == null) return;
|
||||||
|
|
||||||
final Consumer<StreamInfo> onSuccess = info -> syncInternal(currentItem, info);
|
playbackListener.onPlaybackSynchronize(currentItem);
|
||||||
final Consumer<Throwable> onError = throwable -> syncInternal(currentItem, null);
|
|
||||||
|
|
||||||
final Disposable sync = currentItem.getStream()
|
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
|
||||||
.subscribe(onSuccess, onError);
|
|
||||||
syncReactor.set(sync);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void syncInternal(@NonNull final PlayQueueItem item,
|
|
||||||
@Nullable final StreamInfo info) {
|
|
||||||
// Ensure the current item is up to date with the play queue
|
|
||||||
if (playQueue.getItem() == item) {
|
|
||||||
playbackListener.onPlaybackSynchronize(item, info);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void maybeSynchronizePlayer() {
|
private synchronized void maybeSynchronizePlayer() {
|
||||||
|
@ -424,7 +400,8 @@ public class MediaSourceManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the corresponding MediaSource in {@link DynamicConcatenatingMediaSource}
|
* Checks if the corresponding MediaSource in
|
||||||
|
* {@link com.google.android.exoplayer2.source.ConcatenatingMediaSource}
|
||||||
* for a given {@link PlayQueueItem} needs replacement, either due to gapless playback
|
* for a given {@link PlayQueueItem} needs replacement, either due to gapless playback
|
||||||
* readiness or playlist desynchronization.
|
* readiness or playlist desynchronization.
|
||||||
* <br><br>
|
* <br><br>
|
||||||
|
@ -481,8 +458,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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ public interface PlaybackListener {
|
||||||
*
|
*
|
||||||
* May be called anytime at any amount once unblock is called.
|
* May be called anytime at any amount once unblock is called.
|
||||||
* */
|
* */
|
||||||
void onPlaybackSynchronize(@NonNull final PlayQueueItem item, @Nullable final StreamInfo info);
|
void onPlaybackSynchronize(@NonNull final PlayQueueItem item);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Requests the listener to resolve a stream info into a media source
|
* Requests the listener to resolve a stream info into a media source
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
package org.schabi.newpipe.player.resolver;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
|
import com.google.android.exoplayer2.source.MediaSource;
|
||||||
|
|
||||||
|
import org.schabi.newpipe.extractor.MediaFormat;
|
||||||
|
import org.schabi.newpipe.extractor.stream.AudioStream;
|
||||||
|
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
||||||
|
import org.schabi.newpipe.player.helper.PlayerDataSource;
|
||||||
|
import org.schabi.newpipe.player.helper.PlayerHelper;
|
||||||
|
import org.schabi.newpipe.util.ListHelper;
|
||||||
|
|
||||||
|
public class AudioPlaybackResolver implements PlaybackResolver {
|
||||||
|
|
||||||
|
@NonNull private final Context context;
|
||||||
|
@NonNull private final PlayerDataSource dataSource;
|
||||||
|
|
||||||
|
public AudioPlaybackResolver(@NonNull final Context context,
|
||||||
|
@NonNull final PlayerDataSource dataSource) {
|
||||||
|
this.context = context;
|
||||||
|
this.dataSource = dataSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public MediaSource resolve(@NonNull StreamInfo info) {
|
||||||
|
final MediaSource liveSource = maybeBuildLiveMediaSource(dataSource, info);
|
||||||
|
if (liveSource != null) return liveSource;
|
||||||
|
|
||||||
|
final int index = ListHelper.getDefaultAudioFormat(context, info.getAudioStreams());
|
||||||
|
if (index < 0 || index >= info.getAudioStreams().size()) return null;
|
||||||
|
|
||||||
|
final AudioStream audio = info.getAudioStreams().get(index);
|
||||||
|
final MediaSourceTag tag = new MediaSourceTag(info);
|
||||||
|
return buildMediaSource(dataSource, audio.getUrl(), PlayerHelper.cacheKeyOf(info, audio),
|
||||||
|
MediaFormat.getSuffixById(audio.getFormatId()), tag);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,51 @@
|
||||||
|
package org.schabi.newpipe.player.resolver;
|
||||||
|
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
|
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
||||||
|
import org.schabi.newpipe.extractor.stream.VideoStream;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class MediaSourceTag implements Serializable {
|
||||||
|
@NonNull private final StreamInfo metadata;
|
||||||
|
|
||||||
|
@NonNull private final List<VideoStream> sortedAvailableVideoStreams;
|
||||||
|
private final int selectedVideoStreamIndex;
|
||||||
|
|
||||||
|
public MediaSourceTag(@NonNull final StreamInfo metadata,
|
||||||
|
@NonNull final List<VideoStream> sortedAvailableVideoStreams,
|
||||||
|
final int selectedVideoStreamIndex) {
|
||||||
|
this.metadata = metadata;
|
||||||
|
this.sortedAvailableVideoStreams = sortedAvailableVideoStreams;
|
||||||
|
this.selectedVideoStreamIndex = selectedVideoStreamIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MediaSourceTag(@NonNull final StreamInfo metadata) {
|
||||||
|
this(metadata, Collections.emptyList(), /*indexNotAvailable=*/-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public StreamInfo getMetadata() {
|
||||||
|
return metadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public List<VideoStream> getSortedAvailableVideoStreams() {
|
||||||
|
return sortedAvailableVideoStreams;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSelectedVideoStreamIndex() {
|
||||||
|
return selectedVideoStreamIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public VideoStream getSelectedVideoStream() {
|
||||||
|
return selectedVideoStreamIndex < 0 ||
|
||||||
|
selectedVideoStreamIndex >= sortedAvailableVideoStreams.size() ? null :
|
||||||
|
sortedAvailableVideoStreams.get(selectedVideoStreamIndex);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,84 @@
|
||||||
|
package org.schabi.newpipe.player.resolver;
|
||||||
|
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import com.google.android.exoplayer2.C;
|
||||||
|
import com.google.android.exoplayer2.source.MediaSource;
|
||||||
|
import com.google.android.exoplayer2.util.Util;
|
||||||
|
|
||||||
|
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
||||||
|
import org.schabi.newpipe.extractor.stream.StreamType;
|
||||||
|
import org.schabi.newpipe.player.helper.PlayerDataSource;
|
||||||
|
|
||||||
|
public interface PlaybackResolver extends Resolver<StreamInfo, MediaSource> {
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
default MediaSource maybeBuildLiveMediaSource(@NonNull final PlayerDataSource dataSource,
|
||||||
|
@NonNull final StreamInfo info) {
|
||||||
|
final StreamType streamType = info.getStreamType();
|
||||||
|
if (!(streamType == StreamType.AUDIO_LIVE_STREAM || streamType == StreamType.LIVE_STREAM)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
final MediaSourceTag tag = new MediaSourceTag(info);
|
||||||
|
if (!info.getHlsUrl().isEmpty()) {
|
||||||
|
return buildLiveMediaSource(dataSource, info.getHlsUrl(), C.TYPE_HLS, tag);
|
||||||
|
} else if (!info.getDashMpdUrl().isEmpty()) {
|
||||||
|
return buildLiveMediaSource(dataSource, info.getDashMpdUrl(), C.TYPE_DASH, tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
default MediaSource buildLiveMediaSource(@NonNull final PlayerDataSource dataSource,
|
||||||
|
@NonNull final String sourceUrl,
|
||||||
|
@C.ContentType final int type,
|
||||||
|
@NonNull final MediaSourceTag metadata) {
|
||||||
|
final Uri uri = Uri.parse(sourceUrl);
|
||||||
|
switch (type) {
|
||||||
|
case C.TYPE_SS:
|
||||||
|
return dataSource.getLiveSsMediaSourceFactory().setTag(metadata)
|
||||||
|
.createMediaSource(uri);
|
||||||
|
case C.TYPE_DASH:
|
||||||
|
return dataSource.getLiveDashMediaSourceFactory().setTag(metadata)
|
||||||
|
.createMediaSource(uri);
|
||||||
|
case C.TYPE_HLS:
|
||||||
|
return dataSource.getLiveHlsMediaSourceFactory().setTag(metadata)
|
||||||
|
.createMediaSource(uri);
|
||||||
|
default:
|
||||||
|
throw new IllegalStateException("Unsupported type: " + type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
default MediaSource buildMediaSource(@NonNull final PlayerDataSource dataSource,
|
||||||
|
@NonNull final String sourceUrl,
|
||||||
|
@NonNull final String cacheKey,
|
||||||
|
@NonNull final String overrideExtension,
|
||||||
|
@NonNull final MediaSourceTag metadata) {
|
||||||
|
final Uri uri = Uri.parse(sourceUrl);
|
||||||
|
@C.ContentType final int type = TextUtils.isEmpty(overrideExtension) ?
|
||||||
|
Util.inferContentType(uri) : Util.inferContentType("." + overrideExtension);
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case C.TYPE_SS:
|
||||||
|
return dataSource.getLiveSsMediaSourceFactory().setTag(metadata)
|
||||||
|
.createMediaSource(uri);
|
||||||
|
case C.TYPE_DASH:
|
||||||
|
return dataSource.getDashMediaSourceFactory().setTag(metadata)
|
||||||
|
.createMediaSource(uri);
|
||||||
|
case C.TYPE_HLS:
|
||||||
|
return dataSource.getHlsMediaSourceFactory().setTag(metadata)
|
||||||
|
.createMediaSource(uri);
|
||||||
|
case C.TYPE_OTHER:
|
||||||
|
return dataSource.getExtractorMediaSourceFactory(cacheKey).setTag(metadata)
|
||||||
|
.createMediaSource(uri);
|
||||||
|
default:
|
||||||
|
throw new IllegalStateException("Unsupported type: " + type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
package org.schabi.newpipe.player.resolver;
|
||||||
|
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
|
public interface Resolver<Source, Product> {
|
||||||
|
@Nullable Product resolve(@NonNull Source source);
|
||||||
|
}
|
|
@ -0,0 +1,123 @@
|
||||||
|
package org.schabi.newpipe.player.resolver;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
|
import com.google.android.exoplayer2.Format;
|
||||||
|
import com.google.android.exoplayer2.source.MediaSource;
|
||||||
|
import com.google.android.exoplayer2.source.MergingMediaSource;
|
||||||
|
|
||||||
|
import org.schabi.newpipe.extractor.MediaFormat;
|
||||||
|
import org.schabi.newpipe.extractor.Subtitles;
|
||||||
|
import org.schabi.newpipe.extractor.stream.AudioStream;
|
||||||
|
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
||||||
|
import org.schabi.newpipe.extractor.stream.VideoStream;
|
||||||
|
import org.schabi.newpipe.player.helper.PlayerDataSource;
|
||||||
|
import org.schabi.newpipe.player.helper.PlayerHelper;
|
||||||
|
import org.schabi.newpipe.util.ListHelper;
|
||||||
|
|
||||||
|
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 {
|
||||||
|
|
||||||
|
public interface QualityResolver {
|
||||||
|
int getDefaultResolutionIndex(final List<VideoStream> sortedVideos);
|
||||||
|
int getOverrideResolutionIndex(final List<VideoStream> sortedVideos,
|
||||||
|
final String playbackQuality);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull private final Context context;
|
||||||
|
@NonNull private final PlayerDataSource dataSource;
|
||||||
|
@NonNull private final QualityResolver qualityResolver;
|
||||||
|
|
||||||
|
@Nullable private String playbackQuality;
|
||||||
|
|
||||||
|
public VideoPlaybackResolver(@NonNull final Context context,
|
||||||
|
@NonNull final PlayerDataSource dataSource,
|
||||||
|
@NonNull final QualityResolver qualityResolver) {
|
||||||
|
this.context = context;
|
||||||
|
this.dataSource = dataSource;
|
||||||
|
this.qualityResolver = qualityResolver;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public MediaSource resolve(@NonNull StreamInfo info) {
|
||||||
|
final MediaSource liveSource = maybeBuildLiveMediaSource(dataSource, info);
|
||||||
|
if (liveSource != null) return liveSource;
|
||||||
|
|
||||||
|
List<MediaSource> mediaSources = new ArrayList<>();
|
||||||
|
|
||||||
|
// Create video stream source
|
||||||
|
final List<VideoStream> videos = ListHelper.getSortedStreamVideosList(context,
|
||||||
|
info.getVideoStreams(), info.getVideoOnlyStreams(), false);
|
||||||
|
final int index;
|
||||||
|
if (videos.isEmpty()) {
|
||||||
|
index = -1;
|
||||||
|
} else if (playbackQuality == null) {
|
||||||
|
index = qualityResolver.getDefaultResolutionIndex(videos);
|
||||||
|
} else {
|
||||||
|
index = qualityResolver.getOverrideResolutionIndex(videos, getPlaybackQuality());
|
||||||
|
}
|
||||||
|
final MediaSourceTag tag = new MediaSourceTag(info, videos, index);
|
||||||
|
@Nullable final VideoStream video = tag.getSelectedVideoStream();
|
||||||
|
|
||||||
|
if (video != null) {
|
||||||
|
final MediaSource streamSource = buildMediaSource(dataSource, video.getUrl(),
|
||||||
|
PlayerHelper.cacheKeyOf(info, video),
|
||||||
|
MediaFormat.getSuffixById(video.getFormatId()), tag);
|
||||||
|
mediaSources.add(streamSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create optional audio stream source
|
||||||
|
final List<AudioStream> audioStreams = info.getAudioStreams();
|
||||||
|
final AudioStream audio = audioStreams.isEmpty() ? null : audioStreams.get(
|
||||||
|
ListHelper.getDefaultAudioFormat(context, audioStreams));
|
||||||
|
// Use the audio stream if there is no video stream, or
|
||||||
|
// Merge with audio stream in case if video does not contain audio
|
||||||
|
if (audio != null && ((video != null && video.isVideoOnly) || video == null)) {
|
||||||
|
final MediaSource audioSource = buildMediaSource(dataSource, audio.getUrl(),
|
||||||
|
PlayerHelper.cacheKeyOf(info, audio),
|
||||||
|
MediaFormat.getSuffixById(audio.getFormatId()), tag);
|
||||||
|
mediaSources.add(audioSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If there is no audio or video sources, then this media source cannot be played back
|
||||||
|
if (mediaSources.isEmpty()) return null;
|
||||||
|
// Below are auxiliary media sources
|
||||||
|
|
||||||
|
// Create subtitle sources
|
||||||
|
for (final Subtitles subtitle : info.getSubtitles()) {
|
||||||
|
final String mimeType = PlayerHelper.mimeTypesOf(subtitle.getFileType());
|
||||||
|
if (mimeType == null) continue;
|
||||||
|
|
||||||
|
final Format textFormat = Format.createTextSampleFormat(null, mimeType,
|
||||||
|
SELECTION_FLAG_AUTOSELECT, PlayerHelper.captionLanguageOf(context, subtitle));
|
||||||
|
final MediaSource textSource = dataSource.getSampleMediaSourceFactory()
|
||||||
|
.createMediaSource(Uri.parse(subtitle.getURL()), textFormat, TIME_UNSET);
|
||||||
|
mediaSources.add(textSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mediaSources.size() == 1) {
|
||||||
|
return mediaSources.get(0);
|
||||||
|
} else {
|
||||||
|
return new MergingMediaSource(mediaSources.toArray(
|
||||||
|
new MediaSource[mediaSources.size()]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public String getPlaybackQuality() {
|
||||||
|
return playbackQuality;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPlaybackQuality(@Nullable String playbackQuality) {
|
||||||
|
this.playbackQuality = playbackQuality;
|
||||||
|
}
|
||||||
|
}
|
|
@ -277,6 +277,7 @@ public class ContentSettingsFragment extends BasePreferenceFragment {
|
||||||
newpipe_db_shm.delete();
|
newpipe_db_shm.delete();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
Toast.makeText(getContext(), R.string.could_not_import_all_files, Toast.LENGTH_LONG)
|
Toast.makeText(getContext(), R.string.could_not_import_all_files, Toast.LENGTH_LONG)
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,11 +100,13 @@ public class NavigationHelper {
|
||||||
final int repeatMode,
|
final int repeatMode,
|
||||||
final float playbackSpeed,
|
final float playbackSpeed,
|
||||||
final float playbackPitch,
|
final float playbackPitch,
|
||||||
|
final boolean playbackSkipSilence,
|
||||||
@Nullable final String playbackQuality) {
|
@Nullable final String playbackQuality) {
|
||||||
return getPlayerIntent(context, targetClazz, playQueue, playbackQuality)
|
return getPlayerIntent(context, targetClazz, playQueue, playbackQuality)
|
||||||
.putExtra(BasePlayer.REPEAT_MODE, repeatMode)
|
.putExtra(BasePlayer.REPEAT_MODE, repeatMode)
|
||||||
.putExtra(BasePlayer.PLAYBACK_SPEED, playbackSpeed)
|
.putExtra(BasePlayer.PLAYBACK_SPEED, playbackSpeed)
|
||||||
.putExtra(BasePlayer.PLAYBACK_PITCH, playbackPitch);
|
.putExtra(BasePlayer.PLAYBACK_PITCH, playbackPitch)
|
||||||
|
.putExtra(BasePlayer.PLAYBACK_SKIP_SILENCE, playbackSkipSilence);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void playOnMainPlayer(final Context context, final PlayQueue queue) {
|
public static void playOnMainPlayer(final Context context, final PlayQueue queue) {
|
||||||
|
|
|
@ -41,7 +41,6 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
android:scaleType="centerInside"
|
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
tools:background="@android:color/white"
|
tools:background="@android:color/white"
|
||||||
tools:ignore="ContentDescription"
|
tools:ignore="ContentDescription"
|
||||||
|
|
|
@ -260,13 +260,95 @@
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
<View
|
<View
|
||||||
android:id="@+id/separatorCheckbox"
|
android:id="@+id/separatorStepSizeSelector"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="1dp"
|
android:layout_height="1dp"
|
||||||
android:layout_below="@+id/pitchControl"
|
android:layout_below="@+id/pitchControl"
|
||||||
android:layout_margin="@dimen/video_item_search_padding"
|
android:layout_margin="@dimen/video_item_search_padding"
|
||||||
android:background="?attr/separator_color"/>
|
android:background="?attr/separator_color"/>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/stepSizeSelector"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="40dp"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:layout_below="@id/separatorStepSizeSelector">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/stepSizeText"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:gravity="center"
|
||||||
|
android:text="@string/playback_step"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:clickable="false"
|
||||||
|
android:textColor="?attr/colorAccent"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/stepSizeOnePercent"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:gravity="center"
|
||||||
|
android:clickable="true"
|
||||||
|
android:focusable="true"
|
||||||
|
android:background="?attr/selectableItemBackground"
|
||||||
|
android:textColor="?attr/colorAccent"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/stepSizeFivePercent"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:gravity="center"
|
||||||
|
android:clickable="true"
|
||||||
|
android:focusable="true"
|
||||||
|
android:background="?attr/selectableItemBackground"
|
||||||
|
android:textColor="?attr/colorAccent"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/stepSizeTenPercent"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:gravity="center"
|
||||||
|
android:clickable="true"
|
||||||
|
android:focusable="true"
|
||||||
|
android:background="?attr/selectableItemBackground"
|
||||||
|
android:textColor="?attr/colorAccent"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/stepSizeTwentyFivePercent"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:gravity="center"
|
||||||
|
android:clickable="true"
|
||||||
|
android:focusable="true"
|
||||||
|
android:background="?attr/selectableItemBackground"
|
||||||
|
android:textColor="?attr/colorAccent"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/stepSizeOneHundredPercent"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:gravity="center"
|
||||||
|
android:clickable="true"
|
||||||
|
android:focusable="true"
|
||||||
|
android:background="?attr/selectableItemBackground"
|
||||||
|
android:textColor="?attr/colorAccent"/>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:id="@+id/separatorCheckbox"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="1dp"
|
||||||
|
android:layout_below="@+id/stepSizeSelector"
|
||||||
|
android:layout_margin="@dimen/video_item_search_padding"
|
||||||
|
android:background="?attr/separator_color"/>
|
||||||
|
|
||||||
<CheckBox
|
<CheckBox
|
||||||
android:id="@+id/unhookCheckbox"
|
android:id="@+id/unhookCheckbox"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -279,33 +361,17 @@
|
||||||
android:layout_centerHorizontal="true"
|
android:layout_centerHorizontal="true"
|
||||||
android:layout_below="@id/separatorCheckbox"/>
|
android:layout_below="@id/separatorCheckbox"/>
|
||||||
|
|
||||||
<LinearLayout
|
<CheckBox
|
||||||
android:id="@+id/presetSelector"
|
android:id="@+id/skipSilenceCheckbox"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="40dp"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal"
|
android:checked="false"
|
||||||
android:layout_below="@id/unhookCheckbox">
|
android:clickable="true"
|
||||||
|
android:focusable="true"
|
||||||
<TextView
|
android:text="@string/skip_silence_checkbox"
|
||||||
android:id="@+id/presetNightcore"
|
android:maxLines="1"
|
||||||
android:layout_width="0dp"
|
android:layout_centerHorizontal="true"
|
||||||
android:layout_height="match_parent"
|
android:layout_below="@id/unhookCheckbox"/>
|
||||||
android:layout_weight="1"
|
|
||||||
android:gravity="center"
|
|
||||||
android:text="@string/playback_nightcore"
|
|
||||||
android:background="?attr/selectableItemBackground"
|
|
||||||
android:textColor="?attr/colorAccent"/>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/presetReset"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:gravity="center"
|
|
||||||
android:text="@string/playback_default"
|
|
||||||
android:background="?attr/selectableItemBackground"
|
|
||||||
android:textColor="?attr/colorAccent"/>
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<!-- END HERE -->
|
<!-- END HERE -->
|
||||||
|
|
||||||
|
|
|
@ -111,7 +111,7 @@
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/resizeTextView"
|
android:id="@+id/resizeTextView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_alignParentLeft="true"
|
android:layout_alignParentLeft="true"
|
||||||
android:background="?attr/selectableItemBackground"
|
android:background="?attr/selectableItemBackground"
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="?attr/selectableItemBackground"
|
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
|
@ -12,7 +11,9 @@
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:clickable="true"
|
android:clickable="true"
|
||||||
android:focusable="true">
|
android:focusable="true"
|
||||||
|
android:background="?attr/selectableItemBackground">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/sortButtonIcon"
|
android:id="@+id/sortButtonIcon"
|
||||||
android:layout_width="48dp"
|
android:layout_width="48dp"
|
||||||
|
|
|
@ -479,9 +479,10 @@
|
||||||
<string name="playback_speed_control">Playback Speed Controls</string>
|
<string name="playback_speed_control">Playback Speed Controls</string>
|
||||||
<string name="playback_tempo">Tempo</string>
|
<string name="playback_tempo">Tempo</string>
|
||||||
<string name="playback_pitch">Pitch</string>
|
<string name="playback_pitch">Pitch</string>
|
||||||
<string name="unhook_checkbox">Unhook (may cause distortion)</string>
|
<string name="unhook_checkbox">Unlink (may cause distortion)</string>
|
||||||
<string name="playback_nightcore">Nightcore</string>
|
<string name="skip_silence_checkbox">Fast-forward during silence</string>
|
||||||
<string name="playback_default">Default</string>
|
<string name="playback_step">Step</string>
|
||||||
|
<string name="playback_reset">Reset</string>
|
||||||
|
|
||||||
<!-- GDPR dialog -->
|
<!-- GDPR dialog -->
|
||||||
<string name="start_accept_privacy_policy">In order to comply with the European General Data Protection Regulation (GDPR), we herby draw your attention to NewPipe\'s privacy policy. Please read it carefully.\nYou must accept it to send us the bug report.</string>
|
<string name="start_accept_privacy_policy">In order to comply with the European General Data Protection Regulation (GDPR), we herby draw your attention to NewPipe\'s privacy policy. Please read it carefully.\nYou must accept it to send us the bug report.</string>
|
||||||
|
|
Loading…
Reference in a new issue