Skip to content

Commit 5b0df8a

Browse files
Add buffering spinner to player for live TV channel tuning
Show a theme-colored loading spinner during ExoPlayer buffering state, improving visual feedback when tuning to live TV channels.
1 parent f6af0b8 commit 5b0df8a

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

app/src/main/java/org/jellyfin/androidtv/ui/playback/VideoManager.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import android.util.TypedValue;
1313
import android.view.View;
1414
import android.widget.FrameLayout;
15+
import android.widget.ProgressBar;
1516

1617
import androidx.annotation.NonNull;
1718
import 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;

app/src/main/res/layout/vlc_player_interface.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@
3838
android:layout_height="match_parent"
3939
android:layout_gravity="center" />
4040

41+
<ProgressBar
42+
android:id="@+id/bufferingSpinner"
43+
style="?android:attr/progressBarStyleLarge"
44+
android:layout_width="wrap_content"
45+
android:layout_height="wrap_content"
46+
android:layout_gravity="center"
47+
android:indeterminateTint="?android:attr/colorAccent"
48+
android:visibility="gone" />
49+
4150
</FrameLayout>
4251

4352
<FrameLayout

0 commit comments

Comments
 (0)