8181import androidx .media3 .common .TrackSelectionOverride ;
8282import androidx .media3 .common .TrackSelectionParameters ;
8383import androidx .media3 .common .Tracks ;
84+ import androidx .media3 .common .endeavor .ExoConfig ;
8485import androidx .media3 .common .endeavor .LimitedSeekRange ;
8586import androidx .media3 .common .endeavor .TimelineAdjuster ;
8687import androidx .media3 .common .util .Assertions ;
@@ -724,8 +725,32 @@ public void setExtraAdGroupMarkers(
724725 } else {
725726 extraPlayedAdGroups = checkNotNull (extraPlayedAdGroups );
726727 Assertions .checkArgument (extraAdGroupTimesMs .length == extraPlayedAdGroups .length );
727- this .extraAdGroupTimesMs = extraAdGroupTimesMs ;
728- this .extraPlayedAdGroups = extraPlayedAdGroups ;
728+
729+ long [] newExtraAdGroupTimesMs = extraAdGroupTimesMs ;
730+ boolean [] newExtraPlayedAdGroups = extraPlayedAdGroups ;
731+ if (ExoConfig .getInstance ().isHideMarkerForWatchedAd ()) {
732+ int markerCount = 0 ;
733+ for (boolean markerPlayed : extraPlayedAdGroups ) {
734+ if (!markerPlayed ) {
735+ markerCount ++;
736+ }
737+ }
738+ if (markerCount != extraPlayedAdGroups .length ) {
739+ int index = 0 ;
740+ newExtraAdGroupTimesMs = new long [markerCount ];
741+ newExtraPlayedAdGroups = new boolean [markerCount ];
742+ for (int i = 0 ; i < extraPlayedAdGroups .length ; i ++) {
743+ if (extraPlayedAdGroups [i ]) {
744+ continue ;
745+ }
746+ newExtraAdGroupTimesMs [index ] = extraAdGroupTimesMs [i ];
747+ newExtraPlayedAdGroups [index ] = false ;
748+ index ++;
749+ }
750+ }
751+ }
752+ this .extraAdGroupTimesMs = newExtraAdGroupTimesMs ;
753+ this .extraPlayedAdGroups = newExtraPlayedAdGroups ;
729754 }
730755 updateTimeline ();
731756 }
@@ -741,23 +766,23 @@ public void setLimitedSeekRange(LimitedSeekRange limitedSeekRange) {
741766 }
742767
743768 protected long scaleSeekbarToTimelineMs (long seekbarMs ) {
744- long positionMs = LimitedSeekRange .revertPosition (seekbarMs , limitedSeekRange ).getPositionMs ();
769+ long positionMs = LimitedSeekRange .scaleSeekbarToTimelineMs (seekbarMs , limitedSeekRange ).getPositionMs ();
745770 if (timelineAdjuster != null ) {
746771 positionMs = timelineAdjuster .scaleSeekbarToTimelineMs (positionMs );
747772 }
748773 return positionMs ;
749774 }
750775
751776 protected long scaleTimelineToSeekbarMs (long timelineMs ) {
752- long positionMs = LimitedSeekRange .adjustPosition (timelineMs , limitedSeekRange ).getPositionMs ();
777+ long positionMs = LimitedSeekRange .scaleTimelineToSeekbarMs (timelineMs , limitedSeekRange ).getPositionMs ();
753778 if (timelineAdjuster != null ) {
754779 positionMs = timelineAdjuster .scaleTimelineToSeekbarMs (positionMs );
755780 }
756781 return positionMs ;
757782 }
758783
759- protected long adjustDuration (long realDurationMs ) {
760- long durationMs = LimitedSeekRange .adjustDuration (realDurationMs , limitedSeekRange );
784+ protected long scaleDurationToSeekbarMs (long realDurationMs ) {
785+ long durationMs = LimitedSeekRange .scaleDurationToSeekbarMs (realDurationMs , limitedSeekRange );
761786 if (timelineAdjuster != null ) {
762787 durationMs = timelineAdjuster .scaleTimelineToSeekbarMs (durationMs );
763788 }
@@ -1326,7 +1351,9 @@ private void updateTimeline() {
13261351 }
13271352 adGroupTimesMs [adGroupCount ] = Util .usToMs (durationUs + adGroupTimeInWindowUs );
13281353 playedAdGroups [adGroupCount ] = period .hasPlayedAdGroup (adGroupIndex );
1329- adGroupCount ++;
1354+ if (!playedAdGroups [adGroupCount ] || !ExoConfig .getInstance ().isHideMarkerForWatchedAd ()) {
1355+ adGroupCount ++;
1356+ }
13301357 }
13311358 }
13321359 }
@@ -1341,8 +1368,8 @@ private void updateTimeline() {
13411368 // Apply the timeline converter.
13421369 // long durationMs = Util.usToMs(durationUs);
13431370 long realDurationMs = Util .usToMs (durationUs );
1344- long durationMs = adjustDuration (realDurationMs );
1345- boolean isVod = LimitedSeekRange .isUseAsVod (limitedSeekRange );
1371+ long durationMs = scaleDurationToSeekbarMs (realDurationMs );
1372+ boolean isVod = LimitedSeekRange .isUseLiveAsVod (limitedSeekRange );
13461373 if (dvrWindowListener != null && player .isCurrentMediaItemLive () && !isVod ) {
13471374 dvrWindowListener .onDvrWindowUpdate (realDurationMs > MIN_LENGTH_OF_DVR_MS );
13481375 }
@@ -1395,7 +1422,7 @@ private void updateProgress() {
13951422 // Apply the timeline converter.
13961423 // int playbackState = player == null ? Player.STATE_IDLE : player.getPlaybackState();
13971424 int realPlaybackState = player == null ? Player .STATE_IDLE : player .getPlaybackState ();
1398- int playbackState = LimitedSeekRange .adjustPlaybackState (realPlaybackState , limitedSeekRange );
1425+ int playbackState = LimitedSeekRange .scalePlaybackState (realPlaybackState , limitedSeekRange );
13991426 if (player != null && player .isPlaying () && playbackState != Player .STATE_ENDED ) {
14001427 long mediaTimeDelayMs =
14011428 timeBar != null ? timeBar .getPreferredUpdateDelay () : MAX_UPDATE_INTERVAL_MS ;
0 commit comments