@@ -549,7 +549,7 @@ public Builder setTimedMetadata(Metadata timedMetadata) {
549
549
public Builder setPlaylist (List <MediaItemData > playlist ) {
550
550
HashSet <Object > uids = new HashSet <>();
551
551
for (int i = 0 ; i < playlist .size (); i ++) {
552
- checkArgument (uids .add (playlist .get (i ).uid ));
552
+ checkArgument (uids .add (playlist .get (i ).uid ), "Duplicate MediaItemData UID in playlist" );
553
553
}
554
554
this .playlist = ImmutableList .copyOf (playlist );
555
555
this .timeline = new PlaylistTimeline (this .playlist );
@@ -882,16 +882,20 @@ private State(Builder builder) {
882
882
if (builder .timeline .isEmpty ()) {
883
883
checkArgument (
884
884
builder .playbackState == Player .STATE_IDLE
885
- || builder .playbackState == Player .STATE_ENDED );
885
+ || builder .playbackState == Player .STATE_ENDED ,
886
+ "Empty playlist only allowed in STATE_IDLE or STATE_ENDED" );
886
887
checkArgument (
887
888
builder .currentAdGroupIndex == C .INDEX_UNSET
888
- && builder .currentAdIndexInAdGroup == C .INDEX_UNSET );
889
+ && builder .currentAdIndexInAdGroup == C .INDEX_UNSET ,
890
+ "Ads not allowed if playlist is empty" );
889
891
} else {
890
892
int mediaItemIndex = builder .currentMediaItemIndex ;
891
893
if (mediaItemIndex == C .INDEX_UNSET ) {
892
894
mediaItemIndex = 0 ; // TODO: Use shuffle order to find first index.
893
895
} else {
894
- checkArgument (builder .currentMediaItemIndex < builder .timeline .getWindowCount ());
896
+ checkArgument (
897
+ builder .currentMediaItemIndex < builder .timeline .getWindowCount (),
898
+ "currentMediaItemIndex must be less than playlist.size()" );
895
899
}
896
900
if (builder .currentAdGroupIndex != C .INDEX_UNSET ) {
897
901
Timeline .Period period = new Timeline .Period ();
@@ -904,19 +908,25 @@ private State(Builder builder) {
904
908
getPeriodIndexFromWindowPosition (
905
909
builder .timeline , mediaItemIndex , contentPositionMs , window , period );
906
910
builder .timeline .getPeriod (periodIndex , period );
907
- checkArgument (builder .currentAdGroupIndex < period .getAdGroupCount ());
911
+ checkArgument (
912
+ builder .currentAdGroupIndex < period .getAdGroupCount (),
913
+ "PeriodData has less ad groups than adGroupIndex" );
908
914
int adCountInGroup = period .getAdCountInAdGroup (builder .currentAdGroupIndex );
909
915
if (adCountInGroup != C .LENGTH_UNSET ) {
910
- checkArgument (builder .currentAdIndexInAdGroup < adCountInGroup );
916
+ checkArgument (
917
+ builder .currentAdIndexInAdGroup < adCountInGroup ,
918
+ "Ad group has less ads than adIndexInGroupIndex" );
911
919
}
912
920
}
913
921
}
914
922
if (builder .playerError != null ) {
915
- checkArgument (builder .playbackState == Player .STATE_IDLE );
923
+ checkArgument (
924
+ builder .playbackState == Player .STATE_IDLE , "Player error only allowed in STATE_IDLE" );
916
925
}
917
926
if (builder .playbackState == Player .STATE_IDLE
918
927
|| builder .playbackState == Player .STATE_ENDED ) {
919
- checkArgument (!builder .isLoading );
928
+ checkArgument (
929
+ !builder .isLoading , "isLoading only allowed when not in STATE_IDLE or STATE_ENDED" );
920
930
}
921
931
PositionSupplier contentPositionMsSupplier = builder .contentPositionMsSupplier ;
922
932
if (builder .contentPositionMs != null ) {
@@ -1494,9 +1504,12 @@ public Builder setIsPlaceholder(boolean isPlaceholder) {
1494
1504
public Builder setPeriods (List <PeriodData > periods ) {
1495
1505
int periodCount = periods .size ();
1496
1506
for (int i = 0 ; i < periodCount - 1 ; i ++) {
1497
- checkArgument (periods .get (i ).durationUs != C .TIME_UNSET );
1507
+ checkArgument (
1508
+ periods .get (i ).durationUs != C .TIME_UNSET , "Periods other than last need a duration" );
1498
1509
for (int j = i + 1 ; j < periodCount ; j ++) {
1499
- checkArgument (!periods .get (i ).uid .equals (periods .get (j ).uid ));
1510
+ checkArgument (
1511
+ !periods .get (i ).uid .equals (periods .get (j ).uid ),
1512
+ "Duplicate PeriodData UIDs in period list" );
1500
1513
}
1501
1514
}
1502
1515
this .periods = ImmutableList .copyOf (periods );
@@ -1575,16 +1588,26 @@ public MediaItemData build() {
1575
1588
1576
1589
private MediaItemData (Builder builder ) {
1577
1590
if (builder .liveConfiguration == null ) {
1578
- checkArgument (builder .presentationStartTimeMs == C .TIME_UNSET );
1579
- checkArgument (builder .windowStartTimeMs == C .TIME_UNSET );
1580
- checkArgument (builder .elapsedRealtimeEpochOffsetMs == C .TIME_UNSET );
1591
+ checkArgument (
1592
+ builder .presentationStartTimeMs == C .TIME_UNSET ,
1593
+ "presentationStartTimeMs can only be set if liveConfiguration != null" );
1594
+ checkArgument (
1595
+ builder .windowStartTimeMs == C .TIME_UNSET ,
1596
+ "windowStartTimeMs can only be set if liveConfiguration != null" );
1597
+ checkArgument (
1598
+ builder .elapsedRealtimeEpochOffsetMs == C .TIME_UNSET ,
1599
+ "elapsedRealtimeEpochOffsetMs can only be set if liveConfiguration != null" );
1581
1600
} else if (builder .presentationStartTimeMs != C .TIME_UNSET
1582
1601
&& builder .windowStartTimeMs != C .TIME_UNSET ) {
1583
- checkArgument (builder .windowStartTimeMs >= builder .presentationStartTimeMs );
1602
+ checkArgument (
1603
+ builder .windowStartTimeMs >= builder .presentationStartTimeMs ,
1604
+ "windowStartTimeMs can't be less than presentationStartTimeMs" );
1584
1605
}
1585
1606
int periodCount = builder .periods .size ();
1586
1607
if (builder .durationUs != C .TIME_UNSET ) {
1587
- checkArgument (builder .defaultPositionUs <= builder .durationUs );
1608
+ checkArgument (
1609
+ builder .defaultPositionUs <= builder .durationUs ,
1610
+ "defaultPositionUs can't be greater than durationUs" );
1588
1611
}
1589
1612
this .uid = builder .uid ;
1590
1613
this .tracks = builder .tracks ;
@@ -2782,7 +2805,7 @@ protected MediaItemData getPlaceholderMediaItemData(MediaItem mediaItem) {
2782
2805
*/
2783
2806
@ ForOverride
2784
2807
protected ListenableFuture <?> handleSetPlayWhenReady (boolean playWhenReady ) {
2785
- throw new IllegalStateException ();
2808
+ throw new IllegalStateException ("Missing implementation to handle COMMAND_PLAY_PAUSE" );
2786
2809
}
2787
2810
2788
2811
/**
@@ -2795,7 +2818,7 @@ protected ListenableFuture<?> handleSetPlayWhenReady(boolean playWhenReady) {
2795
2818
*/
2796
2819
@ ForOverride
2797
2820
protected ListenableFuture <?> handlePrepare () {
2798
- throw new IllegalStateException ();
2821
+ throw new IllegalStateException ("Missing implementation to handle COMMAND_PREPARE" );
2799
2822
}
2800
2823
2801
2824
/**
@@ -2808,7 +2831,7 @@ protected ListenableFuture<?> handlePrepare() {
2808
2831
*/
2809
2832
@ ForOverride
2810
2833
protected ListenableFuture <?> handleStop () {
2811
- throw new IllegalStateException ();
2834
+ throw new IllegalStateException ("Missing implementation to handle COMMAND_STOP" );
2812
2835
}
2813
2836
2814
2837
/**
@@ -2820,7 +2843,7 @@ protected ListenableFuture<?> handleStop() {
2820
2843
// TODO(b/261158047): Add that this method will only be called if COMMAND_RELEASE is available.
2821
2844
@ ForOverride
2822
2845
protected ListenableFuture <?> handleRelease () {
2823
- throw new IllegalStateException ();
2846
+ throw new IllegalStateException ("Missing implementation to handle COMMAND_RELEASE" );
2824
2847
}
2825
2848
2826
2849
/**
@@ -2834,7 +2857,7 @@ protected ListenableFuture<?> handleRelease() {
2834
2857
*/
2835
2858
@ ForOverride
2836
2859
protected ListenableFuture <?> handleSetRepeatMode (@ RepeatMode int repeatMode ) {
2837
- throw new IllegalStateException ();
2860
+ throw new IllegalStateException ("Missing implementation to handle COMMAND_SET_REPEAT_MODE" );
2838
2861
}
2839
2862
2840
2863
/**
@@ -2848,7 +2871,7 @@ protected ListenableFuture<?> handleSetRepeatMode(@RepeatMode int repeatMode) {
2848
2871
*/
2849
2872
@ ForOverride
2850
2873
protected ListenableFuture <?> handleSetShuffleModeEnabled (boolean shuffleModeEnabled ) {
2851
- throw new IllegalStateException ();
2874
+ throw new IllegalStateException ("Missing implementation to handle COMMAND_SET_SHUFFLE_MODE" );
2852
2875
}
2853
2876
2854
2877
/**
@@ -2862,7 +2885,7 @@ protected ListenableFuture<?> handleSetShuffleModeEnabled(boolean shuffleModeEna
2862
2885
*/
2863
2886
@ ForOverride
2864
2887
protected ListenableFuture <?> handleSetPlaybackParameters (PlaybackParameters playbackParameters ) {
2865
- throw new IllegalStateException ();
2888
+ throw new IllegalStateException ("Missing implementation to handle COMMAND_SET_SPEED_AND_PITCH" );
2866
2889
}
2867
2890
2868
2891
/**
@@ -2877,7 +2900,8 @@ protected ListenableFuture<?> handleSetPlaybackParameters(PlaybackParameters pla
2877
2900
@ ForOverride
2878
2901
protected ListenableFuture <?> handleSetTrackSelectionParameters (
2879
2902
TrackSelectionParameters trackSelectionParameters ) {
2880
- throw new IllegalStateException ();
2903
+ throw new IllegalStateException (
2904
+ "Missing implementation to handle COMMAND_SET_TRACK_SELECTION_PARAMETERS" );
2881
2905
}
2882
2906
2883
2907
/**
@@ -2891,7 +2915,8 @@ protected ListenableFuture<?> handleSetTrackSelectionParameters(
2891
2915
*/
2892
2916
@ ForOverride
2893
2917
protected ListenableFuture <?> handleSetPlaylistMetadata (MediaMetadata playlistMetadata ) {
2894
- throw new IllegalStateException ();
2918
+ throw new IllegalStateException (
2919
+ "Missing implementation to handle COMMAND_SET_MEDIA_ITEMS_METADATA" );
2895
2920
}
2896
2921
2897
2922
/**
@@ -2906,7 +2931,7 @@ protected ListenableFuture<?> handleSetPlaylistMetadata(MediaMetadata playlistMe
2906
2931
*/
2907
2932
@ ForOverride
2908
2933
protected ListenableFuture <?> handleSetVolume (@ FloatRange (from = 0 , to = 1.0 ) float volume ) {
2909
- throw new IllegalStateException ();
2934
+ throw new IllegalStateException ("Missing implementation to handle COMMAND_SET_VOLUME" );
2910
2935
}
2911
2936
2912
2937
/**
@@ -2920,7 +2945,7 @@ protected ListenableFuture<?> handleSetVolume(@FloatRange(from = 0, to = 1.0) fl
2920
2945
*/
2921
2946
@ ForOverride
2922
2947
protected ListenableFuture <?> handleSetDeviceVolume (@ IntRange (from = 0 ) int deviceVolume ) {
2923
- throw new IllegalStateException ();
2948
+ throw new IllegalStateException ("Missing implementation to handle COMMAND_SET_DEVICE_VOLUME" );
2924
2949
}
2925
2950
2926
2951
/**
@@ -2933,7 +2958,8 @@ protected ListenableFuture<?> handleSetDeviceVolume(@IntRange(from = 0) int devi
2933
2958
*/
2934
2959
@ ForOverride
2935
2960
protected ListenableFuture <?> handleIncreaseDeviceVolume () {
2936
- throw new IllegalStateException ();
2961
+ throw new IllegalStateException (
2962
+ "Missing implementation to handle COMMAND_ADJUST_DEVICE_VOLUME" );
2937
2963
}
2938
2964
2939
2965
/**
@@ -2946,7 +2972,8 @@ protected ListenableFuture<?> handleIncreaseDeviceVolume() {
2946
2972
*/
2947
2973
@ ForOverride
2948
2974
protected ListenableFuture <?> handleDecreaseDeviceVolume () {
2949
- throw new IllegalStateException ();
2975
+ throw new IllegalStateException (
2976
+ "Missing implementation to handle COMMAND_ADJUST_DEVICE_VOLUME" );
2950
2977
}
2951
2978
2952
2979
/**
@@ -2960,7 +2987,8 @@ protected ListenableFuture<?> handleDecreaseDeviceVolume() {
2960
2987
*/
2961
2988
@ ForOverride
2962
2989
protected ListenableFuture <?> handleSetDeviceMuted (boolean muted ) {
2963
- throw new IllegalStateException ();
2990
+ throw new IllegalStateException (
2991
+ "Missing implementation to handle COMMAND_ADJUST_DEVICE_VOLUME" );
2964
2992
}
2965
2993
2966
2994
/**
@@ -2975,7 +3003,7 @@ protected ListenableFuture<?> handleSetDeviceMuted(boolean muted) {
2975
3003
*/
2976
3004
@ ForOverride
2977
3005
protected ListenableFuture <?> handleSetVideoOutput (Object videoOutput ) {
2978
- throw new IllegalStateException ();
3006
+ throw new IllegalStateException ("Missing implementation to handle COMMAND_SET_VIDEO_SURFACE" );
2979
3007
}
2980
3008
2981
3009
/**
@@ -2992,7 +3020,7 @@ protected ListenableFuture<?> handleSetVideoOutput(Object videoOutput) {
2992
3020
*/
2993
3021
@ ForOverride
2994
3022
protected ListenableFuture <?> handleClearVideoOutput (@ Nullable Object videoOutput ) {
2995
- throw new IllegalStateException ();
3023
+ throw new IllegalStateException ("Missing implementation to handle COMMAND_SET_VIDEO_SURFACE" );
2996
3024
}
2997
3025
2998
3026
/**
@@ -3013,7 +3041,7 @@ protected ListenableFuture<?> handleClearVideoOutput(@Nullable Object videoOutpu
3013
3041
@ ForOverride
3014
3042
protected ListenableFuture <?> handleSetMediaItems (
3015
3043
List <MediaItem > mediaItems , int startIndex , long startPositionMs ) {
3016
- throw new IllegalStateException ();
3044
+ throw new IllegalStateException ("Missing implementation to handle COMMAND_SET_MEDIA_ITEM(S)" );
3017
3045
}
3018
3046
3019
3047
/**
@@ -3029,7 +3057,7 @@ protected ListenableFuture<?> handleSetMediaItems(
3029
3057
*/
3030
3058
@ ForOverride
3031
3059
protected ListenableFuture <?> handleAddMediaItems (int index , List <MediaItem > mediaItems ) {
3032
- throw new IllegalStateException ();
3060
+ throw new IllegalStateException ("Missing implementation to handle COMMAND_CHANGE_MEDIA_ITEMS" );
3033
3061
}
3034
3062
3035
3063
/**
@@ -3049,7 +3077,7 @@ protected ListenableFuture<?> handleAddMediaItems(int index, List<MediaItem> med
3049
3077
*/
3050
3078
@ ForOverride
3051
3079
protected ListenableFuture <?> handleMoveMediaItems (int fromIndex , int toIndex , int newIndex ) {
3052
- throw new IllegalStateException ();
3080
+ throw new IllegalStateException ("Missing implementation to handle COMMAND_CHANGE_MEDIA_ITEMS" );
3053
3081
}
3054
3082
3055
3083
/**
@@ -3066,7 +3094,7 @@ protected ListenableFuture<?> handleMoveMediaItems(int fromIndex, int toIndex, i
3066
3094
*/
3067
3095
@ ForOverride
3068
3096
protected ListenableFuture <?> handleRemoveMediaItems (int fromIndex , int toIndex ) {
3069
- throw new IllegalStateException ();
3097
+ throw new IllegalStateException ("Missing implementation to handle COMMAND_CHANGE_MEDIA_ITEMS" );
3070
3098
}
3071
3099
3072
3100
/**
@@ -3087,7 +3115,7 @@ protected ListenableFuture<?> handleRemoveMediaItems(int fromIndex, int toIndex)
3087
3115
@ ForOverride
3088
3116
protected ListenableFuture <?> handleSeek (
3089
3117
int mediaItemIndex , long positionMs , @ Player .Command int seekCommand ) {
3090
- throw new IllegalStateException ();
3118
+ throw new IllegalStateException ("Missing implementation to handle one of the COMMAND_SEEK_*" );
3091
3119
}
3092
3120
3093
3121
@ RequiresNonNull ("state" )
0 commit comments