1212import android .util .TypedValue ;
1313import android .view .View ;
1414import android .widget .FrameLayout ;
15+ import android .widget .ProgressBar ;
1516
1617import androidx .annotation .NonNull ;
1718import androidx .annotation .Nullable ;
@@ -72,6 +73,7 @@ public class VideoManager {
7273 private PlaybackOverlayFragmentHelper _helper ;
7374 public ExoPlayer mExoPlayer ;
7475 private PlayerView mExoPlayerView ;
76+ @ Nullable private ProgressBar mBufferingSpinner ;
7577 private Handler mHandler = new Handler ();
7678
7779 private long mMetaDuration = -1 ;
@@ -106,6 +108,7 @@ public void onAudioSessionIdChanged(AnalyticsListener.EventTime eventTime, int a
106108
107109 mExoPlayerView = view .findViewById (R .id .exoPlayerView );
108110 mExoPlayerView .setPlayer (mExoPlayer );
111+ mBufferingSpinner = view .findViewById (R .id .bufferingSpinner );
109112 int strokeColor = userPreferences .get (UserPreferences .Companion .getSubtitleTextStrokeColor ()).intValue ();
110113 int textWeight = userPreferences .get (UserPreferences .Companion .getSubtitlesTextWeight ());
111114 CaptionStyleCompat subtitleStyle = new CaptionStyleCompat (
@@ -131,6 +134,7 @@ public void onPlayerError(@NonNull PlaybackException error) {
131134 @ Override
132135 public void onIsPlayingChanged (boolean isPlaying ) {
133136 if (isPlaying ) {
137+ setBufferingSpinnerVisible (false );
134138 if (mPlaybackControllerNotifiable != null ) mPlaybackControllerNotifiable .onPrepared ();
135139 startProgressLoop ();
136140 _helper .setScreensaverLock (true );
@@ -144,9 +148,11 @@ public void onIsPlayingChanged(boolean isPlaying) {
144148 public void onPlaybackStateChanged (int playbackState ) {
145149 if (playbackState == Player .STATE_BUFFERING ) {
146150 Timber .d ("Player is buffering" );
147- }
148-
149- if (playbackState == Player .STATE_ENDED ) {
151+ setBufferingSpinnerVisible (true );
152+ } else if (playbackState == Player .STATE_READY ) {
153+ setBufferingSpinnerVisible (false );
154+ } else if (playbackState == Player .STATE_ENDED ) {
155+ setBufferingSpinnerVisible (false );
150156 if (mPlaybackControllerNotifiable != null ) mPlaybackControllerNotifiable .onCompletion ();
151157 stopProgressLoop ();
152158 }
@@ -183,6 +189,14 @@ public void subscribe(@NonNull PlaybackControllerNotifiable notifier) {
183189 mPlaybackControllerNotifiable = notifier ;
184190 }
185191
192+ private void setBufferingSpinnerVisible (boolean visible ) {
193+ if (mBufferingSpinner != null ) {
194+ mActivity .runOnUiThread (() ->
195+ mBufferingSpinner .setVisibility (visible ? View .VISIBLE : View .GONE )
196+ );
197+ }
198+ }
199+
186200 private int determineExoPlayerExtensionRendererMode () {
187201 if (userPreferences .get (UserPreferences .Companion .getPreferExoPlayerFfmpeg ())) {
188202 return DefaultRenderersFactory .EXTENSION_RENDERER_MODE_PREFER ;
0 commit comments