2222import android .util .Log ;
2323import android .view .LayoutInflater ;
2424import android .view .ViewGroup ;
25+ import android .widget .Button ;
2526import android .widget .FrameLayout ;
2627import android .widget .ImageButton ;
2728import android .widget .LinearLayout ;
2829import android .widget .RelativeLayout ;
29- import android .widget .TextView ;
30- import android .widget .Button ;
3130import android .widget .SeekBar ;
31+ import android .widget .TextView ;
32+
3233import androidx .annotation .DrawableRes ;
3334import androidx .annotation .NonNull ;
3435import androidx .annotation .Nullable ;
4647import androidx .media3 .ui .TimeBar ;
4748
4849import com .google .android .material .dialog .MaterialAlertDialogBuilder ;
50+
4951import org .quantumbadger .redreader .R ;
5052import org .quantumbadger .redreader .common .AndroidCommon ;
5153import org .quantumbadger .redreader .common .General ;
@@ -68,6 +70,7 @@ public interface Listener {
6870 @ NonNull private final ExoPlayer mVideoPlayer ;
6971
7072 @ Nullable private final RelativeLayout mControlView ;
73+ @ Nullable private final ImageButton mPlayButton ;
7174
7275 @ Nullable private final DefaultTimeBar mTimeBarView ;
7376 @ Nullable private final TextView mTimeTextView ;
@@ -165,34 +168,17 @@ public ExoPlayerWrapperView(
165168 updateProgress ();
166169 }), buttons );
167170
168- {
169- final AtomicReference <ImageButton > playButton = new AtomicReference <>();
170-
171- playButton .set (createButton (
172- context ,
173- mControlView ,
174- R .drawable .icon_pause ,
175- R .string .video_pause ,
176- view -> {
177- mVideoPlayer .setPlayWhenReady (!mVideoPlayer .getPlayWhenReady ());
178-
179- if (mVideoPlayer .getPlayWhenReady ()) {
180- playButton .get ()
181- .setImageResource (R .drawable .icon_pause );
182- playButton .get ().setContentDescription (
183- context .getString (R .string .video_pause ));
184- } else {
185- playButton .get ()
186- .setImageResource (R .drawable .icon_play );
187- playButton .get ().setContentDescription (
188- context .getString (R .string .video_play ));
189- }
190-
191- updateProgress ();
192- }));
171+ mPlayButton = createButton (
172+ context ,
173+ mControlView ,
174+ R .drawable .icon_pause ,
175+ R .string .video_pause ,
176+ view -> {
177+ mVideoPlayer .setPlayWhenReady (!mVideoPlayer .getPlayWhenReady ());
178+ updateProgress ();
179+ });
193180
194- addButton (playButton .get (), buttons );
195- }
181+ addButton (mPlayButton , buttons );
196182
197183 addButton (createButton (
198184 context ,
@@ -305,7 +291,8 @@ public void run() {
305291 mSpeedTextView = new TextView (context );
306292 timeAndSpeedLayout .addView (mSpeedTextView );
307293 mSpeedTextView .setTextColor (Color .WHITE );
308- mSpeedTextView .setText (String .format (Locale .US , "(%.2fx)" , mCurrentPlaybackSpeed ));
294+ // Initially empty
295+ mSpeedTextView .setText ("" );
309296
310297 final int marginSidesPx = General .dpToPixels (context , 16 );
311298 final int marginBottomPx = General .dpToPixels (context , 8 );
@@ -324,6 +311,7 @@ public void run() {
324311 mTimeBarView = null ;
325312 mTimeTextView = null ;
326313 mSpeedTextView = null ;
314+ mPlayButton = null ;
327315 }
328316
329317 videoPlayerView .setLayoutParams (new FrameLayout .LayoutParams (
@@ -345,6 +333,22 @@ public void onPositionDiscontinuity(
345333
346334 updateProgress ();
347335 }
336+
337+ @ Override
338+ public void onPlayWhenReadyChanged (boolean playWhenReady , int reason ) {
339+
340+ if (mPlayButton == null ) {
341+ return ;
342+ }
343+
344+ if (playWhenReady ) {
345+ mPlayButton .setImageResource (R .drawable .icon_pause );
346+ mPlayButton .setContentDescription (context .getString (R .string .video_pause ));
347+ } else {
348+ mPlayButton .setImageResource (R .drawable .icon_play );
349+ mPlayButton .setContentDescription (context .getString (R .string .video_play ));
350+ }
351+ }
348352 });
349353 }
350354
@@ -542,6 +546,7 @@ public void onStopTrackingTouch(final SeekBar seekBar) { }
542546 // Resume video playback when dialog is dismissed
543547 mVideoPlayer .setPlayWhenReady (true );
544548 });
549+
545550 builder .setNegativeButton (R .string .dialog_cancel , (dialog , which ) -> {
546551 // Resume video playback when dialog is dismissed
547552 mVideoPlayer .setPlayWhenReady (true );
0 commit comments