mirror of
				https://github.com/TeamNewPipe/NewPipe
				synced 2025-10-26 21:07:38 +00:00 
			
		
		
		
	Use StreamTypeUtil where possible and add isAudio and isVideo to this utility class
This commit is contained in:
		| @@ -12,8 +12,7 @@ import org.schabi.newpipe.database.BasicDAO | |||||||
| import org.schabi.newpipe.database.stream.model.StreamEntity | import org.schabi.newpipe.database.stream.model.StreamEntity | ||||||
| import org.schabi.newpipe.database.stream.model.StreamEntity.Companion.STREAM_ID | import org.schabi.newpipe.database.stream.model.StreamEntity.Companion.STREAM_ID | ||||||
| import org.schabi.newpipe.extractor.stream.StreamType | import org.schabi.newpipe.extractor.stream.StreamType | ||||||
| import org.schabi.newpipe.extractor.stream.StreamType.AUDIO_LIVE_STREAM | import org.schabi.newpipe.util.StreamTypeUtil | ||||||
| import org.schabi.newpipe.extractor.stream.StreamType.LIVE_STREAM |  | ||||||
| import java.time.OffsetDateTime | import java.time.OffsetDateTime | ||||||
|  |  | ||||||
| @Dao | @Dao | ||||||
| @@ -91,8 +90,7 @@ abstract class StreamDAO : BasicDAO<StreamEntity> { | |||||||
|             ?: throw IllegalStateException("Stream cannot be null just after insertion.") |             ?: throw IllegalStateException("Stream cannot be null just after insertion.") | ||||||
|         newerStream.uid = existentMinimalStream.uid |         newerStream.uid = existentMinimalStream.uid | ||||||
|  |  | ||||||
|         val isNewerStreamLive = newerStream.streamType == AUDIO_LIVE_STREAM || newerStream.streamType == LIVE_STREAM |         if (!StreamTypeUtil.isLiveStream(newerStream.streamType)) { | ||||||
|         if (!isNewerStreamLive) { |  | ||||||
|  |  | ||||||
|             // Use the existent upload date if the newer stream does not have a better precision |             // Use the existent upload date if the newer stream does not have a better precision | ||||||
|             // (i.e. is an approximation). This is done to prevent unnecessary changes. |             // (i.e. is an approximation). This is done to prevent unnecessary changes. | ||||||
|   | |||||||
| @@ -24,6 +24,7 @@ import org.schabi.newpipe.extractor.InfoItem; | |||||||
| import org.schabi.newpipe.extractor.stream.StreamInfoItem; | import org.schabi.newpipe.extractor.stream.StreamInfoItem; | ||||||
| import org.schabi.newpipe.extractor.stream.StreamType; | import org.schabi.newpipe.extractor.stream.StreamType; | ||||||
| import org.schabi.newpipe.player.helper.PlayerHolder; | import org.schabi.newpipe.player.helper.PlayerHolder; | ||||||
|  | import org.schabi.newpipe.util.StreamTypeUtil; | ||||||
| import org.schabi.newpipe.util.external_communication.KoreUtils; | import org.schabi.newpipe.util.external_communication.KoreUtils; | ||||||
|  |  | ||||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||||
| @@ -269,8 +270,7 @@ public final class InfoItemDialog { | |||||||
|          */ |          */ | ||||||
|         public Builder addStartHereEntries() { |         public Builder addStartHereEntries() { | ||||||
|             addEntry(StreamDialogDefaultEntry.START_HERE_ON_BACKGROUND); |             addEntry(StreamDialogDefaultEntry.START_HERE_ON_BACKGROUND); | ||||||
|             if (infoItem.getStreamType() != StreamType.AUDIO_STREAM |             if (!StreamTypeUtil.isAudio(infoItem.getStreamType())) { | ||||||
|                     && infoItem.getStreamType() != StreamType.AUDIO_LIVE_STREAM) { |  | ||||||
|                 addEntry(StreamDialogDefaultEntry.START_HERE_ON_POPUP); |                 addEntry(StreamDialogDefaultEntry.START_HERE_ON_POPUP); | ||||||
|             } |             } | ||||||
|             return this; |             return this; | ||||||
| @@ -285,9 +285,7 @@ public final class InfoItemDialog { | |||||||
|             final boolean isWatchHistoryEnabled = PreferenceManager |             final boolean isWatchHistoryEnabled = PreferenceManager | ||||||
|                     .getDefaultSharedPreferences(context) |                     .getDefaultSharedPreferences(context) | ||||||
|                     .getBoolean(context.getString(R.string.enable_watch_history_key), false); |                     .getBoolean(context.getString(R.string.enable_watch_history_key), false); | ||||||
|             if (isWatchHistoryEnabled |             if (isWatchHistoryEnabled && !StreamTypeUtil.isLiveStream(infoItem.getStreamType())) { | ||||||
|                     && infoItem.getStreamType() != StreamType.LIVE_STREAM |  | ||||||
|                     && infoItem.getStreamType() != StreamType.AUDIO_LIVE_STREAM) { |  | ||||||
|                 addEntry(StreamDialogDefaultEntry.MARK_AS_WATCHED); |                 addEntry(StreamDialogDefaultEntry.MARK_AS_WATCHED); | ||||||
|             } |             } | ||||||
|             return this; |             return this; | ||||||
|   | |||||||
| @@ -11,12 +11,12 @@ import org.schabi.newpipe.R; | |||||||
| import org.schabi.newpipe.database.stream.model.StreamStateEntity; | import org.schabi.newpipe.database.stream.model.StreamStateEntity; | ||||||
| import org.schabi.newpipe.extractor.InfoItem; | import org.schabi.newpipe.extractor.InfoItem; | ||||||
| import org.schabi.newpipe.extractor.stream.StreamInfoItem; | import org.schabi.newpipe.extractor.stream.StreamInfoItem; | ||||||
| import org.schabi.newpipe.extractor.stream.StreamType; |  | ||||||
| import org.schabi.newpipe.info_list.InfoItemBuilder; | import org.schabi.newpipe.info_list.InfoItemBuilder; | ||||||
| import org.schabi.newpipe.ktx.ViewUtils; | import org.schabi.newpipe.ktx.ViewUtils; | ||||||
| import org.schabi.newpipe.local.history.HistoryRecordManager; | import org.schabi.newpipe.local.history.HistoryRecordManager; | ||||||
| import org.schabi.newpipe.util.PicassoHelper; | import org.schabi.newpipe.util.PicassoHelper; | ||||||
| import org.schabi.newpipe.util.Localization; | import org.schabi.newpipe.util.Localization; | ||||||
|  | import org.schabi.newpipe.util.StreamTypeUtil; | ||||||
| import org.schabi.newpipe.views.AnimatedProgressBar; | import org.schabi.newpipe.views.AnimatedProgressBar; | ||||||
|  |  | ||||||
| import java.util.concurrent.TimeUnit; | import java.util.concurrent.TimeUnit; | ||||||
| @@ -70,8 +70,7 @@ public class StreamMiniInfoItemHolder extends InfoItemHolder { | |||||||
|             } else { |             } else { | ||||||
|                 itemProgressView.setVisibility(View.GONE); |                 itemProgressView.setVisibility(View.GONE); | ||||||
|             } |             } | ||||||
|         } else if (item.getStreamType() == StreamType.LIVE_STREAM |         } else if (StreamTypeUtil.isLiveStream(item.getStreamType())) { | ||||||
|                 || item.getStreamType() == StreamType.AUDIO_LIVE_STREAM) { |  | ||||||
|             itemDurationView.setText(R.string.duration_live); |             itemDurationView.setText(R.string.duration_live); | ||||||
|             itemDurationView.setBackgroundColor(ContextCompat.getColor(itemBuilder.getContext(), |             itemDurationView.setBackgroundColor(ContextCompat.getColor(itemBuilder.getContext(), | ||||||
|                     R.color.live_duration_background_color)); |                     R.color.live_duration_background_color)); | ||||||
| @@ -115,8 +114,7 @@ public class StreamMiniInfoItemHolder extends InfoItemHolder { | |||||||
|         final StreamStateEntity state |         final StreamStateEntity state | ||||||
|                 = historyRecordManager.loadStreamState(infoItem).blockingGet()[0]; |                 = historyRecordManager.loadStreamState(infoItem).blockingGet()[0]; | ||||||
|         if (state != null && item.getDuration() > 0 |         if (state != null && item.getDuration() > 0 | ||||||
|                 && item.getStreamType() != StreamType.LIVE_STREAM |                 && !StreamTypeUtil.isLiveStream(item.getStreamType())) { | ||||||
|                 && item.getStreamType() != StreamType.AUDIO_LIVE_STREAM) { |  | ||||||
|             itemProgressView.setMax((int) item.getDuration()); |             itemProgressView.setMax((int) item.getDuration()); | ||||||
|             if (itemProgressView.getVisibility() == View.VISIBLE) { |             if (itemProgressView.getVisibility() == View.VISIBLE) { | ||||||
|                 itemProgressView.setProgressAnimated((int) TimeUnit.MILLISECONDS |                 itemProgressView.setProgressAnimated((int) TimeUnit.MILLISECONDS | ||||||
|   | |||||||
| @@ -4234,10 +4234,7 @@ public final class Player implements | |||||||
|         if (playQueueManagerReloadingNeeded(sourceType, info, getVideoRendererIndex())) { |         if (playQueueManagerReloadingNeeded(sourceType, info, getVideoRendererIndex())) { | ||||||
|             reloadPlayQueueManager(); |             reloadPlayQueueManager(); | ||||||
|         } else { |         } else { | ||||||
|             final StreamType streamType = info.getStreamType(); |             if (StreamTypeUtil.isAudio(info.getStreamType())) { | ||||||
|             if (streamType == StreamType.AUDIO_STREAM |  | ||||||
|                     || streamType == StreamType.AUDIO_LIVE_STREAM |  | ||||||
|                     || streamType == StreamType.POST_LIVE_AUDIO_STREAM) { |  | ||||||
|                 // Nothing to do more than setting the recovery position |                 // Nothing to do more than setting the recovery position | ||||||
|                 setRecovery(); |                 setRecovery(); | ||||||
|                 return; |                 return; | ||||||
| @@ -4296,20 +4293,16 @@ public final class Player implements | |||||||
|                                                     @NonNull final StreamInfo streamInfo, |                                                     @NonNull final StreamInfo streamInfo, | ||||||
|                                                     final int videoRendererIndex) { |                                                     final int videoRendererIndex) { | ||||||
|         final StreamType streamType = streamInfo.getStreamType(); |         final StreamType streamType = streamInfo.getStreamType(); | ||||||
|  |         final boolean isStreamTypeAudio = StreamTypeUtil.isAudio(streamType); | ||||||
|  |  | ||||||
|         if (videoRendererIndex == RENDERER_UNAVAILABLE && streamType != StreamType.AUDIO_STREAM |         if (videoRendererIndex == RENDERER_UNAVAILABLE && !isStreamTypeAudio) { | ||||||
|                 && streamType != StreamType.AUDIO_LIVE_STREAM |  | ||||||
|                 && streamType != StreamType.POST_LIVE_AUDIO_STREAM) { |  | ||||||
|             return true; |             return true; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         // The content is an audio stream, an audio live stream, or a live stream with a live |         // The content is an audio stream, an audio live stream, or a live stream with a live | ||||||
|         // source: it's not needed to reload the play queue manager because the stream source will |         // source: it's not needed to reload the play queue manager because the stream source will | ||||||
|         // be the same |         // be the same | ||||||
|         if ((streamType == StreamType.AUDIO_STREAM |         if (isStreamTypeAudio || (streamType == StreamType.LIVE_STREAM | ||||||
|                 || streamType == StreamType.POST_LIVE_AUDIO_STREAM |  | ||||||
|                 || streamType == StreamType.AUDIO_LIVE_STREAM) |  | ||||||
|                 || (streamType == StreamType.LIVE_STREAM |  | ||||||
|                 && sourceType == SourceType.LIVE_STREAM)) { |                 && sourceType == SourceType.LIVE_STREAM)) { | ||||||
|             return false; |             return false; | ||||||
|         } |         } | ||||||
| @@ -4324,9 +4317,7 @@ public final class Player implements | |||||||
|                     && isNullOrEmpty(streamInfo.getAudioStreams()))) { |                     && isNullOrEmpty(streamInfo.getAudioStreams()))) { | ||||||
|             // It's not needed to reload the play queue manager only if the content's stream type |             // It's not needed to reload the play queue manager only if the content's stream type | ||||||
|             // is a video stream, a live stream or an ended live stream |             // is a video stream, a live stream or an ended live stream | ||||||
|             return streamType != StreamType.VIDEO_STREAM |             return !StreamTypeUtil.isVideo(streamType); | ||||||
|                     && streamType != StreamType.LIVE_STREAM |  | ||||||
|                     && streamType != StreamType.POST_LIVE_STREAM; |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         // Other cases: the play queue manager reload is needed |         // Other cases: the play queue manager reload is needed | ||||||
|   | |||||||
| @@ -1,7 +1,5 @@ | |||||||
| package org.schabi.newpipe.util; | package org.schabi.newpipe.util; | ||||||
|  |  | ||||||
| import static org.schabi.newpipe.extractor.stream.StreamType.AUDIO_LIVE_STREAM; |  | ||||||
| import static org.schabi.newpipe.extractor.stream.StreamType.LIVE_STREAM; |  | ||||||
| import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; | import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; | ||||||
|  |  | ||||||
| import android.content.Context; | import android.content.Context; | ||||||
| @@ -49,8 +47,8 @@ public final class SparseItemUtil { | |||||||
|     public static void fetchItemInfoIfSparse(@NonNull final Context context, |     public static void fetchItemInfoIfSparse(@NonNull final Context context, | ||||||
|                                              @NonNull final StreamInfoItem item, |                                              @NonNull final StreamInfoItem item, | ||||||
|                                              @NonNull final Consumer<SinglePlayQueue> callback) { |                                              @NonNull final Consumer<SinglePlayQueue> callback) { | ||||||
|         if (((item.getStreamType() == LIVE_STREAM || item.getStreamType() == AUDIO_LIVE_STREAM) |         if ((StreamTypeUtil.isLiveStream(item.getStreamType()) || item.getDuration() >= 0) | ||||||
|                 || item.getDuration() >= 0) && !isNullOrEmpty(item.getUploaderUrl())) { |                 && !isNullOrEmpty(item.getUploaderUrl())) { | ||||||
|             // if the duration is >= 0 (provided that the item is not a livestream) and there is an |             // if the duration is >= 0 (provided that the item is not a livestream) and there is an | ||||||
|             // uploader url, probably all info is already there, so there is no need to fetch it |             // uploader url, probably all info is already there, so there is no need to fetch it | ||||||
|             callback.accept(new SinglePlayQueue(item)); |             callback.accept(new SinglePlayQueue(item)); | ||||||
|   | |||||||
| @@ -14,8 +14,34 @@ public final class StreamTypeUtil { | |||||||
|      * Check if the {@link StreamType} of a stream is a livestream. |      * Check if the {@link StreamType} of a stream is a livestream. | ||||||
|      * |      * | ||||||
|      * @param streamType the stream type of the stream |      * @param streamType the stream type of the stream | ||||||
|      * @return <code>true</code> if the streamType is a |      * @return whether the stream type is {@link StreamType#AUDIO_STREAM}, | ||||||
|      * {@link StreamType#LIVE_STREAM} or {@link StreamType#AUDIO_LIVE_STREAM} |      * {@link StreamType#AUDIO_LIVE_STREAM} or {@link StreamType#POST_LIVE_AUDIO_STREAM} | ||||||
|  |      */ | ||||||
|  |     public static boolean isAudio(final StreamType streamType) { | ||||||
|  |         return streamType == StreamType.AUDIO_STREAM | ||||||
|  |                 || streamType == StreamType.AUDIO_LIVE_STREAM | ||||||
|  |                 || streamType == StreamType.POST_LIVE_AUDIO_STREAM; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Check if the {@link StreamType} of a stream is a livestream. | ||||||
|  |      * | ||||||
|  |      * @param streamType the stream type of the stream | ||||||
|  |      * @return whether the stream type is {@link StreamType#VIDEO_STREAM}, | ||||||
|  |      * {@link StreamType#LIVE_STREAM} or {@link StreamType#POST_LIVE_STREAM} | ||||||
|  |      */ | ||||||
|  |     public static boolean isVideo(final StreamType streamType) { | ||||||
|  |         return streamType == StreamType.VIDEO_STREAM | ||||||
|  |                 || streamType == StreamType.LIVE_STREAM | ||||||
|  |                 || streamType == StreamType.POST_LIVE_STREAM; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Check if the {@link StreamType} of a stream is a livestream. | ||||||
|  |      * | ||||||
|  |      * @param streamType the stream type of the stream | ||||||
|  |      * @return whether the stream type is {@link StreamType#LIVE_STREAM} or | ||||||
|  |      * {@link StreamType#AUDIO_LIVE_STREAM} | ||||||
|      */ |      */ | ||||||
|     public static boolean isLiveStream(final StreamType streamType) { |     public static boolean isLiveStream(final StreamType streamType) { | ||||||
|         return streamType == StreamType.LIVE_STREAM |         return streamType == StreamType.LIVE_STREAM | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 AudricV
					AudricV