11package org .schabi .newpipe .player ;
22
3- import static com .google .android .exoplayer2 .Player .DISCONTINUITY_REASON_AD_INSERTION ;
3+ import static com .google .android .exoplayer2 .Player .DISCONTINUITY_REASON_AUTO_TRANSITION ;
44import static com .google .android .exoplayer2 .Player .DISCONTINUITY_REASON_INTERNAL ;
5- import static com .google .android .exoplayer2 .Player .DISCONTINUITY_REASON_PERIOD_TRANSITION ;
5+ import static com .google .android .exoplayer2 .Player .DISCONTINUITY_REASON_REMOVE ;
66import static com .google .android .exoplayer2 .Player .DISCONTINUITY_REASON_SEEK ;
77import static com .google .android .exoplayer2 .Player .DISCONTINUITY_REASON_SEEK_ADJUSTMENT ;
8+ import static com .google .android .exoplayer2 .Player .DISCONTINUITY_REASON_SKIP ;
89import static com .google .android .exoplayer2 .Player .DiscontinuityReason ;
9- import static com .google .android .exoplayer2 .Player .EventListener ;
10+ import static com .google .android .exoplayer2 .Player .Listener ;
1011import static com .google .android .exoplayer2 .Player .REPEAT_MODE_ALL ;
1112import static com .google .android .exoplayer2 .Player .REPEAT_MODE_OFF ;
1213import static com .google .android .exoplayer2 .Player .REPEAT_MODE_ONE ;
116117import com .google .android .exoplayer2 .DefaultRenderersFactory ;
117118import com .google .android .exoplayer2 .ExoPlaybackException ;
118119import com .google .android .exoplayer2 .PlaybackParameters ;
120+ import com .google .android .exoplayer2 .Player .PositionInfo ;
119121import com .google .android .exoplayer2 .RenderersFactory ;
120122import com .google .android .exoplayer2 .SimpleExoPlayer ;
121123import com .google .android .exoplayer2 .Timeline ;
122124import com .google .android .exoplayer2 .source .BehindLiveWindowException ;
123125import com .google .android .exoplayer2 .source .MediaSource ;
124126import com .google .android .exoplayer2 .source .TrackGroup ;
125127import com .google .android .exoplayer2 .source .TrackGroupArray ;
126- import com .google .android .exoplayer2 .text .CaptionStyleCompat ;
128+ import com .google .android .exoplayer2 .text .Cue ;
127129import com .google .android .exoplayer2 .trackselection .TrackSelectionArray ;
128130import com .google .android .exoplayer2 .ui .AspectRatioFrameLayout ;
131+ import com .google .android .exoplayer2 .ui .CaptionStyleCompat ;
129132import com .google .android .exoplayer2 .ui .SubtitleView ;
130133import com .google .android .exoplayer2 .upstream .DefaultBandwidthMeter ;
131134import com .google .android .exoplayer2 .util .Util ;
132- import com .google .android .exoplayer2 .video .VideoListener ;
135+ import com .google .android .exoplayer2 .video .VideoSize ;
133136import com .google .android .material .floatingactionbutton .FloatingActionButton ;
134137import com .squareup .picasso .Picasso ;
135138import com .squareup .picasso .Target ;
174177import org .schabi .newpipe .player .resolver .VideoPlaybackResolver ;
175178import org .schabi .newpipe .player .seekbarpreview .SeekbarPreviewThumbnailHelper ;
176179import org .schabi .newpipe .player .seekbarpreview .SeekbarPreviewThumbnailHolder ;
177- import org .schabi .newpipe .util .StreamTypeUtil ;
178180import org .schabi .newpipe .util .DeviceUtils ;
179181import org .schabi .newpipe .util .ListHelper ;
180182import org .schabi .newpipe .util .NavigationHelper ;
181183import org .schabi .newpipe .util .PicassoHelper ;
182184import org .schabi .newpipe .util .SerializedCache ;
185+ import org .schabi .newpipe .util .StreamTypeUtil ;
183186import org .schabi .newpipe .util .external_communication .KoreUtils ;
184187import org .schabi .newpipe .util .external_communication .ShareUtils ;
185188import org .schabi .newpipe .views .ExpandableSurfaceView ;
197200import io .reactivex .rxjava3 .disposables .SerialDisposable ;
198201
199202public final class Player implements
200- EventListener ,
201203 PlaybackListener ,
202- VideoListener ,
204+ Listener ,
203205 SeekBar .OnSeekBarChangeListener ,
204206 View .OnClickListener ,
205207 PopupMenu .OnMenuItemClickListener ,
@@ -501,10 +503,6 @@ private void initPlayer(final boolean playOnReady) {
501503
502504 // Setup video view
503505 setupVideoSurface ();
504- simpleExoPlayer .addVideoListener (this );
505-
506- // Setup subtitle view
507- simpleExoPlayer .addTextOutput (binding .subtitleView );
508506
509507 // enable media tunneling
510508 if (DEBUG && PreferenceManager .getDefaultSharedPreferences (context )
@@ -513,7 +511,7 @@ private void initPlayer(final boolean playOnReady) {
513511 + "media tunneling disabled in debug preferences" );
514512 } else if (DeviceUtils .shouldSupportMediaTunneling ()) {
515513 trackSelector .setParameters (trackSelector .buildUponParameters ()
516- .setTunnelingAudioSessionId ( C . generateAudioSessionIdV21 ( context ) ));
514+ .setTunnelingEnabled ( true ));
517515 } else if (DEBUG ) {
518516 Log .d (TAG , "[" + Util .DEVICE_DEBUG_INFO + "] does not support media tunneling" );
519517 }
@@ -809,7 +807,6 @@ private void destroyPlayer() {
809807
810808 if (!exoPlayerIsNull ()) {
811809 simpleExoPlayer .removeListener (this );
812- simpleExoPlayer .removeVideoListener (this );
813810 simpleExoPlayer .stop ();
814811 simpleExoPlayer .release ();
815812 }
@@ -898,7 +895,7 @@ public void onPlaybackShutdown() {
898895
899896 public void smoothStopPlayer () {
900897 // Pausing would make transition from one stream to a new stream not smooth, so only stop
901- simpleExoPlayer .stop (false );
898+ simpleExoPlayer .stop ();
902899 }
903900 //endregion
904901
@@ -2437,7 +2434,9 @@ public void onPlaybackParametersChanged(@NonNull final PlaybackParameters playba
24372434 }
24382435
24392436 @ Override
2440- public void onPositionDiscontinuity (@ DiscontinuityReason final int discontinuityReason ) {
2437+ public void onPositionDiscontinuity (
2438+ final PositionInfo oldPosition , final PositionInfo newPosition ,
2439+ @ DiscontinuityReason final int discontinuityReason ) {
24412440 if (DEBUG ) {
24422441 Log .d (TAG , "ExoPlayer - onPositionDiscontinuity() called with "
24432442 + "discontinuityReason = [" + discontinuityReason + "]" );
@@ -2449,7 +2448,7 @@ public void onPositionDiscontinuity(@DiscontinuityReason final int discontinuity
24492448 // Refresh the playback if there is a transition to the next video
24502449 final int newWindowIndex = simpleExoPlayer .getCurrentWindowIndex ();
24512450 switch (discontinuityReason ) {
2452- case DISCONTINUITY_REASON_PERIOD_TRANSITION :
2451+ case DISCONTINUITY_REASON_REMOVE :
24532452 // When player is in single repeat mode and a period transition occurs,
24542453 // we need to register a view count here since no metadata has changed
24552454 if (getRepeatMode () == REPEAT_MODE_ONE && newWindowIndex == playQueue .getIndex ()) {
@@ -2470,7 +2469,8 @@ public void onPositionDiscontinuity(@DiscontinuityReason final int discontinuity
24702469 playQueue .setIndex (newWindowIndex );
24712470 }
24722471 break ;
2473- case DISCONTINUITY_REASON_AD_INSERTION :
2472+ case DISCONTINUITY_REASON_SKIP :
2473+ case DISCONTINUITY_REASON_AUTO_TRANSITION :
24742474 break ; // only makes Android Studio linter happy, as there are no ads
24752475 }
24762476
@@ -2482,6 +2482,11 @@ public void onRenderedFirstFrame() {
24822482 //TODO check if this causes black screen when switching to fullscreen
24832483 animate (binding .surfaceForeground , false , DEFAULT_CONTROLS_DURATION );
24842484 }
2485+
2486+ @ Override
2487+ public void onCues (final List <Cue > cues ) {
2488+ binding .subtitleView .onCues (cues );
2489+ }
24852490 //endregion
24862491
24872492
@@ -2503,7 +2508,7 @@ public void onRenderedFirstFrame() {
25032508 * </ul>
25042509 *
25052510 * @see #processSourceError(IOException)
2506- * @see com.google.android.exoplayer2.Player.EventListener #onPlayerError(ExoPlaybackException)
2511+ * @see com.google.android.exoplayer2.Player.Listener #onPlayerError(ExoPlaybackException)
25072512 */
25082513 @ Override
25092514 public void onPlayerError (@ NonNull final ExoPlaybackException error ) {
@@ -3867,19 +3872,17 @@ void onResizeClicked() {
38673872 }
38683873
38693874 @ Override // exoplayer listener
3870- public void onVideoSizeChanged (final int width , final int height ,
3871- final int unappliedRotationDegrees ,
3872- final float pixelWidthHeightRatio ) {
3875+ public void onVideoSizeChanged (final VideoSize videoSize ) {
38733876 if (DEBUG ) {
38743877 Log .d (TAG , "onVideoSizeChanged() called with: "
3875- + "width / height = [" + width + " / " + height
3876- + " = " + (((float ) width ) / height ) + "], "
3877- + "unappliedRotationDegrees = [" + unappliedRotationDegrees + "], "
3878- + "pixelWidthHeightRatio = [" + pixelWidthHeightRatio + "]" );
3878+ + "width / height = [" + videoSize . width + " / " + videoSize . height
3879+ + " = " + (((float ) videoSize . width ) / videoSize . height ) + "], "
3880+ + "unappliedRotationDegrees = [" + videoSize . unappliedRotationDegrees + "], "
3881+ + "pixelWidthHeightRatio = [" + videoSize . pixelWidthHeightRatio + "]" );
38793882 }
38803883
3881- binding .surfaceView .setAspectRatio (((float ) width ) / height );
3882- isVerticalVideo = width < height ;
3884+ binding .surfaceView .setAspectRatio (((float ) videoSize . width ) / videoSize . height );
3885+ isVerticalVideo = videoSize . width < videoSize . height ;
38833886
38843887 if (globalScreenOrientationLocked (context )
38853888 && isFullscreen
0 commit comments