No need to define INVALID_TIME multiple times
This commit is contained in:
parent
17f2ebd7f2
commit
a29041cd4d
|
@ -669,8 +669,8 @@ public class VideoplayerActivity extends CastEnabledActivity implements SeekBar.
|
|||
int remainingTime = converter.convert(
|
||||
controller.getDuration() - controller.getPosition());
|
||||
Log.d(TAG, "currentPosition " + Converter.getDurationStringLong(currentPosition));
|
||||
if (currentPosition == PlaybackService.INVALID_TIME
|
||||
|| duration == PlaybackService.INVALID_TIME) {
|
||||
if (currentPosition == Playable.INVALID_TIME
|
||||
|| duration == Playable.INVALID_TIME) {
|
||||
Log.w(TAG, "Could not react to position observer update because of invalid time");
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -28,7 +28,6 @@ import com.google.android.material.elevation.SurfaceColors;
|
|||
import com.google.android.material.snackbar.Snackbar;
|
||||
|
||||
import de.danoeh.antennapod.core.receiver.MediaButtonReceiver;
|
||||
import de.danoeh.antennapod.core.service.playback.PlaybackService;
|
||||
import de.danoeh.antennapod.core.util.playback.PlaybackController;
|
||||
import de.danoeh.antennapod.event.playback.BufferUpdateEvent;
|
||||
import de.danoeh.antennapod.event.playback.PlaybackServiceEvent;
|
||||
|
@ -375,7 +374,7 @@ public class AudioPlayerFragment extends Fragment implements
|
|||
int remainingTime = converter.convert(Math.max(event.getDuration() - event.getPosition(), 0));
|
||||
currentChapterIndex = ChapterUtils.getCurrentChapterIndex(controller.getMedia(), currentPosition);
|
||||
Log.d(TAG, "currentPosition " + Converter.getDurationStringLong(currentPosition));
|
||||
if (currentPosition == PlaybackService.INVALID_TIME || duration == PlaybackService.INVALID_TIME) {
|
||||
if (currentPosition == Playable.INVALID_TIME || duration == Playable.INVALID_TIME) {
|
||||
Log.w(TAG, "Could not react to position observer update because of invalid time");
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -139,8 +139,8 @@ public class ExternalPlayerFragment extends Fragment {
|
|||
public void onPositionObserverUpdate(PlaybackPositionEvent event) {
|
||||
if (controller == null) {
|
||||
return;
|
||||
} else if (controller.getPosition() == PlaybackService.INVALID_TIME
|
||||
|| controller.getDuration() == PlaybackService.INVALID_TIME) {
|
||||
} else if (controller.getPosition() == Playable.INVALID_TIME
|
||||
|| controller.getDuration() == Playable.INVALID_TIME) {
|
||||
return;
|
||||
}
|
||||
progressBar.setProgress((int)
|
||||
|
|
|
@ -30,10 +30,10 @@ import de.danoeh.antennapod.model.feed.FeedMedia;
|
|||
import de.danoeh.antennapod.model.playback.MediaType;
|
||||
import de.danoeh.antennapod.core.feed.util.ImageResourceUtils;
|
||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||
import de.danoeh.antennapod.core.service.playback.PlaybackService;
|
||||
import de.danoeh.antennapod.core.util.Converter;
|
||||
import de.danoeh.antennapod.core.util.FeedItemUtil;
|
||||
import de.danoeh.antennapod.core.util.NetworkUtils;
|
||||
import de.danoeh.antennapod.model.playback.Playable;
|
||||
import de.danoeh.antennapod.ui.common.CircularProgressBar;
|
||||
import de.danoeh.antennapod.ui.common.ThemeUtils;
|
||||
|
||||
|
@ -230,7 +230,7 @@ public class EpisodeItemViewHolder extends RecyclerView.ViewHolder {
|
|||
int timeDuration = event.getDuration();
|
||||
int remainingTime = Math.max(timeDuration - currentPosition, 0);
|
||||
Log.d(TAG, "currentPosition " + Converter.getDurationStringLong(currentPosition));
|
||||
if (currentPosition == PlaybackService.INVALID_TIME || timeDuration == PlaybackService.INVALID_TIME) {
|
||||
if (currentPosition == Playable.INVALID_TIME || timeDuration == Playable.INVALID_TIME) {
|
||||
Log.w(TAG, "Could not react to position observer update because of invalid time");
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ import de.danoeh.antennapod.core.service.download.AntennapodHttpClient;
|
|||
import de.danoeh.antennapod.core.service.download.HttpCredentialEncoder;
|
||||
import de.danoeh.antennapod.core.util.NetworkUtils;
|
||||
import de.danoeh.antennapod.core.util.playback.IPlayer;
|
||||
import de.danoeh.antennapod.playback.base.PlaybackServiceMediaPlayer;
|
||||
import de.danoeh.antennapod.model.playback.Playable;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
|
@ -154,7 +154,7 @@ public class ExoPlayerWrapper implements IPlayer {
|
|||
@Override
|
||||
public int getDuration() {
|
||||
if (exoPlayer.getDuration() == C.TIME_UNSET) {
|
||||
return PlaybackServiceMediaPlayer.INVALID_TIME;
|
||||
return Playable.INVALID_TIME;
|
||||
}
|
||||
return (int) exoPlayer.getDuration();
|
||||
}
|
||||
|
|
|
@ -543,7 +543,7 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer {
|
|||
executor.submit(() -> {
|
||||
playerLock.lock();
|
||||
int currentPosition = getPosition();
|
||||
if (currentPosition != INVALID_TIME) {
|
||||
if (currentPosition != Playable.INVALID_TIME) {
|
||||
seekToSync(currentPosition + d);
|
||||
} else {
|
||||
Log.e(TAG, "getPosition() returned INVALID_TIME in seekDelta");
|
||||
|
@ -559,10 +559,10 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer {
|
|||
@Override
|
||||
public int getDuration() {
|
||||
if (!playerLock.tryLock()) {
|
||||
return INVALID_TIME;
|
||||
return Playable.INVALID_TIME;
|
||||
}
|
||||
|
||||
int retVal = INVALID_TIME;
|
||||
int retVal = Playable.INVALID_TIME;
|
||||
if (playerStatus == PlayerStatus.PLAYING
|
||||
|| playerStatus == PlayerStatus.PAUSED
|
||||
|| playerStatus == PlayerStatus.PREPARED) {
|
||||
|
@ -583,13 +583,13 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer {
|
|||
public int getPosition() {
|
||||
try {
|
||||
if (!playerLock.tryLock(50, TimeUnit.MILLISECONDS)) {
|
||||
return INVALID_TIME;
|
||||
return Playable.INVALID_TIME;
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
return INVALID_TIME;
|
||||
return Playable.INVALID_TIME;
|
||||
}
|
||||
|
||||
int retVal = INVALID_TIME;
|
||||
int retVal = Playable.INVALID_TIME;
|
||||
if (playerStatus.isAtLeast(PlayerStatus.PREPARED)) {
|
||||
retVal = mediaPlayer.getCurrentPosition();
|
||||
}
|
||||
|
|
|
@ -156,12 +156,6 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
|||
*/
|
||||
public static final int NOTIFICATION_TYPE_PLAYBACK_END = 7;
|
||||
|
||||
/**
|
||||
* Returned by getPositionSafe() or getDurationSafe() if the playbackService
|
||||
* is in an invalid state.
|
||||
*/
|
||||
public static final int INVALID_TIME = -1;
|
||||
|
||||
/**
|
||||
* Is true if service is running.
|
||||
*/
|
||||
|
@ -761,7 +755,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
|||
private final PlaybackServiceTaskManager.PSTMCallback taskManagerCallback = new PlaybackServiceTaskManager.PSTMCallback() {
|
||||
@Override
|
||||
public void positionSaverTick() {
|
||||
saveCurrentPosition(true, null, PlaybackServiceMediaPlayer.INVALID_TIME);
|
||||
saveCurrentPosition(true, null, Playable.INVALID_TIME);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -813,7 +807,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
|||
break;
|
||||
case PLAYING:
|
||||
PlaybackPreferences.writePlayerStatus(mediaPlayer.getPlayerStatus());
|
||||
saveCurrentPosition(true, null, INVALID_TIME);
|
||||
saveCurrentPosition(true, null, Playable.INVALID_TIME);
|
||||
updateNotificationAndMediaSession(newInfo.playable);
|
||||
setupPositionObserver();
|
||||
stateManager.validStartCommandWasReceived();
|
||||
|
@ -868,7 +862,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
|||
@Override
|
||||
public void onPlaybackStart(@NonNull Playable playable, int position) {
|
||||
taskManager.startWidgetUpdater();
|
||||
if (position != PlaybackServiceMediaPlayer.INVALID_TIME) {
|
||||
if (position != Playable.INVALID_TIME) {
|
||||
playable.setPosition(position);
|
||||
} else {
|
||||
skipIntro(playable);
|
||||
|
@ -881,8 +875,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
|||
public void onPlaybackPause(Playable playable, int position) {
|
||||
taskManager.cancelPositionSaver();
|
||||
cancelPositionObserver();
|
||||
saveCurrentPosition(position == PlaybackServiceMediaPlayer.INVALID_TIME || playable == null,
|
||||
playable, position);
|
||||
saveCurrentPosition(position == Playable.INVALID_TIME || playable == null, playable, position);
|
||||
taskManager.cancelWidgetUpdater();
|
||||
if (playable != null) {
|
||||
if (playable instanceof FeedMedia) {
|
||||
|
@ -1377,7 +1370,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
|||
} else {
|
||||
duration = playable.getDuration();
|
||||
}
|
||||
if (position != INVALID_TIME && duration != INVALID_TIME && playable != null) {
|
||||
if (position != Playable.INVALID_TIME && duration != Playable.INVALID_TIME && playable != null) {
|
||||
Log.d(TAG, "Saving current position to " + position);
|
||||
PlayableUtils.saveCurrentPosition(playable, position, System.currentTimeMillis());
|
||||
}
|
||||
|
@ -1653,7 +1646,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
|||
*/
|
||||
public int getDuration() {
|
||||
if (mediaPlayer == null) {
|
||||
return INVALID_TIME;
|
||||
return Playable.INVALID_TIME;
|
||||
}
|
||||
return mediaPlayer.getDuration();
|
||||
}
|
||||
|
@ -1664,7 +1657,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
|||
*/
|
||||
public int getCurrentPosition() {
|
||||
if (mediaPlayer == null) {
|
||||
return INVALID_TIME;
|
||||
return Playable.INVALID_TIME;
|
||||
}
|
||||
return mediaPlayer.getPosition();
|
||||
}
|
||||
|
|
|
@ -39,7 +39,6 @@ import java.util.List;
|
|||
public abstract class PlaybackController {
|
||||
|
||||
private static final String TAG = "PlaybackController";
|
||||
private static final int INVALID_TIME = -1;
|
||||
|
||||
private final Activity activity;
|
||||
private PlaybackService playbackService;
|
||||
|
@ -363,7 +362,7 @@ public abstract class PlaybackController {
|
|||
} else if (getMedia() != null) {
|
||||
return getMedia().getPosition();
|
||||
} else {
|
||||
return PlaybackService.INVALID_TIME;
|
||||
return Playable.INVALID_TIME;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -373,7 +372,7 @@ public abstract class PlaybackController {
|
|||
} else if (getMedia() != null) {
|
||||
return getMedia().getDuration();
|
||||
} else {
|
||||
return PlaybackService.INVALID_TIME;
|
||||
return Playable.INVALID_TIME;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -398,13 +397,13 @@ public abstract class PlaybackController {
|
|||
if (playbackService != null) {
|
||||
return playbackService.getSleepTimerTimeLeft();
|
||||
} else {
|
||||
return INVALID_TIME;
|
||||
return Playable.INVALID_TIME;
|
||||
}
|
||||
}
|
||||
|
||||
public void extendSleepTimer(long extendTime) {
|
||||
long timeLeft = getSleepTimerTimeLeft();
|
||||
if (playbackService != null && timeLeft != INVALID_TIME) {
|
||||
if (playbackService != null && timeLeft != Playable.INVALID_TIME) {
|
||||
setSleepTimer(timeLeft + extendTime);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,11 +28,6 @@ import de.danoeh.antennapod.model.playback.Playable;
|
|||
public abstract class PlaybackServiceMediaPlayer {
|
||||
private static final String TAG = "PlaybackSvcMediaPlayer";
|
||||
|
||||
/**
|
||||
* Return value of some PSMP methods if the method call failed.
|
||||
*/
|
||||
public static final int INVALID_TIME = -1;
|
||||
|
||||
private volatile PlayerStatus oldPlayerStatus;
|
||||
protected volatile PlayerStatus playerStatus;
|
||||
|
||||
|
@ -307,7 +302,7 @@ public abstract class PlaybackServiceMediaPlayer {
|
|||
* @param newStatus The new PlayerStatus. This must not be null.
|
||||
* @param newMedia The new playable object of the PSMP object. This can be null.
|
||||
* @param position The position to be set to the current Playable object in case playback started or paused.
|
||||
* Will be ignored if given the value of {@link #INVALID_TIME}.
|
||||
* Will be ignored if given the value of {@link Playable#INVALID_TIME}.
|
||||
*/
|
||||
protected final synchronized void setPlayerStatus(@NonNull PlayerStatus newStatus,
|
||||
Playable newMedia, int position) {
|
||||
|
@ -337,7 +332,7 @@ public abstract class PlaybackServiceMediaPlayer {
|
|||
* @see #setPlayerStatus(PlayerStatus, Playable, int)
|
||||
*/
|
||||
protected final void setPlayerStatus(@NonNull PlayerStatus newStatus, Playable newMedia) {
|
||||
setPlayerStatus(newStatus, newMedia, INVALID_TIME);
|
||||
setPlayerStatus(newStatus, newMedia, Playable.INVALID_TIME);
|
||||
}
|
||||
|
||||
public interface PSMPCallback {
|
||||
|
|
|
@ -173,7 +173,7 @@ public class CastPsmp extends PlaybackServiceMediaPlayer {
|
|||
|
||||
if (mediaChanged && stateChanged && oldState == MediaStatus.PLAYER_STATE_PLAYING
|
||||
&& state != MediaStatus.PLAYER_STATE_IDLE) {
|
||||
callback.onPlaybackPause(null, INVALID_TIME);
|
||||
callback.onPlaybackPause(null, Playable.INVALID_TIME);
|
||||
// We don't want setPlayerStatus to handle the onPlaybackPause callback
|
||||
setPlayerStatus(PlayerStatus.INDETERMINATE, currentMedia);
|
||||
}
|
||||
|
@ -197,7 +197,7 @@ public class CastPsmp extends PlaybackServiceMediaPlayer {
|
|||
case MediaStatus.PLAYER_STATE_BUFFERING:
|
||||
setPlayerStatus((mediaChanged || playerStatus == PlayerStatus.PREPARING)
|
||||
? PlayerStatus.PREPARING : PlayerStatus.SEEKING, currentMedia,
|
||||
currentMedia != null ? currentMedia.getPosition() : INVALID_TIME);
|
||||
currentMedia != null ? currentMedia.getPosition() : Playable.INVALID_TIME);
|
||||
break;
|
||||
case MediaStatus.PLAYER_STATE_IDLE:
|
||||
int reason = status.getIdleReason();
|
||||
|
@ -218,7 +218,7 @@ public class CastPsmp extends PlaybackServiceMediaPlayer {
|
|||
// Means that a request to load a different media was sent
|
||||
// Not sure if currentMedia already reflects the to be loaded one
|
||||
if (mediaChanged && oldState == MediaStatus.PLAYER_STATE_PLAYING) {
|
||||
callback.onPlaybackPause(null, INVALID_TIME);
|
||||
callback.onPlaybackPause(null, Playable.INVALID_TIME);
|
||||
setPlayerStatus(PlayerStatus.INDETERMINATE, currentMedia);
|
||||
}
|
||||
setPlayerStatus(PlayerStatus.PREPARING, currentMedia);
|
||||
|
@ -376,7 +376,7 @@ public class CastPsmp extends PlaybackServiceMediaPlayer {
|
|||
@Override
|
||||
public void seekDelta(int d) {
|
||||
int position = getPosition();
|
||||
if (position != INVALID_TIME) {
|
||||
if (position != Playable.INVALID_TIME) {
|
||||
seekTo(position + d);
|
||||
} else {
|
||||
Log.e(TAG, "getPosition() returned INVALID_TIME in seekDelta");
|
||||
|
@ -386,7 +386,7 @@ public class CastPsmp extends PlaybackServiceMediaPlayer {
|
|||
@Override
|
||||
public int getDuration() {
|
||||
int retVal = (int) remoteMediaClient.getStreamDuration();
|
||||
if (retVal == INVALID_TIME && media != null && media.getDuration() > 0) {
|
||||
if (retVal == Playable.INVALID_TIME && media != null && media.getDuration() > 0) {
|
||||
retVal = media.getDuration();
|
||||
}
|
||||
return retVal;
|
||||
|
@ -542,7 +542,7 @@ public class CastPsmp extends PlaybackServiceMediaPlayer {
|
|||
}
|
||||
} else if (isPlaying) {
|
||||
callback.onPlaybackPause(currentMedia,
|
||||
currentMedia != null ? currentMedia.getPosition() : INVALID_TIME);
|
||||
currentMedia != null ? currentMedia.getPosition() : Playable.INVALID_TIME);
|
||||
}
|
||||
|
||||
FutureTask<?> future = new FutureTask<>(() -> { }, null);
|
||||
|
|
Loading…
Reference in New Issue