11package org .schabi .newpipe .player ;
22
3+ import static com .google .android .exoplayer2 .Player .DISCONTINUITY_REASON_AD_INSERTION ;
4+ import static com .google .android .exoplayer2 .Player .DISCONTINUITY_REASON_INTERNAL ;
5+ import static com .google .android .exoplayer2 .Player .DISCONTINUITY_REASON_PERIOD_TRANSITION ;
6+ import static com .google .android .exoplayer2 .Player .DISCONTINUITY_REASON_SEEK ;
7+ import static com .google .android .exoplayer2 .Player .DISCONTINUITY_REASON_SEEK_ADJUSTMENT ;
8+ import static com .google .android .exoplayer2 .Player .DiscontinuityReason ;
9+ import static com .google .android .exoplayer2 .Player .EventListener ;
10+ import static com .google .android .exoplayer2 .Player .REPEAT_MODE_ALL ;
11+ import static com .google .android .exoplayer2 .Player .REPEAT_MODE_OFF ;
12+ import static com .google .android .exoplayer2 .Player .REPEAT_MODE_ONE ;
13+ import static com .google .android .exoplayer2 .Player .RepeatMode ;
14+ import static org .schabi .newpipe .QueueItemMenuUtil .openPopupMenu ;
15+ import static org .schabi .newpipe .extractor .ServiceList .YouTube ;
16+ import static org .schabi .newpipe .extractor .utils .Utils .isNullOrEmpty ;
17+ import static org .schabi .newpipe .ktx .ViewUtils .animate ;
18+ import static org .schabi .newpipe .ktx .ViewUtils .animateRotation ;
19+ import static org .schabi .newpipe .player .MainPlayer .ACTION_CLOSE ;
20+ import static org .schabi .newpipe .player .MainPlayer .ACTION_FAST_FORWARD ;
21+ import static org .schabi .newpipe .player .MainPlayer .ACTION_FAST_REWIND ;
22+ import static org .schabi .newpipe .player .MainPlayer .ACTION_PLAY_NEXT ;
23+ import static org .schabi .newpipe .player .MainPlayer .ACTION_PLAY_PAUSE ;
24+ import static org .schabi .newpipe .player .MainPlayer .ACTION_PLAY_PREVIOUS ;
25+ import static org .schabi .newpipe .player .MainPlayer .ACTION_RECREATE_NOTIFICATION ;
26+ import static org .schabi .newpipe .player .MainPlayer .ACTION_REPEAT ;
27+ import static org .schabi .newpipe .player .MainPlayer .ACTION_SHUFFLE ;
28+ import static org .schabi .newpipe .player .helper .PlayerHelper .MinimizeMode .MINIMIZE_ON_EXIT_MODE_BACKGROUND ;
29+ import static org .schabi .newpipe .player .helper .PlayerHelper .MinimizeMode .MINIMIZE_ON_EXIT_MODE_NONE ;
30+ import static org .schabi .newpipe .player .helper .PlayerHelper .MinimizeMode .MINIMIZE_ON_EXIT_MODE_POPUP ;
31+ import static org .schabi .newpipe .player .helper .PlayerHelper .buildCloseOverlayLayoutParams ;
32+ import static org .schabi .newpipe .player .helper .PlayerHelper .formatSpeed ;
33+ import static org .schabi .newpipe .player .helper .PlayerHelper .getMinimizeOnExitAction ;
34+ import static org .schabi .newpipe .player .helper .PlayerHelper .getMinimumVideoHeight ;
35+ import static org .schabi .newpipe .player .helper .PlayerHelper .getTimeString ;
36+ import static org .schabi .newpipe .player .helper .PlayerHelper .globalScreenOrientationLocked ;
37+ import static org .schabi .newpipe .player .helper .PlayerHelper .isPlaybackResumeEnabled ;
38+ import static org .schabi .newpipe .player .helper .PlayerHelper .nextRepeatMode ;
39+ import static org .schabi .newpipe .player .helper .PlayerHelper .nextResizeModeAndSaveToPrefs ;
40+ import static org .schabi .newpipe .player .helper .PlayerHelper .retrievePlaybackParametersFromPrefs ;
41+ import static org .schabi .newpipe .player .helper .PlayerHelper .retrievePlayerTypeFromIntent ;
42+ import static org .schabi .newpipe .player .helper .PlayerHelper .retrievePopupLayoutParamsFromPrefs ;
43+ import static org .schabi .newpipe .player .helper .PlayerHelper .retrieveSeekDurationFromPreferences ;
44+ import static org .schabi .newpipe .player .helper .PlayerHelper .savePlaybackParametersToPrefs ;
45+ import static org .schabi .newpipe .util .ListHelper .getPopupResolutionIndex ;
46+ import static org .schabi .newpipe .util .ListHelper .getResolutionIndex ;
47+ import static org .schabi .newpipe .util .Localization .assureCorrectAppLanguage ;
48+ import static org .schabi .newpipe .util .Localization .containsCaseInsensitive ;
49+ import static java .util .concurrent .TimeUnit .MILLISECONDS ;
50+
351import android .animation .Animator ;
452import android .animation .AnimatorListenerAdapter ;
553import android .animation .ObjectAnimator ;
94142import org .schabi .newpipe .extractor .MediaFormat ;
95143import org .schabi .newpipe .extractor .stream .StreamInfo ;
96144import org .schabi .newpipe .extractor .stream .StreamSegment ;
97- import org .schabi .newpipe .extractor .stream .StreamType ;
98145import org .schabi .newpipe .extractor .stream .VideoStream ;
99146import org .schabi .newpipe .fragments .OnScrollBelowItemsListener ;
100147import org .schabi .newpipe .fragments .detail .VideoDetailFragment ;
127174import org .schabi .newpipe .player .resolver .VideoPlaybackResolver ;
128175import org .schabi .newpipe .player .seekbarpreview .SeekbarPreviewThumbnailHelper ;
129176import org .schabi .newpipe .player .seekbarpreview .SeekbarPreviewThumbnailHolder ;
177+ import org .schabi .newpipe .util .StreamTypeUtil ;
130178import org .schabi .newpipe .util .DeviceUtils ;
131- import org .schabi .newpipe .util .external_communication .KoreUtils ;
132179import org .schabi .newpipe .util .ListHelper ;
133180import org .schabi .newpipe .util .NavigationHelper ;
134181import org .schabi .newpipe .util .PicassoHelper ;
135182import org .schabi .newpipe .util .SerializedCache ;
183+ import org .schabi .newpipe .util .external_communication .KoreUtils ;
136184import org .schabi .newpipe .util .external_communication .ShareUtils ;
137185import org .schabi .newpipe .views .ExpandableSurfaceView ;
138186
139187import java .io .IOException ;
140188import java .util .ArrayList ;
141189import java .util .List ;
142190import java .util .Objects ;
191+ import java .util .Optional ;
143192
144193import io .reactivex .rxjava3 .android .schedulers .AndroidSchedulers ;
145194import io .reactivex .rxjava3 .core .Observable ;
146195import io .reactivex .rxjava3 .disposables .CompositeDisposable ;
147196import io .reactivex .rxjava3 .disposables .Disposable ;
148197import io .reactivex .rxjava3 .disposables .SerialDisposable ;
149198
150- import static com .google .android .exoplayer2 .Player .DISCONTINUITY_REASON_AD_INSERTION ;
151- import static com .google .android .exoplayer2 .Player .DISCONTINUITY_REASON_INTERNAL ;
152- import static com .google .android .exoplayer2 .Player .DISCONTINUITY_REASON_PERIOD_TRANSITION ;
153- import static com .google .android .exoplayer2 .Player .DISCONTINUITY_REASON_SEEK ;
154- import static com .google .android .exoplayer2 .Player .DISCONTINUITY_REASON_SEEK_ADJUSTMENT ;
155- import static com .google .android .exoplayer2 .Player .DiscontinuityReason ;
156- import static com .google .android .exoplayer2 .Player .EventListener ;
157- import static com .google .android .exoplayer2 .Player .REPEAT_MODE_ALL ;
158- import static com .google .android .exoplayer2 .Player .REPEAT_MODE_OFF ;
159- import static com .google .android .exoplayer2 .Player .REPEAT_MODE_ONE ;
160- import static com .google .android .exoplayer2 .Player .RepeatMode ;
161- import static java .util .concurrent .TimeUnit .MILLISECONDS ;
162- import static org .schabi .newpipe .QueueItemMenuUtil .openPopupMenu ;
163- import static org .schabi .newpipe .extractor .ServiceList .YouTube ;
164- import static org .schabi .newpipe .extractor .utils .Utils .isNullOrEmpty ;
165- import static org .schabi .newpipe .ktx .ViewUtils .animate ;
166- import static org .schabi .newpipe .ktx .ViewUtils .animateRotation ;
167- import static org .schabi .newpipe .player .MainPlayer .ACTION_CLOSE ;
168- import static org .schabi .newpipe .player .MainPlayer .ACTION_FAST_FORWARD ;
169- import static org .schabi .newpipe .player .MainPlayer .ACTION_FAST_REWIND ;
170- import static org .schabi .newpipe .player .MainPlayer .ACTION_PLAY_NEXT ;
171- import static org .schabi .newpipe .player .MainPlayer .ACTION_PLAY_PAUSE ;
172- import static org .schabi .newpipe .player .MainPlayer .ACTION_PLAY_PREVIOUS ;
173- import static org .schabi .newpipe .player .MainPlayer .ACTION_RECREATE_NOTIFICATION ;
174- import static org .schabi .newpipe .player .MainPlayer .ACTION_REPEAT ;
175- import static org .schabi .newpipe .player .MainPlayer .ACTION_SHUFFLE ;
176- import static org .schabi .newpipe .player .helper .PlayerHelper .MinimizeMode .MINIMIZE_ON_EXIT_MODE_BACKGROUND ;
177- import static org .schabi .newpipe .player .helper .PlayerHelper .MinimizeMode .MINIMIZE_ON_EXIT_MODE_NONE ;
178- import static org .schabi .newpipe .player .helper .PlayerHelper .MinimizeMode .MINIMIZE_ON_EXIT_MODE_POPUP ;
179- import static org .schabi .newpipe .player .helper .PlayerHelper .buildCloseOverlayLayoutParams ;
180- import static org .schabi .newpipe .player .helper .PlayerHelper .formatSpeed ;
181- import static org .schabi .newpipe .player .helper .PlayerHelper .getMinimizeOnExitAction ;
182- import static org .schabi .newpipe .player .helper .PlayerHelper .getMinimumVideoHeight ;
183- import static org .schabi .newpipe .player .helper .PlayerHelper .getTimeString ;
184- import static org .schabi .newpipe .player .helper .PlayerHelper .globalScreenOrientationLocked ;
185- import static org .schabi .newpipe .player .helper .PlayerHelper .isPlaybackResumeEnabled ;
186- import static org .schabi .newpipe .player .helper .PlayerHelper .nextRepeatMode ;
187- import static org .schabi .newpipe .player .helper .PlayerHelper .nextResizeModeAndSaveToPrefs ;
188- import static org .schabi .newpipe .player .helper .PlayerHelper .retrievePlaybackParametersFromPrefs ;
189- import static org .schabi .newpipe .player .helper .PlayerHelper .retrievePlayerTypeFromIntent ;
190- import static org .schabi .newpipe .player .helper .PlayerHelper .retrievePopupLayoutParamsFromPrefs ;
191- import static org .schabi .newpipe .player .helper .PlayerHelper .retrieveSeekDurationFromPreferences ;
192- import static org .schabi .newpipe .player .helper .PlayerHelper .savePlaybackParametersToPrefs ;
193- import static org .schabi .newpipe .util .ListHelper .getPopupResolutionIndex ;
194- import static org .schabi .newpipe .util .ListHelper .getResolutionIndex ;
195- import static org .schabi .newpipe .util .Localization .assureCorrectAppLanguage ;
196- import static org .schabi .newpipe .util .Localization .containsCaseInsensitive ;
197-
198199public final class Player implements
199200 EventListener ,
200201 PlaybackListener ,
@@ -1622,12 +1623,6 @@ private void onUpdateProgress(final int currentProgress,
16221623 if (isQueueVisible ) {
16231624 updateQueueTime (currentProgress );
16241625 }
1625-
1626- final boolean showThumbnail = prefs .getBoolean (
1627- context .getString (R .string .show_thumbnail_key ), true );
1628- // setMetadata only updates the metadata when any of the metadata keys are null
1629- mediaSessionManager .setMetadata (getVideoTitle (), getUploaderName (),
1630- showThumbnail ? getThumbnail () : null , duration );
16311626 }
16321627
16331628 private void startProgressLoop () {
@@ -1652,10 +1647,10 @@ private void triggerProgressUpdate() {
16521647 // TODO: revert #6307 when introducing proper HLS support
16531648 final int duration ;
16541649 if (currentItem != null
1655- && currentItem .getStreamType () != StreamType . AUDIO_LIVE_STREAM
1656- && currentItem . getStreamType () != StreamType . LIVE_STREAM ) {
1650+ && ! StreamTypeUtil . isLiveStream ( currentItem .getStreamType ())
1651+ ) {
16571652 // convert seconds to milliseconds
1658- duration = (int ) (currentItem .getDuration () * 1000 );
1653+ duration = (int ) (currentItem .getDuration () * 1000 );
16591654 } else {
16601655 duration = (int ) simpleExoPlayer .getDuration ();
16611656 }
@@ -2946,6 +2941,18 @@ private void onMetadataChanged(@NonNull final MediaSourceTag tag) {
29462941 tag .getMetadata ().getPreviewFrames ());
29472942
29482943 NotificationUtil .getInstance ().createNotificationIfNeededAndUpdate (this , false );
2944+
2945+ final boolean showThumbnail = prefs .getBoolean (
2946+ context .getString (R .string .show_thumbnail_key ), true );
2947+ mediaSessionManager .setMetadata (
2948+ getVideoTitle (),
2949+ getUploaderName (),
2950+ showThumbnail ? Optional .ofNullable (getThumbnail ()) : Optional .empty (),
2951+ StreamTypeUtil .isLiveStream (tag .getMetadata ().getStreamType ())
2952+ ? -1
2953+ : tag .getMetadata ().getDuration ()
2954+ );
2955+
29492956 notifyMetadataUpdateToListeners ();
29502957
29512958 if (areSegmentsVisible ) {
@@ -3023,9 +3030,11 @@ public String getUploaderName() {
30233030
30243031 @ Nullable
30253032 public Bitmap getThumbnail () {
3026- return currentThumbnail == null
3027- ? BitmapFactory .decodeResource (context .getResources (), R .drawable .dummy_thumbnail )
3028- : currentThumbnail ;
3033+ if (currentThumbnail == null ) {
3034+ currentThumbnail = BitmapFactory .decodeResource (
3035+ context .getResources (), R .drawable .dummy_thumbnail );
3036+ }
3037+ return currentThumbnail ;
30293038 }
30303039 //endregion
30313040
0 commit comments