Improved streamType check and documentation
This commit is contained in:
parent
bbc13756f3
commit
72dbb9441e
|
@ -17,6 +17,7 @@ import org.schabi.newpipe.extractor.stream.StreamType.LIVE_STREAM
|
||||||
import org.schabi.newpipe.extractor.stream.StreamType.VIDEO_STREAM
|
import org.schabi.newpipe.extractor.stream.StreamType.VIDEO_STREAM
|
||||||
import org.schabi.newpipe.util.Localization
|
import org.schabi.newpipe.util.Localization
|
||||||
import org.schabi.newpipe.util.PicassoHelper
|
import org.schabi.newpipe.util.PicassoHelper
|
||||||
|
import org.schabi.newpipe.util.StreamTypeUtil
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
data class StreamItem(
|
data class StreamItem(
|
||||||
|
@ -58,8 +59,6 @@ data class StreamItem(
|
||||||
viewBinding.itemVideoTitleView.text = stream.title
|
viewBinding.itemVideoTitleView.text = stream.title
|
||||||
viewBinding.itemUploaderView.text = stream.uploader
|
viewBinding.itemUploaderView.text = stream.uploader
|
||||||
|
|
||||||
val isLiveStream = stream.streamType == LIVE_STREAM || stream.streamType == AUDIO_LIVE_STREAM
|
|
||||||
|
|
||||||
if (stream.duration > 0) {
|
if (stream.duration > 0) {
|
||||||
viewBinding.itemDurationView.text = Localization.getDurationString(stream.duration)
|
viewBinding.itemDurationView.text = Localization.getDurationString(stream.duration)
|
||||||
viewBinding.itemDurationView.setBackgroundColor(
|
viewBinding.itemDurationView.setBackgroundColor(
|
||||||
|
@ -77,7 +76,7 @@ data class StreamItem(
|
||||||
} else {
|
} else {
|
||||||
viewBinding.itemProgressView.visibility = View.GONE
|
viewBinding.itemProgressView.visibility = View.GONE
|
||||||
}
|
}
|
||||||
} else if (isLiveStream) {
|
} else if (StreamTypeUtil.isLiveStream(stream.streamType)) {
|
||||||
viewBinding.itemDurationView.setText(R.string.duration_live)
|
viewBinding.itemDurationView.setText(R.string.duration_live)
|
||||||
viewBinding.itemDurationView.setBackgroundColor(
|
viewBinding.itemDurationView.setBackgroundColor(
|
||||||
ContextCompat.getColor(
|
ContextCompat.getColor(
|
||||||
|
|
|
@ -1,5 +1,53 @@
|
||||||
package org.schabi.newpipe.player;
|
package org.schabi.newpipe.player;
|
||||||
|
|
||||||
|
import static com.google.android.exoplayer2.Player.DISCONTINUITY_REASON_AD_INSERTION;
|
||||||
|
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_SEEK;
|
||||||
|
import static com.google.android.exoplayer2.Player.DISCONTINUITY_REASON_SEEK_ADJUSTMENT;
|
||||||
|
import static com.google.android.exoplayer2.Player.DiscontinuityReason;
|
||||||
|
import static com.google.android.exoplayer2.Player.EventListener;
|
||||||
|
import static com.google.android.exoplayer2.Player.REPEAT_MODE_ALL;
|
||||||
|
import static com.google.android.exoplayer2.Player.REPEAT_MODE_OFF;
|
||||||
|
import static com.google.android.exoplayer2.Player.REPEAT_MODE_ONE;
|
||||||
|
import static com.google.android.exoplayer2.Player.RepeatMode;
|
||||||
|
import static org.schabi.newpipe.QueueItemMenuUtil.openPopupMenu;
|
||||||
|
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
|
||||||
|
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
||||||
|
import static org.schabi.newpipe.ktx.ViewUtils.animate;
|
||||||
|
import static org.schabi.newpipe.ktx.ViewUtils.animateRotation;
|
||||||
|
import static org.schabi.newpipe.player.MainPlayer.ACTION_CLOSE;
|
||||||
|
import static org.schabi.newpipe.player.MainPlayer.ACTION_FAST_FORWARD;
|
||||||
|
import static org.schabi.newpipe.player.MainPlayer.ACTION_FAST_REWIND;
|
||||||
|
import static org.schabi.newpipe.player.MainPlayer.ACTION_PLAY_NEXT;
|
||||||
|
import static org.schabi.newpipe.player.MainPlayer.ACTION_PLAY_PAUSE;
|
||||||
|
import static org.schabi.newpipe.player.MainPlayer.ACTION_PLAY_PREVIOUS;
|
||||||
|
import static org.schabi.newpipe.player.MainPlayer.ACTION_RECREATE_NOTIFICATION;
|
||||||
|
import static org.schabi.newpipe.player.MainPlayer.ACTION_REPEAT;
|
||||||
|
import static org.schabi.newpipe.player.MainPlayer.ACTION_SHUFFLE;
|
||||||
|
import static org.schabi.newpipe.player.helper.PlayerHelper.MinimizeMode.MINIMIZE_ON_EXIT_MODE_BACKGROUND;
|
||||||
|
import static org.schabi.newpipe.player.helper.PlayerHelper.MinimizeMode.MINIMIZE_ON_EXIT_MODE_NONE;
|
||||||
|
import static org.schabi.newpipe.player.helper.PlayerHelper.MinimizeMode.MINIMIZE_ON_EXIT_MODE_POPUP;
|
||||||
|
import static org.schabi.newpipe.player.helper.PlayerHelper.buildCloseOverlayLayoutParams;
|
||||||
|
import static org.schabi.newpipe.player.helper.PlayerHelper.formatSpeed;
|
||||||
|
import static org.schabi.newpipe.player.helper.PlayerHelper.getMinimizeOnExitAction;
|
||||||
|
import static org.schabi.newpipe.player.helper.PlayerHelper.getMinimumVideoHeight;
|
||||||
|
import static org.schabi.newpipe.player.helper.PlayerHelper.getTimeString;
|
||||||
|
import static org.schabi.newpipe.player.helper.PlayerHelper.globalScreenOrientationLocked;
|
||||||
|
import static org.schabi.newpipe.player.helper.PlayerHelper.isPlaybackResumeEnabled;
|
||||||
|
import static org.schabi.newpipe.player.helper.PlayerHelper.nextRepeatMode;
|
||||||
|
import static org.schabi.newpipe.player.helper.PlayerHelper.nextResizeModeAndSaveToPrefs;
|
||||||
|
import static org.schabi.newpipe.player.helper.PlayerHelper.retrievePlaybackParametersFromPrefs;
|
||||||
|
import static org.schabi.newpipe.player.helper.PlayerHelper.retrievePlayerTypeFromIntent;
|
||||||
|
import static org.schabi.newpipe.player.helper.PlayerHelper.retrievePopupLayoutParamsFromPrefs;
|
||||||
|
import static org.schabi.newpipe.player.helper.PlayerHelper.retrieveSeekDurationFromPreferences;
|
||||||
|
import static org.schabi.newpipe.player.helper.PlayerHelper.savePlaybackParametersToPrefs;
|
||||||
|
import static org.schabi.newpipe.util.ListHelper.getPopupResolutionIndex;
|
||||||
|
import static org.schabi.newpipe.util.ListHelper.getResolutionIndex;
|
||||||
|
import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage;
|
||||||
|
import static org.schabi.newpipe.util.Localization.containsCaseInsensitive;
|
||||||
|
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||||
|
|
||||||
import android.animation.Animator;
|
import android.animation.Animator;
|
||||||
import android.animation.AnimatorListenerAdapter;
|
import android.animation.AnimatorListenerAdapter;
|
||||||
import android.animation.ObjectAnimator;
|
import android.animation.ObjectAnimator;
|
||||||
|
@ -94,7 +142,6 @@ import org.schabi.newpipe.databinding.PlayerPopupCloseOverlayBinding;
|
||||||
import org.schabi.newpipe.extractor.MediaFormat;
|
import org.schabi.newpipe.extractor.MediaFormat;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamSegment;
|
import org.schabi.newpipe.extractor.stream.StreamSegment;
|
||||||
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.fragments.OnScrollBelowItemsListener;
|
import org.schabi.newpipe.fragments.OnScrollBelowItemsListener;
|
||||||
import org.schabi.newpipe.fragments.detail.VideoDetailFragment;
|
import org.schabi.newpipe.fragments.detail.VideoDetailFragment;
|
||||||
|
@ -127,12 +174,13 @@ import org.schabi.newpipe.player.resolver.MediaSourceTag;
|
||||||
import org.schabi.newpipe.player.resolver.VideoPlaybackResolver;
|
import org.schabi.newpipe.player.resolver.VideoPlaybackResolver;
|
||||||
import org.schabi.newpipe.player.seekbarpreview.SeekbarPreviewThumbnailHelper;
|
import org.schabi.newpipe.player.seekbarpreview.SeekbarPreviewThumbnailHelper;
|
||||||
import org.schabi.newpipe.player.seekbarpreview.SeekbarPreviewThumbnailHolder;
|
import org.schabi.newpipe.player.seekbarpreview.SeekbarPreviewThumbnailHolder;
|
||||||
|
import org.schabi.newpipe.util.StreamTypeUtil;
|
||||||
import org.schabi.newpipe.util.DeviceUtils;
|
import org.schabi.newpipe.util.DeviceUtils;
|
||||||
import org.schabi.newpipe.util.external_communication.KoreUtils;
|
|
||||||
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.PicassoHelper;
|
import org.schabi.newpipe.util.PicassoHelper;
|
||||||
import org.schabi.newpipe.util.SerializedCache;
|
import org.schabi.newpipe.util.SerializedCache;
|
||||||
|
import org.schabi.newpipe.util.external_communication.KoreUtils;
|
||||||
import org.schabi.newpipe.util.external_communication.ShareUtils;
|
import org.schabi.newpipe.util.external_communication.ShareUtils;
|
||||||
import org.schabi.newpipe.views.ExpandableSurfaceView;
|
import org.schabi.newpipe.views.ExpandableSurfaceView;
|
||||||
|
|
||||||
|
@ -148,54 +196,6 @@ import io.reactivex.rxjava3.disposables.CompositeDisposable;
|
||||||
import io.reactivex.rxjava3.disposables.Disposable;
|
import io.reactivex.rxjava3.disposables.Disposable;
|
||||||
import io.reactivex.rxjava3.disposables.SerialDisposable;
|
import io.reactivex.rxjava3.disposables.SerialDisposable;
|
||||||
|
|
||||||
import static com.google.android.exoplayer2.Player.DISCONTINUITY_REASON_AD_INSERTION;
|
|
||||||
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_SEEK;
|
|
||||||
import static com.google.android.exoplayer2.Player.DISCONTINUITY_REASON_SEEK_ADJUSTMENT;
|
|
||||||
import static com.google.android.exoplayer2.Player.DiscontinuityReason;
|
|
||||||
import static com.google.android.exoplayer2.Player.EventListener;
|
|
||||||
import static com.google.android.exoplayer2.Player.REPEAT_MODE_ALL;
|
|
||||||
import static com.google.android.exoplayer2.Player.REPEAT_MODE_OFF;
|
|
||||||
import static com.google.android.exoplayer2.Player.REPEAT_MODE_ONE;
|
|
||||||
import static com.google.android.exoplayer2.Player.RepeatMode;
|
|
||||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
|
||||||
import static org.schabi.newpipe.QueueItemMenuUtil.openPopupMenu;
|
|
||||||
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
|
|
||||||
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
|
||||||
import static org.schabi.newpipe.ktx.ViewUtils.animate;
|
|
||||||
import static org.schabi.newpipe.ktx.ViewUtils.animateRotation;
|
|
||||||
import static org.schabi.newpipe.player.MainPlayer.ACTION_CLOSE;
|
|
||||||
import static org.schabi.newpipe.player.MainPlayer.ACTION_FAST_FORWARD;
|
|
||||||
import static org.schabi.newpipe.player.MainPlayer.ACTION_FAST_REWIND;
|
|
||||||
import static org.schabi.newpipe.player.MainPlayer.ACTION_PLAY_NEXT;
|
|
||||||
import static org.schabi.newpipe.player.MainPlayer.ACTION_PLAY_PAUSE;
|
|
||||||
import static org.schabi.newpipe.player.MainPlayer.ACTION_PLAY_PREVIOUS;
|
|
||||||
import static org.schabi.newpipe.player.MainPlayer.ACTION_RECREATE_NOTIFICATION;
|
|
||||||
import static org.schabi.newpipe.player.MainPlayer.ACTION_REPEAT;
|
|
||||||
import static org.schabi.newpipe.player.MainPlayer.ACTION_SHUFFLE;
|
|
||||||
import static org.schabi.newpipe.player.helper.PlayerHelper.MinimizeMode.MINIMIZE_ON_EXIT_MODE_BACKGROUND;
|
|
||||||
import static org.schabi.newpipe.player.helper.PlayerHelper.MinimizeMode.MINIMIZE_ON_EXIT_MODE_NONE;
|
|
||||||
import static org.schabi.newpipe.player.helper.PlayerHelper.MinimizeMode.MINIMIZE_ON_EXIT_MODE_POPUP;
|
|
||||||
import static org.schabi.newpipe.player.helper.PlayerHelper.buildCloseOverlayLayoutParams;
|
|
||||||
import static org.schabi.newpipe.player.helper.PlayerHelper.formatSpeed;
|
|
||||||
import static org.schabi.newpipe.player.helper.PlayerHelper.getMinimizeOnExitAction;
|
|
||||||
import static org.schabi.newpipe.player.helper.PlayerHelper.getMinimumVideoHeight;
|
|
||||||
import static org.schabi.newpipe.player.helper.PlayerHelper.getTimeString;
|
|
||||||
import static org.schabi.newpipe.player.helper.PlayerHelper.globalScreenOrientationLocked;
|
|
||||||
import static org.schabi.newpipe.player.helper.PlayerHelper.isPlaybackResumeEnabled;
|
|
||||||
import static org.schabi.newpipe.player.helper.PlayerHelper.nextRepeatMode;
|
|
||||||
import static org.schabi.newpipe.player.helper.PlayerHelper.nextResizeModeAndSaveToPrefs;
|
|
||||||
import static org.schabi.newpipe.player.helper.PlayerHelper.retrievePlaybackParametersFromPrefs;
|
|
||||||
import static org.schabi.newpipe.player.helper.PlayerHelper.retrievePlayerTypeFromIntent;
|
|
||||||
import static org.schabi.newpipe.player.helper.PlayerHelper.retrievePopupLayoutParamsFromPrefs;
|
|
||||||
import static org.schabi.newpipe.player.helper.PlayerHelper.retrieveSeekDurationFromPreferences;
|
|
||||||
import static org.schabi.newpipe.player.helper.PlayerHelper.savePlaybackParametersToPrefs;
|
|
||||||
import static org.schabi.newpipe.util.ListHelper.getPopupResolutionIndex;
|
|
||||||
import static org.schabi.newpipe.util.ListHelper.getResolutionIndex;
|
|
||||||
import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage;
|
|
||||||
import static org.schabi.newpipe.util.Localization.containsCaseInsensitive;
|
|
||||||
|
|
||||||
public final class Player implements
|
public final class Player implements
|
||||||
EventListener,
|
EventListener,
|
||||||
PlaybackListener,
|
PlaybackListener,
|
||||||
|
@ -1647,8 +1647,8 @@ public final class Player implements
|
||||||
// TODO: revert #6307 when introducing proper HLS support
|
// TODO: revert #6307 when introducing proper HLS support
|
||||||
final int duration;
|
final int duration;
|
||||||
if (currentItem != null
|
if (currentItem != null
|
||||||
&& currentItem.getStreamType() != StreamType.AUDIO_LIVE_STREAM
|
&& !StreamTypeUtil.isLiveStream(currentItem.getStreamType())
|
||||||
&& currentItem.getStreamType() != StreamType.LIVE_STREAM) {
|
) {
|
||||||
// convert seconds to milliseconds
|
// convert seconds to milliseconds
|
||||||
duration = (int) (currentItem.getDuration() * 1000);
|
duration = (int) (currentItem.getDuration() * 1000);
|
||||||
} else {
|
} else {
|
||||||
|
@ -2948,7 +2948,9 @@ public final class Player implements
|
||||||
getVideoTitle(),
|
getVideoTitle(),
|
||||||
getUploaderName(),
|
getUploaderName(),
|
||||||
showThumbnail ? Optional.ofNullable(getThumbnail()) : Optional.empty(),
|
showThumbnail ? Optional.ofNullable(getThumbnail()) : Optional.empty(),
|
||||||
tag.getMetadata().getDuration()
|
StreamTypeUtil.isLiveStream(tag.getMetadata().getStreamType())
|
||||||
|
? -1
|
||||||
|
: tag.getMetadata().getDuration()
|
||||||
);
|
);
|
||||||
|
|
||||||
notifyMetadataUpdateToListeners();
|
notifyMetadataUpdateToListeners();
|
||||||
|
|
|
@ -70,6 +70,15 @@ public class MediaSessionManager {
|
||||||
return mediaSession.getSessionToken();
|
return mediaSession.getSessionToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sets the Metadata - if required.
|
||||||
|
*
|
||||||
|
* @param title {@link MediaMetadataCompat#METADATA_KEY_TITLE}
|
||||||
|
* @param artist {@link MediaMetadataCompat#METADATA_KEY_ARTIST}
|
||||||
|
* @param optAlbumArt {@link MediaMetadataCompat#METADATA_KEY_ALBUM_ART}
|
||||||
|
* @param duration {@link MediaMetadataCompat#METADATA_KEY_DURATION}
|
||||||
|
* - should be a negative value for unknown durations, e.g. for livestreams
|
||||||
|
*/
|
||||||
public void setMetadata(@NonNull final String title,
|
public void setMetadata(@NonNull final String title,
|
||||||
@NonNull final String artist,
|
@NonNull final String artist,
|
||||||
@NonNull final Optional<Bitmap> optAlbumArt,
|
@NonNull final Optional<Bitmap> optAlbumArt,
|
||||||
|
@ -95,7 +104,7 @@ public class MediaSessionManager {
|
||||||
|
|
||||||
if (!checkIfMetadataShouldBeSet(title, artist, optAlbumArt, duration)) {
|
if (!checkIfMetadataShouldBeSet(title, artist, optAlbumArt, duration)) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "setMetadata: No update required");
|
Log.d(TAG, "setMetadata: No update required - exiting");
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ import com.google.android.exoplayer2.util.Util;
|
||||||
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.StreamType;
|
||||||
import org.schabi.newpipe.player.helper.PlayerDataSource;
|
import org.schabi.newpipe.player.helper.PlayerDataSource;
|
||||||
|
import org.schabi.newpipe.util.StreamTypeUtil;
|
||||||
|
|
||||||
public interface PlaybackResolver extends Resolver<StreamInfo, MediaSource> {
|
public interface PlaybackResolver extends Resolver<StreamInfo, MediaSource> {
|
||||||
|
|
||||||
|
@ -21,7 +22,7 @@ public interface PlaybackResolver extends Resolver<StreamInfo, MediaSource> {
|
||||||
default MediaSource maybeBuildLiveMediaSource(@NonNull final PlayerDataSource dataSource,
|
default MediaSource maybeBuildLiveMediaSource(@NonNull final PlayerDataSource dataSource,
|
||||||
@NonNull final StreamInfo info) {
|
@NonNull final StreamInfo info) {
|
||||||
final StreamType streamType = info.getStreamType();
|
final StreamType streamType = info.getStreamType();
|
||||||
if (!(streamType == StreamType.AUDIO_LIVE_STREAM || streamType == StreamType.LIVE_STREAM)) {
|
if (!StreamTypeUtil.isLiveStream(streamType)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
package org.schabi.newpipe.util;
|
||||||
|
|
||||||
|
import org.schabi.newpipe.extractor.stream.StreamType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility class for {@link org.schabi.newpipe.extractor.stream.StreamType}.
|
||||||
|
*/
|
||||||
|
public final class StreamTypeUtil {
|
||||||
|
private StreamTypeUtil() {
|
||||||
|
// No impl pls
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the streamType is a livestream.
|
||||||
|
*
|
||||||
|
* @param streamType
|
||||||
|
* @return <code>true</code> when the streamType is a
|
||||||
|
* {@link StreamType#LIVE_STREAM} or {@link StreamType#AUDIO_LIVE_STREAM}
|
||||||
|
*/
|
||||||
|
public static boolean isLiveStream(final StreamType streamType) {
|
||||||
|
return streamType == StreamType.LIVE_STREAM
|
||||||
|
|| streamType == StreamType.AUDIO_LIVE_STREAM;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue