private void repaintDueToPlaybackStateChange(long oldMaxPosition, long newMaxPosition,
                                                 PlaybackState oldState, PlaybackState newState) {
        if (duration.get() > 0) {  // We are only drawing markers if we know the track duration
            final int width = waveformWidth() + 8;

            // See if we need to redraw a stretch of the “played until” stripe.
            if (oldMaxPosition > newMaxPosition) {
                final int left = Math.max(0, Math.min(width, millisecondsToX(newMaxPosition) - 6));
                final int right = Math.max(0, Math.min(width, millisecondsToX(oldMaxPosition) + 6));
                delegatingRepaint(left, 0, right - left, getHeight());
            } else if (newMaxPosition > oldMaxPosition) {
                final int left = Math.max(0, Math.min(width, millisecondsToX(oldMaxPosition) - 6));
                final int right = Math.max(0, Math.min(width, millisecondsToX(newMaxPosition) + 6));
                delegatingRepaint(left, 0, right - left, getHeight());
            }

            // Also refresh where the specific marker was moved from and/or to.
            if (oldState != null && (newState == null || newState.position != oldState.position)) {
                final int left = Math.max(0, Math.min(width, millisecondsToX(oldState.position) - 6));
                final int right = Math.max(0, Math.min(width, millisecondsToX(oldState.position) + 6));
                delegatingRepaint(left, 0, right - left, getHeight());
            }
            if (newState != null && (oldState == null || newState.position != oldState.position)) {
                final int left = Math.max(0, Math.min(width, millisecondsToX(newState.position) - 6));
                final int right = Math.max(0, Math.min(width, millisecondsToX(newState.position) + 6));
                delegatingRepaint(left, 0, right - left, getHeight());
            }
        }
    }
private void repaintDueToPlaybackStateChange ( long oldMaxPosition , long newMaxPosition , PlaybackState oldState , PlaybackState newState ) { if ( duration . get ( ) > 0 ) { final int width = waveformWidth ( ) + 8 ; if ( oldMaxPosition > newMaxPosition ) { final int left = Math . max ( 0 , Math . min ( width , millisecondsToX ( newMaxPosition ) - 6 ) ) ; final int right = Math . max ( 0 , Math . min ( width , millisecondsToX ( oldMaxPosition ) + 6 ) ) ; delegatingRepaint ( left , 0 , right - left , getHeight ( ) ) ; } else if ( newMaxPosition > oldMaxPosition ) { final int left = Math . max ( 0 , Math . min ( width , millisecondsToX ( oldMaxPosition ) - 6 ) ) ; final int right = Math . max ( 0 , Math . min ( width , millisecondsToX ( newMaxPosition ) + 6 ) ) ; delegatingRepaint ( left , 0 , right - left , getHeight ( ) ) ; } if ( oldState != null && ( newState == null || newState . position != oldState . position ) ) { final int left = Math . max ( 0 , Math . min ( width , millisecondsToX ( oldState . position ) - 6 ) ) ; final int right = Math . max ( 0 , Math . min ( width , millisecondsToX ( oldState . position ) + 6 ) ) ; delegatingRepaint ( left , 0 , right - left , getHeight ( ) ) ; } if ( newState != null && ( oldState == null || newState . position != oldState . position ) ) { final int left = Math . max ( 0 , Math . min ( width , millisecondsToX ( newState . position ) - 6 ) ) ; final int right = Math . max ( 0 , Math . min ( width , millisecondsToX ( newState . position ) + 6 ) ) ; delegatingRepaint ( left , 0 , right - left , getHeight ( ) ) ; } } }
Helper method to mark the parts of the component that need repainting due to a change to the
tracked playback positions.

@param oldMaxPosition The furthest playback position in our previous state
@param newMaxPosition The furthest playback position in our new state
@param oldState the old position of a marker being moved, or {@code null} if we are adding a marker
@param newState the new position of a marker being moved, or {@code null} if we are removing a marker