@picsa/capacitor-video-player 8.0.2 → 8.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -301,7 +301,9 @@ public class FullscreenExoPlayerFragment extends Fragment {
|
|
|
301
301
|
new PlayerView.ControllerVisibilityListener() {
|
|
302
302
|
@Override
|
|
303
303
|
public void onVisibilityChanged(int visibility) {
|
|
304
|
-
linearLayout
|
|
304
|
+
if (linearLayout != null) {
|
|
305
|
+
linearLayout.setVisibility(visibility);
|
|
306
|
+
}
|
|
305
307
|
}
|
|
306
308
|
}
|
|
307
309
|
);
|
|
@@ -310,6 +312,9 @@ public class FullscreenExoPlayerFragment extends Fragment {
|
|
|
310
312
|
new Player.Listener() {
|
|
311
313
|
@Override
|
|
312
314
|
public void onPlayerStateChanged(boolean playWhenReady, int state) {
|
|
315
|
+
if (isFragmentDestroyed || player == null || styledPlayerView == null) {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
313
318
|
String stateString;
|
|
314
319
|
Map<String, Object> info = new HashMap<String, Object>() {
|
|
315
320
|
{
|
|
@@ -546,7 +551,9 @@ public class FullscreenExoPlayerFragment extends Fragment {
|
|
|
546
551
|
|
|
547
552
|
@Override
|
|
548
553
|
protected void onPostExecute(Bitmap result) {
|
|
549
|
-
cast_image
|
|
554
|
+
if (cast_image != null) {
|
|
555
|
+
cast_image.setImageBitmap(result);
|
|
556
|
+
}
|
|
550
557
|
}
|
|
551
558
|
}
|
|
552
559
|
|
|
@@ -554,14 +561,16 @@ public class FullscreenExoPlayerFragment extends Fragment {
|
|
|
554
561
|
* Show controller
|
|
555
562
|
*/
|
|
556
563
|
public void showController() {
|
|
557
|
-
styledPlayerView
|
|
564
|
+
if (styledPlayerView != null) {
|
|
565
|
+
styledPlayerView.showController();
|
|
566
|
+
}
|
|
558
567
|
}
|
|
559
568
|
|
|
560
569
|
/**
|
|
561
570
|
* isControllerIsFullyVisible
|
|
562
571
|
*/
|
|
563
572
|
public boolean isControllerIsFullyVisible() {
|
|
564
|
-
return styledPlayerView.isControllerFullyVisible();
|
|
573
|
+
return styledPlayerView != null && styledPlayerView.isControllerFullyVisible();
|
|
565
574
|
}
|
|
566
575
|
|
|
567
576
|
/**
|
|
@@ -587,6 +596,7 @@ public class FullscreenExoPlayerFragment extends Fragment {
|
|
|
587
596
|
if (
|
|
588
597
|
!isInPictureInPictureMode &&
|
|
589
598
|
Build.VERSION.SDK_INT >= Build.VERSION_CODES.N &&
|
|
599
|
+
packageManager != null &&
|
|
590
600
|
packageManager.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE) &&
|
|
591
601
|
Boolean.TRUE.equals(isPIPModeeEnabled) &&
|
|
592
602
|
Boolean.TRUE.equals(pipEnabled) &&
|
|
@@ -599,18 +609,21 @@ public class FullscreenExoPlayerFragment extends Fragment {
|
|
|
599
609
|
}
|
|
600
610
|
|
|
601
611
|
private void resizePressed() {
|
|
612
|
+
if (styledPlayerView == null) {
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
602
615
|
if (resizeStatus == AspectRatioFrameLayout.RESIZE_MODE_FIT) {
|
|
603
616
|
styledPlayerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FILL);
|
|
604
617
|
resizeStatus = AspectRatioFrameLayout.RESIZE_MODE_FILL;
|
|
605
|
-
resizeBtn.setImageResource(R.drawable.ic_zoom);
|
|
618
|
+
if (resizeBtn != null) resizeBtn.setImageResource(R.drawable.ic_zoom);
|
|
606
619
|
} else if (resizeStatus == AspectRatioFrameLayout.RESIZE_MODE_FILL) {
|
|
607
620
|
styledPlayerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_ZOOM);
|
|
608
621
|
resizeStatus = AspectRatioFrameLayout.RESIZE_MODE_ZOOM;
|
|
609
|
-
resizeBtn.setImageResource(R.drawable.ic_fit);
|
|
622
|
+
if (resizeBtn != null) resizeBtn.setImageResource(R.drawable.ic_fit);
|
|
610
623
|
} else {
|
|
611
624
|
styledPlayerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FIT);
|
|
612
625
|
resizeStatus = AspectRatioFrameLayout.RESIZE_MODE_FIT;
|
|
613
|
-
resizeBtn.setImageResource(R.drawable.ic_expand);
|
|
626
|
+
if (resizeBtn != null) resizeBtn.setImageResource(R.drawable.ic_expand);
|
|
614
627
|
}
|
|
615
628
|
}
|
|
616
629
|
|
|
@@ -645,7 +658,7 @@ public class FullscreenExoPlayerFragment extends Fragment {
|
|
|
645
658
|
* Perform pictureInPictureMode Action
|
|
646
659
|
*/
|
|
647
660
|
private void pictureInPictureMode() {
|
|
648
|
-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && packageManager.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)) {
|
|
661
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && packageManager != null && packageManager.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)) {
|
|
649
662
|
// Store activity reference to avoid multiple getActivity() calls and check for null
|
|
650
663
|
// Fragment may be detached from activity during transitions or configuration changes
|
|
651
664
|
Activity activity = getActivity();
|
|
@@ -653,9 +666,13 @@ public class FullscreenExoPlayerFragment extends Fragment {
|
|
|
653
666
|
Log.v(TAG, "pictureInPictureMode: activity is null");
|
|
654
667
|
return;
|
|
655
668
|
}
|
|
656
|
-
styledPlayerView
|
|
657
|
-
|
|
658
|
-
|
|
669
|
+
if (styledPlayerView != null) {
|
|
670
|
+
styledPlayerView.setUseController(false);
|
|
671
|
+
styledPlayerView.setControllerAutoShow(false);
|
|
672
|
+
}
|
|
673
|
+
if (linearLayout != null) {
|
|
674
|
+
linearLayout.setVisibility(View.INVISIBLE);
|
|
675
|
+
}
|
|
659
676
|
Log.v(TAG, "PIP break 1");
|
|
660
677
|
// require android O or higher
|
|
661
678
|
if (
|
|
@@ -663,9 +680,13 @@ public class FullscreenExoPlayerFragment extends Fragment {
|
|
|
663
680
|
) {
|
|
664
681
|
pictureInPictureParams = new PictureInPictureParams.Builder();
|
|
665
682
|
// setup aspect ratio of the PIP window; fall back to 16:9 for audio-only or not-yet-decoded video
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
683
|
+
if (player != null) {
|
|
684
|
+
VideoSize videoSize = player.getVideoSize();
|
|
685
|
+
if (videoSize != VideoSize.UNKNOWN) {
|
|
686
|
+
pictureInPictureParams.setAspectRatio(new Rational(videoSize.width, videoSize.height));
|
|
687
|
+
} else {
|
|
688
|
+
pictureInPictureParams.setAspectRatio(new Rational(16, 9));
|
|
689
|
+
}
|
|
669
690
|
} else {
|
|
670
691
|
pictureInPictureParams.setAspectRatio(new Rational(16, 9));
|
|
671
692
|
}
|
|
@@ -726,12 +747,10 @@ public class FullscreenExoPlayerFragment extends Fragment {
|
|
|
726
747
|
if (castContext != null && Boolean.TRUE.equals(chromecast) && castPlayer != null && castPlayer.isCastSessionAvailable()) return;
|
|
727
748
|
|
|
728
749
|
initializePlayer();
|
|
729
|
-
if (player.getCurrentPosition() != 0) {
|
|
750
|
+
if (player != null && player.getCurrentPosition() != 0) {
|
|
730
751
|
firstReadyToPlay = false;
|
|
731
752
|
play();
|
|
732
753
|
}
|
|
733
|
-
} else {
|
|
734
|
-
getActivity().finishAndRemoveTask();
|
|
735
754
|
}
|
|
736
755
|
}
|
|
737
756
|
}
|
|
@@ -743,11 +762,16 @@ public class FullscreenExoPlayerFragment extends Fragment {
|
|
|
743
762
|
public void onStop() {
|
|
744
763
|
super.onStop();
|
|
745
764
|
boolean isAppBackground = false;
|
|
746
|
-
if (Boolean.TRUE.equals(bkModeEnabled)) isAppBackground = isApplicationSentToBackground(context);
|
|
765
|
+
if (context != null && Boolean.TRUE.equals(bkModeEnabled)) isAppBackground = isApplicationSentToBackground(context);
|
|
747
766
|
if (isInPictureInPictureMode) {
|
|
748
|
-
linearLayout
|
|
767
|
+
if (linearLayout != null) {
|
|
768
|
+
linearLayout.setVisibility(View.VISIBLE);
|
|
769
|
+
}
|
|
749
770
|
playerExit();
|
|
750
|
-
getActivity()
|
|
771
|
+
Activity activity = getActivity();
|
|
772
|
+
if (activity != null) {
|
|
773
|
+
activity.finishAndRemoveTask();
|
|
774
|
+
}
|
|
751
775
|
}
|
|
752
776
|
}
|
|
753
777
|
|
|
@@ -756,12 +780,12 @@ public class FullscreenExoPlayerFragment extends Fragment {
|
|
|
756
780
|
*/
|
|
757
781
|
@Override
|
|
758
782
|
public void onDestroy() {
|
|
759
|
-
isFragmentDestroyed
|
|
760
|
-
|
|
761
|
-
// Release player before calling super to ensure proper cleanup order
|
|
783
|
+
// Release player before setting isFragmentDestroyed and calling super to ensure proper cleanup order
|
|
762
784
|
releasePlayer();
|
|
785
|
+
isFragmentDestroyed = true;
|
|
763
786
|
|
|
764
|
-
// Clean up
|
|
787
|
+
// Clean up handlers
|
|
788
|
+
handler.removeCallbacks(mRunnable);
|
|
765
789
|
if (mainHandler != null) {
|
|
766
790
|
mainHandler.removeCallbacksAndMessages(null);
|
|
767
791
|
mainHandler = null;
|
|
@@ -781,6 +805,18 @@ public class FullscreenExoPlayerFragment extends Fragment {
|
|
|
781
805
|
super.onDetach();
|
|
782
806
|
}
|
|
783
807
|
|
|
808
|
+
/**
|
|
809
|
+
* Perform onDestroyView Action
|
|
810
|
+
*/
|
|
811
|
+
@Override
|
|
812
|
+
public void onDestroyView() {
|
|
813
|
+
if (styledPlayerView != null) {
|
|
814
|
+
styledPlayerView.setPlayer(null);
|
|
815
|
+
styledPlayerView = null;
|
|
816
|
+
}
|
|
817
|
+
super.onDestroyView();
|
|
818
|
+
}
|
|
819
|
+
|
|
784
820
|
/**
|
|
785
821
|
* Perform onPause Action
|
|
786
822
|
*/
|
|
@@ -791,7 +827,7 @@ public class FullscreenExoPlayerFragment extends Fragment {
|
|
|
791
827
|
castContext.removeCastStateListener(castStateListener);
|
|
792
828
|
}
|
|
793
829
|
boolean isAppBackground = false;
|
|
794
|
-
if (Boolean.TRUE.equals(bkModeEnabled)) isAppBackground = isApplicationSentToBackground(context);
|
|
830
|
+
if (context != null && Boolean.TRUE.equals(bkModeEnabled)) isAppBackground = isApplicationSentToBackground(context);
|
|
795
831
|
|
|
796
832
|
if (!isInPictureInPictureMode) {
|
|
797
833
|
if (Util.SDK_INT < 24) {
|
|
@@ -807,7 +843,7 @@ public class FullscreenExoPlayerFragment extends Fragment {
|
|
|
807
843
|
}
|
|
808
844
|
}
|
|
809
845
|
} else {
|
|
810
|
-
if (linearLayout.getVisibility() == View.VISIBLE) {
|
|
846
|
+
if (linearLayout != null && linearLayout.getVisibility() == View.VISIBLE) {
|
|
811
847
|
linearLayout.setVisibility(View.INVISIBLE);
|
|
812
848
|
}
|
|
813
849
|
if ((isInPictureInPictureMode || isAppBackground) && player != null) play();
|
|
@@ -843,6 +879,9 @@ public class FullscreenExoPlayerFragment extends Fragment {
|
|
|
843
879
|
}
|
|
844
880
|
|
|
845
881
|
private void releasePlayerInternal() {
|
|
882
|
+
if (styledPlayerView != null) {
|
|
883
|
+
styledPlayerView.setPlayer(null);
|
|
884
|
+
}
|
|
846
885
|
if (player != null && !isFragmentDestroyed) {
|
|
847
886
|
try {
|
|
848
887
|
playWhenReady = player.getPlayWhenReady();
|
|
@@ -940,9 +979,15 @@ public class FullscreenExoPlayerFragment extends Fragment {
|
|
|
940
979
|
* Leave the fullsreen mode and reset the status bar to visible
|
|
941
980
|
*/
|
|
942
981
|
private void showSystemUI() {
|
|
943
|
-
getActivity()
|
|
944
|
-
|
|
945
|
-
|
|
982
|
+
Activity activity = getActivity();
|
|
983
|
+
if (activity != null && activity.getWindow() != null) {
|
|
984
|
+
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
|
985
|
+
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
|
986
|
+
View decorView = activity.getWindow().getDecorView();
|
|
987
|
+
if (decorView != null) {
|
|
988
|
+
decorView.setSystemUiVisibility(View.VISIBLE);
|
|
989
|
+
}
|
|
990
|
+
}
|
|
946
991
|
}
|
|
947
992
|
|
|
948
993
|
/**
|
|
@@ -1015,15 +1060,18 @@ public class FullscreenExoPlayerFragment extends Fragment {
|
|
|
1015
1060
|
}
|
|
1016
1061
|
|
|
1017
1062
|
private void setSubtitle(boolean transparent) {
|
|
1063
|
+
if (styledPlayerView == null || styledPlayerView.getSubtitleView() == null) {
|
|
1064
|
+
return;
|
|
1065
|
+
}
|
|
1018
1066
|
int foreground;
|
|
1019
1067
|
int background;
|
|
1020
1068
|
if (!transparent) {
|
|
1021
1069
|
foreground = Color.WHITE;
|
|
1022
1070
|
background = Color.BLACK;
|
|
1023
|
-
if (stForeColor.length() > 4 && stForeColor.substring(0, 4).equals("rgba")) {
|
|
1071
|
+
if (stForeColor != null && stForeColor.length() > 4 && stForeColor.substring(0, 4).equals("rgba")) {
|
|
1024
1072
|
foreground = getColorFromRGBA(stForeColor);
|
|
1025
1073
|
}
|
|
1026
|
-
if (stBackColor.length() > 4 && stBackColor.substring(0, 4).equals("rgba")) {
|
|
1074
|
+
if (stBackColor != null && stBackColor.length() > 4 && stBackColor.substring(0, 4).equals("rgba")) {
|
|
1027
1075
|
background = getColorFromRGBA(stBackColor);
|
|
1028
1076
|
}
|
|
1029
1077
|
} else {
|
|
@@ -1035,7 +1083,7 @@ public class FullscreenExoPlayerFragment extends Fragment {
|
|
|
1035
1083
|
.setStyle(
|
|
1036
1084
|
new CaptionStyleCompat(foreground, background, Color.TRANSPARENT, CaptionStyleCompat.EDGE_TYPE_NONE, Color.WHITE, null)
|
|
1037
1085
|
);
|
|
1038
|
-
styledPlayerView.getSubtitleView().setFixedTextSize(TypedValue.COMPLEX_UNIT_DIP, stFontSize);
|
|
1086
|
+
styledPlayerView.getSubtitleView().setFixedTextSize(TypedValue.COMPLEX_UNIT_DIP, stFontSize != null ? stFontSize : 16);
|
|
1039
1087
|
styledPlayerView.setShowSubtitleButton(true);
|
|
1040
1088
|
}
|
|
1041
1089
|
|
|
@@ -1198,7 +1246,7 @@ public class FullscreenExoPlayerFragment extends Fragment {
|
|
|
1198
1246
|
* Fast Forward TV
|
|
1199
1247
|
*/
|
|
1200
1248
|
private void fastForward(long position, int times) {
|
|
1201
|
-
if (position < mDuration - videoStep) {
|
|
1249
|
+
if (player != null && position < mDuration - videoStep) {
|
|
1202
1250
|
if (player.isPlaying()) {
|
|
1203
1251
|
player.setPlayWhenReady(false);
|
|
1204
1252
|
}
|
|
@@ -1211,7 +1259,7 @@ public class FullscreenExoPlayerFragment extends Fragment {
|
|
|
1211
1259
|
* Rewind TV
|
|
1212
1260
|
*/
|
|
1213
1261
|
private void rewind(long position, int times) {
|
|
1214
|
-
if (position > videoStep) {
|
|
1262
|
+
if (player != null && position > videoStep) {
|
|
1215
1263
|
if (player.isPlaying()) {
|
|
1216
1264
|
player.setPlayWhenReady(false);
|
|
1217
1265
|
}
|
|
@@ -1224,7 +1272,9 @@ public class FullscreenExoPlayerFragment extends Fragment {
|
|
|
1224
1272
|
* Play Pause TV
|
|
1225
1273
|
*/
|
|
1226
1274
|
private void play_pause() {
|
|
1227
|
-
|
|
1275
|
+
if (player != null) {
|
|
1276
|
+
player.setPlayWhenReady(!player.isPlaying());
|
|
1277
|
+
}
|
|
1228
1278
|
}
|
|
1229
1279
|
|
|
1230
1280
|
/**
|
|
@@ -1232,7 +1282,7 @@ public class FullscreenExoPlayerFragment extends Fragment {
|
|
|
1232
1282
|
* @return boolean
|
|
1233
1283
|
*/
|
|
1234
1284
|
public boolean isPlaying() {
|
|
1235
|
-
return player.isPlaying();
|
|
1285
|
+
return player != null && player.isPlaying();
|
|
1236
1286
|
}
|
|
1237
1287
|
|
|
1238
1288
|
/**
|
|
@@ -1312,6 +1362,9 @@ public class FullscreenExoPlayerFragment extends Fragment {
|
|
|
1312
1362
|
* @return int in seconds
|
|
1313
1363
|
*/
|
|
1314
1364
|
public int getDuration() {
|
|
1365
|
+
if (player == null) {
|
|
1366
|
+
return 0;
|
|
1367
|
+
}
|
|
1315
1368
|
return player.getDuration() == UNKNOWN_TIME ? 0 : (int) (player.getDuration() / 1000);
|
|
1316
1369
|
}
|
|
1317
1370
|
|
|
@@ -1338,8 +1391,12 @@ public class FullscreenExoPlayerFragment extends Fragment {
|
|
|
1338
1391
|
|
|
1339
1392
|
try {
|
|
1340
1393
|
if (isInPictureInPictureMode) {
|
|
1341
|
-
styledPlayerView
|
|
1342
|
-
|
|
1394
|
+
if (styledPlayerView != null) {
|
|
1395
|
+
styledPlayerView.setUseController(false);
|
|
1396
|
+
}
|
|
1397
|
+
if (linearLayout != null) {
|
|
1398
|
+
linearLayout.setVisibility(View.INVISIBLE);
|
|
1399
|
+
}
|
|
1343
1400
|
}
|
|
1344
1401
|
long seekPosition = player.getCurrentPosition() == UNKNOWN_TIME
|
|
1345
1402
|
? 0
|
|
@@ -1355,7 +1412,7 @@ public class FullscreenExoPlayerFragment extends Fragment {
|
|
|
1355
1412
|
* @return float
|
|
1356
1413
|
*/
|
|
1357
1414
|
public float getVolume() {
|
|
1358
|
-
return player.getVolume();
|
|
1415
|
+
return player != null ? player.getVolume() : curVolume;
|
|
1359
1416
|
}
|
|
1360
1417
|
|
|
1361
1418
|
/**
|
|
@@ -1364,7 +1421,10 @@ public class FullscreenExoPlayerFragment extends Fragment {
|
|
|
1364
1421
|
*/
|
|
1365
1422
|
public void setVolume(float _volume) {
|
|
1366
1423
|
float volume = Math.min(Math.max(0, _volume), 1L);
|
|
1367
|
-
|
|
1424
|
+
curVolume = volume;
|
|
1425
|
+
if (player != null) {
|
|
1426
|
+
player.setVolume(volume);
|
|
1427
|
+
}
|
|
1368
1428
|
}
|
|
1369
1429
|
|
|
1370
1430
|
/**
|
|
@@ -1381,8 +1441,10 @@ public class FullscreenExoPlayerFragment extends Fragment {
|
|
|
1381
1441
|
*/
|
|
1382
1442
|
public void setRate(float _rate) {
|
|
1383
1443
|
videoRate = _rate;
|
|
1384
|
-
|
|
1385
|
-
|
|
1444
|
+
if (player != null) {
|
|
1445
|
+
PlaybackParameters param = new PlaybackParameters(videoRate != null ? videoRate : 1.0f);
|
|
1446
|
+
player.setPlaybackParameters(param);
|
|
1447
|
+
}
|
|
1386
1448
|
}
|
|
1387
1449
|
|
|
1388
1450
|
/**
|
|
@@ -1391,11 +1453,13 @@ public class FullscreenExoPlayerFragment extends Fragment {
|
|
|
1391
1453
|
*/
|
|
1392
1454
|
public void setMuted(boolean _isMuted) {
|
|
1393
1455
|
isMuted = _isMuted;
|
|
1394
|
-
if (
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1456
|
+
if (player != null) {
|
|
1457
|
+
if (isMuted) {
|
|
1458
|
+
curVolume = player.getVolume();
|
|
1459
|
+
player.setVolume(0L);
|
|
1460
|
+
} else {
|
|
1461
|
+
player.setVolume(curVolume);
|
|
1462
|
+
}
|
|
1399
1463
|
}
|
|
1400
1464
|
}
|
|
1401
1465
|
|
|
@@ -1412,7 +1476,7 @@ public class FullscreenExoPlayerFragment extends Fragment {
|
|
|
1412
1476
|
* @param button
|
|
1413
1477
|
*/
|
|
1414
1478
|
private void mediaRouteButtonColorWhite(MediaRouteButton button) {
|
|
1415
|
-
if (button == null) return;
|
|
1479
|
+
if (button == null || getContext() == null) return;
|
|
1416
1480
|
Context castContext = new ContextThemeWrapper(getContext(), androidx.mediarouter.R.style.Theme_MediaRouter);
|
|
1417
1481
|
|
|
1418
1482
|
TypedArray a = castContext.obtainStyledAttributes(
|
|
@@ -1467,7 +1531,6 @@ public class FullscreenExoPlayerFragment extends Fragment {
|
|
|
1467
1531
|
*/
|
|
1468
1532
|
private void resetVariables() {
|
|
1469
1533
|
vType = null;
|
|
1470
|
-
styledPlayerView = null;
|
|
1471
1534
|
playWhenReady = true;
|
|
1472
1535
|
firstReadyToPlay = true;
|
|
1473
1536
|
isEnded = false;
|
|
@@ -1509,6 +1572,9 @@ public class FullscreenExoPlayerFragment extends Fragment {
|
|
|
1509
1572
|
task.addOnCompleteListener(new OnCompleteListener<CastContext>() {
|
|
1510
1573
|
@Override
|
|
1511
1574
|
public void onComplete(Task<CastContext> task) {
|
|
1575
|
+
if (isFragmentDestroyed || !isAdded() || context == null || mediaRouteButton == null) {
|
|
1576
|
+
return;
|
|
1577
|
+
}
|
|
1512
1578
|
if (task.isSuccessful()) {
|
|
1513
1579
|
castContext = task.getResult();
|
|
1514
1580
|
castPlayer = new CastPlayer(castContext);
|
|
@@ -1525,6 +1591,9 @@ public class FullscreenExoPlayerFragment extends Fragment {
|
|
|
1525
1591
|
|
|
1526
1592
|
castStateListener =
|
|
1527
1593
|
state -> {
|
|
1594
|
+
if (mediaRouteButton == null) {
|
|
1595
|
+
return;
|
|
1596
|
+
}
|
|
1528
1597
|
if (state == CastState.NO_DEVICES_AVAILABLE) {
|
|
1529
1598
|
mediaRouteButton.setVisibility(View.GONE);
|
|
1530
1599
|
} else {
|
|
@@ -1562,35 +1631,53 @@ public class FullscreenExoPlayerFragment extends Fragment {
|
|
|
1562
1631
|
@Override
|
|
1563
1632
|
public void onCastSessionAvailable() {
|
|
1564
1633
|
isCastSession = true;
|
|
1565
|
-
final Long videoPosition = player.getCurrentPosition();
|
|
1566
|
-
if (Boolean.TRUE.equals(pipEnabled)) {
|
|
1634
|
+
final Long videoPosition = player != null ? player.getCurrentPosition() : 0L;
|
|
1635
|
+
if (pipBtn != null && Boolean.TRUE.equals(pipEnabled)) {
|
|
1567
1636
|
pipBtn.setVisibility(View.GONE);
|
|
1568
1637
|
}
|
|
1569
|
-
resizeBtn
|
|
1570
|
-
|
|
1571
|
-
|
|
1638
|
+
if (resizeBtn != null) {
|
|
1639
|
+
resizeBtn.setVisibility(View.GONE);
|
|
1640
|
+
}
|
|
1641
|
+
if (player != null) {
|
|
1642
|
+
player.setPlayWhenReady(false);
|
|
1643
|
+
}
|
|
1644
|
+
if (cast_image != null) {
|
|
1645
|
+
cast_image.setVisibility(View.VISIBLE);
|
|
1646
|
+
}
|
|
1572
1647
|
castPlayer.setMediaItem(mediaItem, videoPosition);
|
|
1573
|
-
styledPlayerView
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1648
|
+
if (styledPlayerView != null) {
|
|
1649
|
+
styledPlayerView.setPlayer(castPlayer);
|
|
1650
|
+
styledPlayerView.setControllerShowTimeoutMs(0);
|
|
1651
|
+
styledPlayerView.setControllerHideOnTouch(false);
|
|
1652
|
+
//We perform a click because for some weird reason, the layout is black until the user clicks on it
|
|
1653
|
+
styledPlayerView.performClick();
|
|
1654
|
+
}
|
|
1578
1655
|
}
|
|
1579
1656
|
|
|
1580
1657
|
@Override
|
|
1581
1658
|
public void onCastSessionUnavailable() {
|
|
1582
1659
|
isCastSession = false;
|
|
1583
|
-
final Long videoPosition = castPlayer.getCurrentPosition();
|
|
1584
|
-
if (Boolean.TRUE.equals(pipEnabled)) {
|
|
1660
|
+
final Long videoPosition = castPlayer != null ? castPlayer.getCurrentPosition() : 0L;
|
|
1661
|
+
if (pipBtn != null && Boolean.TRUE.equals(pipEnabled)) {
|
|
1585
1662
|
pipBtn.setVisibility(View.VISIBLE);
|
|
1586
1663
|
}
|
|
1587
|
-
resizeBtn
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
styledPlayerView
|
|
1664
|
+
if (resizeBtn != null) {
|
|
1665
|
+
resizeBtn.setVisibility(View.VISIBLE);
|
|
1666
|
+
}
|
|
1667
|
+
if (cast_image != null) {
|
|
1668
|
+
cast_image.setVisibility(View.GONE);
|
|
1669
|
+
}
|
|
1670
|
+
if (styledPlayerView != null) {
|
|
1671
|
+
styledPlayerView.setPlayer(player);
|
|
1672
|
+
}
|
|
1673
|
+
if (player != null) {
|
|
1674
|
+
player.setPlayWhenReady(true);
|
|
1675
|
+
player.seekTo(videoPosition);
|
|
1676
|
+
}
|
|
1677
|
+
if (styledPlayerView != null) {
|
|
1678
|
+
styledPlayerView.setControllerShowTimeoutMs(3000);
|
|
1679
|
+
styledPlayerView.setControllerHideOnTouch(true);
|
|
1680
|
+
}
|
|
1594
1681
|
}
|
|
1595
1682
|
}
|
|
1596
1683
|
);
|
|
@@ -1602,7 +1689,7 @@ public class FullscreenExoPlayerFragment extends Fragment {
|
|
|
1602
1689
|
Map<String, Object> info = new HashMap<String, Object>() {
|
|
1603
1690
|
{
|
|
1604
1691
|
put("fromPlayerId", playerId);
|
|
1605
|
-
put("currentTime", String.valueOf(player.getCurrentPosition() / 1000));
|
|
1692
|
+
put("currentTime", String.valueOf(player != null ? player.getCurrentPosition() / 1000 : 0));
|
|
1606
1693
|
}
|
|
1607
1694
|
};
|
|
1608
1695
|
switch (state) {
|
|
@@ -1640,6 +1727,8 @@ public class FullscreenExoPlayerFragment extends Fragment {
|
|
|
1640
1727
|
}
|
|
1641
1728
|
|
|
1642
1729
|
private void adjustAspectRatio() {
|
|
1643
|
-
styledPlayerView
|
|
1730
|
+
if (styledPlayerView != null) {
|
|
1731
|
+
styledPlayerView.setResizeMode(resizeStatus);
|
|
1732
|
+
}
|
|
1644
1733
|
}
|
|
1645
1734
|
}
|
|
@@ -78,6 +78,9 @@ public class PickerVideoFragment extends Fragment {
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
private void loadVideos() {
|
|
81
|
+
if (context == null) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
81
84
|
String[] projection = {
|
|
82
85
|
MediaStore.Video.Media._ID,
|
|
83
86
|
MediaStore.Video.Media.DISPLAY_NAME,
|
|
@@ -92,37 +95,46 @@ public class PickerVideoFragment extends Fragment {
|
|
|
92
95
|
collection = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
|
|
93
96
|
}
|
|
94
97
|
|
|
95
|
-
Cursor cursor =
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
try (Cursor cursor = context.getContentResolver().query(collection, projection, null, null, sortOrder)) {
|
|
99
|
+
if (cursor != null) {
|
|
100
|
+
int idColumn = cursor.getColumnIndexOrThrow(MediaStore.Video.Media._ID);
|
|
101
|
+
int titleColumn = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DISPLAY_NAME);
|
|
102
|
+
int durationColumn = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DURATION);
|
|
100
103
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
104
|
+
while (cursor.moveToNext()) {
|
|
105
|
+
long id = cursor.getLong(idColumn);
|
|
106
|
+
String title = cursor.getString(titleColumn);
|
|
107
|
+
int duration = cursor.getInt(durationColumn);
|
|
105
108
|
|
|
106
|
-
|
|
109
|
+
Uri data = ContentUris.withAppendedId(collection, id);
|
|
107
110
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
111
|
+
String duration_formatted;
|
|
112
|
+
int sec = (duration / 1000) % 60;
|
|
113
|
+
int min = (duration / (1000 * 60)) % 60;
|
|
114
|
+
int hrs = duration / (1000 * 60 * 60);
|
|
112
115
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
116
|
+
if (hrs == 0) {
|
|
117
|
+
duration_formatted = String.valueOf(min).concat(":".concat(String.format(Locale.UK, "%02d", sec)));
|
|
118
|
+
} else {
|
|
119
|
+
duration_formatted = String.valueOf(hrs).concat(
|
|
120
|
+
":".concat(String.format(Locale.UK, "%02d", min).concat(":".concat(String.format(Locale.UK, "%02d", sec))))
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
Log.v(TAG, "**** video " + id + " " + title + " " + duration_formatted + " ****");
|
|
124
|
+
videosList.add(new ModelVideo(id, data, title, duration_formatted));
|
|
122
125
|
}
|
|
123
|
-
Log.v(TAG, "**** video " + id + " " + title + " " + duration_formatted + " ****");
|
|
124
|
-
videosList.add(new ModelVideo(id, data, title, duration_formatted));
|
|
125
126
|
}
|
|
127
|
+
} catch (Exception e) {
|
|
128
|
+
Log.e(TAG, "Error loading videos from media store", e);
|
|
126
129
|
}
|
|
127
130
|
}
|
|
131
|
+
|
|
132
|
+
@Override
|
|
133
|
+
public void onDestroyView() {
|
|
134
|
+
recyclerView = null;
|
|
135
|
+
recyclerViewLayoutManager = null;
|
|
136
|
+
adapterVideoList = null;
|
|
137
|
+
view = null;
|
|
138
|
+
super.onDestroyView();
|
|
139
|
+
}
|
|
128
140
|
}
|