@@ -138,6 +138,8 @@ public class CustomPlaybackOverlayFragment extends Fragment implements LiveTvGui
138
138
139
139
private final PlaybackOverlayFragmentHelper helper = new PlaybackOverlayFragmentHelper (this );
140
140
141
+ private PlaybackController playbackController ;
142
+
141
143
@ Override
142
144
public void onCreate (Bundle savedInstanceState ) {
143
145
super .onCreate (savedInstanceState );
@@ -161,6 +163,8 @@ public void onCreate(Bundle savedInstanceState) {
161
163
162
164
playbackControllerContainer .getValue ().setPlaybackController (new PlaybackController (mItemsToPlay , this , mediaPosition ));
163
165
166
+ playbackController = playbackControllerContainer .getValue ().getPlaybackController ();
167
+
164
168
// setup fade task
165
169
mHideTask = () -> {
166
170
if (mIsVisible ) {
@@ -218,8 +222,8 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
218
222
return ;
219
223
}
220
224
221
- if (playbackControllerContainer . getValue (). getPlaybackController () != null ) {
222
- playbackControllerContainer . getValue (). getPlaybackController () .init (new VideoManager ((requireActivity ()), view , helper ), this );
225
+ if (playbackController != null ) {
226
+ playbackController .init (new VideoManager ((requireActivity ()), view , helper ), this );
223
227
}
224
228
}
225
229
@@ -294,7 +298,7 @@ public void onScrollChanged(ObservableHorizontalScrollView scrollView, int x, in
294
298
int startPos = getArguments ().getInt ("Position" , 0 );
295
299
296
300
// start playing
297
- playbackControllerContainer . getValue (). getPlaybackController () .play (startPos );
301
+ playbackController .play (startPos );
298
302
leanbackOverlayFragment .updatePlayState ();
299
303
300
304
// Set initial skip overlay state
@@ -356,7 +360,7 @@ public void onAnimationRepeat(Animation animation) {
356
360
public void onAudioFocusChange (int focusChange ) {
357
361
switch (focusChange ) {
358
362
case AudioManager .AUDIOFOCUS_LOSS_TRANSIENT :
359
- playbackControllerContainer . getValue (). getPlaybackController () .pause ();
363
+ playbackController .pause ();
360
364
break ;
361
365
case AudioManager .AUDIOFOCUS_LOSS :
362
366
// We don't do anything here on purpose
@@ -375,7 +379,7 @@ public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item,
375
379
if (item instanceof ChapterItemInfoBaseRowItem ) {
376
380
ChapterItemInfoBaseRowItem rowItem = (ChapterItemInfoBaseRowItem ) item ;
377
381
Long start = rowItem .getChapterInfo ().getStartPositionTicks () / 10000 ;
378
- playbackControllerContainer . getValue (). getPlaybackController () .seek (start );
382
+ playbackController .seek (start );
379
383
hidePopupPanel ();
380
384
} else if (item instanceof BaseItemDto ) {
381
385
hidePopupPanel ();
@@ -393,7 +397,7 @@ public void handleOnBackPressed() {
393
397
leanbackOverlayFragment .hideOverlay ();
394
398
395
399
// also close this if live tv
396
- if (playbackControllerContainer . getValue (). getPlaybackController () .isLiveTv ()) hide ();
400
+ if (playbackController .isLiveTv ()) hide ();
397
401
} else if (mGuideVisible ) {
398
402
hideGuide ();
399
403
} else {
@@ -436,20 +440,23 @@ else if (mSelectedProgramView instanceof GuideChannelHeader)
436
440
return false ;
437
441
}
438
442
443
+ playbackControllerContainer .getValue ().setEpisodeWasInterrupted (true );
444
+ playbackControllerContainer .getValue ().resetEpisodesPlayedWithoutInterruption ();
445
+
439
446
if (keyCode == KeyEvent .KEYCODE_MEDIA_PLAY ) {
440
- playbackControllerContainer . getValue (). getPlaybackController () .play (0 );
447
+ playbackController .play (0 );
441
448
return true ;
442
449
} else if (keyCode == KeyEvent .KEYCODE_MEDIA_PAUSE ) {
443
- playbackControllerContainer . getValue (). getPlaybackController () .pause ();
450
+ playbackController .pause ();
444
451
return true ;
445
452
} else if (keyCode == KeyEvent .KEYCODE_MEDIA_PLAY_PAUSE ) {
446
- playbackControllerContainer . getValue (). getPlaybackController () .playPause ();
453
+ playbackController .playPause ();
447
454
return true ;
448
455
} else if (keyCode == KeyEvent .KEYCODE_MEDIA_FAST_FORWARD || keyCode == KeyEvent .KEYCODE_BUTTON_R1 || keyCode == KeyEvent .KEYCODE_BUTTON_R2 ) {
449
- playbackControllerContainer . getValue (). getPlaybackController () .fastForward ();
456
+ playbackController .fastForward ();
450
457
return true ;
451
458
} else if (keyCode == KeyEvent .KEYCODE_MEDIA_REWIND || keyCode == KeyEvent .KEYCODE_BUTTON_L1 || keyCode == KeyEvent .KEYCODE_BUTTON_L2 ) {
452
- playbackControllerContainer . getValue (). getPlaybackController () .rewind ();
459
+ playbackController .rewind ();
453
460
return true ;
454
461
}
455
462
}
@@ -485,7 +492,7 @@ public boolean onKey(View v, int keyCode, KeyEvent event) {
485
492
486
493
// Hide with seek
487
494
if (keyCode == KeyEvent .KEYCODE_DPAD_CENTER || keyCode == KeyEvent .KEYCODE_ENTER ) {
488
- playbackControllerContainer . getValue (). getPlaybackController () .seek (binding .skipOverlay .getTargetPositionMs (), true );
495
+ playbackController .seek (binding .skipOverlay .getTargetPositionMs (), true );
489
496
leanbackOverlayFragment .setShouldShowOverlay (false );
490
497
if (binding != null ) binding .skipOverlay .setTargetPositionMs (null );
491
498
return true ;
@@ -504,15 +511,15 @@ public boolean onKey(View v, int keyCode, KeyEvent event) {
504
511
leanbackOverlayFragment .hideOverlay ();
505
512
506
513
// also close this if live tv
507
- if (playbackControllerContainer . getValue (). getPlaybackController () .isLiveTv ()) hide ();
514
+ if (playbackController .isLiveTv ()) hide ();
508
515
return true ;
509
516
} else if (mGuideVisible ) {
510
517
hideGuide ();
511
518
return true ;
512
519
}
513
520
}
514
521
515
- if (playbackControllerContainer . getValue (). getPlaybackController () .isLiveTv () && !mPopupPanelVisible && !mGuideVisible && keyCode == KeyEvent .KEYCODE_DPAD_DOWN ) {
522
+ if (playbackController .isLiveTv () && !mPopupPanelVisible && !mGuideVisible && keyCode == KeyEvent .KEYCODE_DPAD_DOWN ) {
516
523
if (!leanbackOverlayFragment .isControlsOverlayVisible ()) {
517
524
leanbackOverlayFragment .setShouldShowOverlay (false );
518
525
leanbackOverlayFragment .hideOverlay ();
@@ -541,7 +548,7 @@ public boolean onKey(View v, int keyCode, KeyEvent event) {
541
548
}
542
549
}
543
550
544
- if (playbackControllerContainer . getValue (). getPlaybackController () .isLiveTv () && keyCode == KeyEvent .KEYCODE_MENU || keyCode == KeyEvent .KEYCODE_BUTTON_Y ) {
551
+ if (playbackController .isLiveTv () && keyCode == KeyEvent .KEYCODE_MENU || keyCode == KeyEvent .KEYCODE_BUTTON_Y ) {
545
552
showGuide ();
546
553
return true ;
547
554
}
@@ -557,7 +564,7 @@ public boolean onKey(View v, int keyCode, KeyEvent event) {
557
564
// up or down should close panel
558
565
if (keyCode == KeyEvent .KEYCODE_DPAD_DOWN || keyCode == KeyEvent .KEYCODE_DPAD_UP ) {
559
566
hidePopupPanel ();
560
- if (playbackControllerContainer . getValue (). getPlaybackController () .isLiveTv ())
567
+ if (playbackController .isLiveTv ())
561
568
hide (); //also close this if live tv
562
569
return true ;
563
570
} else {
@@ -566,22 +573,22 @@ public boolean onKey(View v, int keyCode, KeyEvent event) {
566
573
}
567
574
568
575
// Control fast forward and rewind if overlay hidden and not showing live TV
569
- if (!playbackControllerContainer . getValue (). getPlaybackController () .isLiveTv ()) {
576
+ if (!playbackController .isLiveTv ()) {
570
577
if (keyCode == KeyEvent .KEYCODE_MEDIA_FAST_FORWARD || keyCode == KeyEvent .KEYCODE_BUTTON_R1 || keyCode == KeyEvent .KEYCODE_BUTTON_R2 ) {
571
- playbackControllerContainer . getValue (). getPlaybackController () .fastForward ();
578
+ playbackController .fastForward ();
572
579
setFadingEnabled (true );
573
580
return true ;
574
581
}
575
582
576
583
if (keyCode == KeyEvent .KEYCODE_MEDIA_REWIND || keyCode == KeyEvent .KEYCODE_BUTTON_L1 || keyCode == KeyEvent .KEYCODE_BUTTON_L2 ) {
577
- playbackControllerContainer . getValue (). getPlaybackController () .rewind ();
584
+ playbackController .rewind ();
578
585
setFadingEnabled (true );
579
586
return true ;
580
587
}
581
588
}
582
589
583
590
if (!mIsVisible ) {
584
- if (!playbackControllerContainer . getValue (). getPlaybackController () .isLiveTv ()) {
591
+ if (!playbackController .isLiveTv ()) {
585
592
if (keyCode == KeyEvent .KEYCODE_DPAD_RIGHT ) {
586
593
setFadingEnabled (true );
587
594
return true ;
@@ -594,10 +601,10 @@ public boolean onKey(View v, int keyCode, KeyEvent event) {
594
601
}
595
602
596
603
if ((keyCode == KeyEvent .KEYCODE_DPAD_CENTER || keyCode == KeyEvent .KEYCODE_ENTER )
597
- && playbackControllerContainer . getValue (). getPlaybackController () .canSeek ()) {
604
+ && playbackController .canSeek ()) {
598
605
// if the player is playing and the overlay is hidden, this will pause
599
606
// if the player is paused and then 'back' is pressed to hide the overlay, this will play
600
- playbackControllerContainer . getValue (). getPlaybackController () .playPause ();
607
+ playbackController .playPause ();
601
608
return true ;
602
609
}
603
610
}
@@ -630,12 +637,12 @@ public void switchChannel(UUID id) {
630
637
}
631
638
632
639
public void switchChannel (UUID id , boolean hideGuide ) {
633
- if (playbackControllerContainer . getValue (). getPlaybackController () .getCurrentlyPlayingItem ().getId ().equals (id )) {
640
+ if (playbackController .getCurrentlyPlayingItem ().getId ().equals (id )) {
634
641
// same channel, just dismiss overlay
635
642
if (hideGuide )
636
643
hideGuide ();
637
644
} else {
638
- playbackControllerContainer . getValue (). getPlaybackController () .stop ();
645
+ playbackController .stop ();
639
646
if (hideGuide )
640
647
hideGuide ();
641
648
@@ -654,7 +661,6 @@ public void onResume() {
654
661
super .onResume ();
655
662
656
663
// Close player when resuming without a valid playback controller
657
- PlaybackController playbackController = playbackControllerContainer .getValue ().getPlaybackController ();
658
664
if (playbackController == null || !playbackController .hasFragment ()) {
659
665
closePlayer ();
660
666
@@ -693,9 +699,9 @@ public void onStop() {
693
699
694
700
// end playback from here if this fragment belongs to the current session.
695
701
// if it doesn't, playback has already been stopped elsewhere, and the references to this have been replaced
696
- if (playbackControllerContainer . getValue (). getPlaybackController () != null && playbackControllerContainer . getValue (). getPlaybackController () .getFragment () == this ) {
702
+ if (playbackController != null && playbackController .getFragment () == this ) {
697
703
Timber .d ("this fragment belongs to the current session, ending it" );
698
- playbackControllerContainer . getValue (). getPlaybackController () .endPlayback ();
704
+ playbackController .endPlayback ();
699
705
}
700
706
701
707
closePlayer ();
@@ -736,7 +742,7 @@ public void showGuide() {
736
742
hide ();
737
743
leanbackOverlayFragment .setShouldShowOverlay (false );
738
744
leanbackOverlayFragment .hideOverlay ();
739
- playbackControllerContainer . getValue (). getPlaybackController () .mVideoManager .contractVideo (Utils .convertDpToPixel (requireContext (), 300 ));
745
+ playbackController .mVideoManager .contractVideo (Utils .convertDpToPixel (requireContext (), 300 ));
740
746
tvGuideBinding .getRoot ().setVisibility (View .VISIBLE );
741
747
mGuideVisible = true ;
742
748
LocalDateTime now = LocalDateTime .now ();
@@ -755,7 +761,7 @@ public void showGuide() {
755
761
756
762
private void hideGuide () {
757
763
tvGuideBinding .getRoot ().setVisibility (View .GONE );
758
- playbackControllerContainer . getValue (). getPlaybackController () .mVideoManager .setVideoFullSize (true );
764
+ playbackController .mVideoManager .setVideoFullSize (true );
759
765
mGuideVisible = false ;
760
766
binding .skipOverlay .setSkipUiEnabled (!mIsVisible && !mGuideVisible && !mPopupPanelVisible );
761
767
}
@@ -825,7 +831,7 @@ protected void onPreExecute() {
825
831
Timber .d ("*** Display programs pre-execute" );
826
832
tvGuideBinding .channels .removeAllViews ();
827
833
tvGuideBinding .programRows .removeAllViews ();
828
- mFirstFocusChannelId = playbackControllerContainer . getValue (). getPlaybackController () .getCurrentlyPlayingItem ().getId ();
834
+ mFirstFocusChannelId = playbackController .getCurrentlyPlayingItem ().getId ();
829
835
830
836
if (mCurrentDisplayChannelStartNdx > 0 ) {
831
837
// Show a paging row for channels above
@@ -1134,7 +1140,7 @@ public void showChapterSelector() {
1134
1140
mHandler .postDelayed (() -> {
1135
1141
if (!getLifecycle ().getCurrentState ().isAtLeast (Lifecycle .State .STARTED )) return ;
1136
1142
1137
- int ndx = getCurrentChapterIndex (playbackControllerContainer . getValue (). getPlaybackController (). getCurrentlyPlayingItem (), playbackControllerContainer . getValue (). getPlaybackController () .getCurrentPosition () * 10000 );
1143
+ int ndx = getCurrentChapterIndex (playbackController . getCurrentlyPlayingItem (), playbackController .getCurrentPosition () * 10000 );
1138
1144
if (ndx > 0 ) {
1139
1145
mPopupRowPresenter .setPosition (ndx );
1140
1146
}
@@ -1223,7 +1229,7 @@ public void setPlayPauseActionState(final int state) {
1223
1229
}
1224
1230
1225
1231
public void updateDisplay () {
1226
- BaseItemDto current = playbackControllerContainer . getValue (). getPlaybackController () .getCurrentlyPlayingItem ();
1232
+ BaseItemDto current = playbackController .getCurrentlyPlayingItem ();
1227
1233
if (current != null && getContext () != null ) {
1228
1234
leanbackOverlayFragment .mediaInfoChanged ();
1229
1235
leanbackOverlayFragment .onFullyInitialized ();
@@ -1251,7 +1257,7 @@ public void updateDisplay() {
1251
1257
binding .itemTitle .setVisibility (View .VISIBLE );
1252
1258
}
1253
1259
1254
- if (playbackControllerContainer . getValue (). getPlaybackController () .isLiveTv ()) {
1260
+ if (playbackController .isLiveTv ()) {
1255
1261
prepareChannelAdapter ();
1256
1262
} else {
1257
1263
prepareChapterAdapter ();
@@ -1260,7 +1266,7 @@ public void updateDisplay() {
1260
1266
}
1261
1267
1262
1268
private void prepareChapterAdapter () {
1263
- BaseItemDto item = playbackControllerContainer . getValue (). getPlaybackController () .getCurrentlyPlayingItem ();
1269
+ BaseItemDto item = playbackController .getCurrentlyPlayingItem ();
1264
1270
List <ChapterInfo > chapters = item .getChapters ();
1265
1271
1266
1272
if (chapters != null && !chapters .isEmpty ()) {
0 commit comments