diff --git a/app/src/androidTest/java/de/test/antennapod/ui/SpeedChangeTest.java b/app/src/androidTest/java/de/test/antennapod/ui/SpeedChangeTest.java index 5565bf474..e91554521 100644 --- a/app/src/androidTest/java/de/test/antennapod/ui/SpeedChangeTest.java +++ b/app/src/androidTest/java/de/test/antennapod/ui/SpeedChangeTest.java @@ -75,7 +75,7 @@ public class SpeedChangeTest { EspressoTestUtils.tryKillPlaybackService(); activityRule.launchActivity(new Intent().putExtra(MainActivity.EXTRA_OPEN_PLAYER, true)); - controller = new PlaybackController(activityRule.getActivity(), true); + controller = new PlaybackController(activityRule.getActivity()); controller.init(); controller.getMedia(); // To load media } diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java index 55aadc60b..9a4a5ef3a 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java @@ -93,7 +93,7 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements private Disposable disposable; private PlaybackController newPlaybackController() { - return new PlaybackController(this, false) { + return new PlaybackController(this) { @Override public void setupGUI() { @@ -150,11 +150,6 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements MediaplayerActivity.this.onAwaitingVideoSurface(); } - @Override - public void onServiceQueried() { - MediaplayerActivity.this.onServiceQueried(); - } - @Override public void onShutdownNotification() { finish(); @@ -197,10 +192,6 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements updatePlaybackSpeedButtonText(); } - private void onServiceQueried() { - supportInvalidateOptionsMenu(); - } - void chooseTheme() { setTheme(UserPreferences.getTheme()); } @@ -648,31 +639,33 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements private float prog; @Override - public void onProgressChanged(SeekBar seekBar,int progress, boolean fromUser) { + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if (controller == null || txtvLength == null) { return; } - prog = controller.onSeekBarProgressChanged(seekBar, progress, fromUser, txtvPosition); - if (showTimeLeft && prog != 0) { + if (fromUser) { + prog = progress / ((float) seekBar.getMax()); int duration = controller.getDuration(); TimeSpeedConverter converter = new TimeSpeedConverter(controller.getCurrentPlaybackSpeedMultiplier()); - int timeLeft = converter.convert(duration - (int) (prog * duration)); - String length = "-" + Converter.getDurationStringLong(timeLeft); - txtvLength.setText(length); + int position = converter.convert((int) (prog * duration)); + txtvPosition.setText(Converter.getDurationStringLong(position)); + + if (showTimeLeft) { + int timeLeft = converter.convert(duration - (int) (prog * duration)); + txtvLength.setText("-" + Converter.getDurationStringLong(timeLeft)); + } } } @Override public void onStartTrackingTouch(SeekBar seekBar) { - if (controller != null) { - controller.onSeekBarStartTrackingTouch(seekBar); - } + } @Override public void onStopTrackingTouch(SeekBar seekBar) { if (controller != null) { - controller.onSeekBarStopTrackingTouch(seekBar, prog); + controller.seekTo((int) (prog * controller.getDuration())); } } diff --git a/app/src/main/java/de/danoeh/antennapod/activity/VideoplayerActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/VideoplayerActivity.java index 212cb2f75..cb79a9265 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/VideoplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/VideoplayerActivity.java @@ -247,11 +247,7 @@ public class VideoplayerActivity extends MediaplayerActivity { Log.d(TAG, "Videoview holder created"); videoSurfaceCreated = true; if (controller != null && controller.getStatus() == PlayerStatus.PLAYING) { - if (controller.serviceAvailable()) { - controller.setVideoSurface(holder); - } else { - Log.e(TAG, "Couldn't attach surface to mediaplayer - reference to service was null"); - } + controller.setVideoSurface(holder); } setupVideoAspectRatio(); } diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/PlaybackControlsDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/PlaybackControlsDialog.java index 95d6dfd9e..894b54529 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/PlaybackControlsDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/PlaybackControlsDialog.java @@ -39,7 +39,7 @@ public class PlaybackControlsDialog extends DialogFragment { @Override public void onStart() { super.onStart(); - controller = new PlaybackController(getActivity(), false) { + controller = new PlaybackController(getActivity()) { @Override public void setupGUI() { setupUi(); diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/SleepTimerDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/SleepTimerDialog.java index d36f97c7a..0a35c95ff 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/SleepTimerDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/SleepTimerDialog.java @@ -49,7 +49,7 @@ public class SleepTimerDialog extends DialogFragment { @Override public void onStart() { super.onStart(); - controller = new PlaybackController(getActivity(), false) { + controller = new PlaybackController(getActivity()) { @Override public void setupGUI() { updateTime(); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/AudioPlayerFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/AudioPlayerFragment.java index 0be59904d..430968549 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/AudioPlayerFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/AudioPlayerFragment.java @@ -246,7 +246,7 @@ public class AudioPlayerFragment extends Fragment implements } private PlaybackController newPlaybackController() { - return new PlaybackController(getActivity(), false) { + return new PlaybackController(getActivity()) { @Override public void setupGUI() { diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ChaptersFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ChaptersFragment.java index 0aba568d1..e097a40fb 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ChaptersFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ChaptersFragment.java @@ -70,7 +70,7 @@ public class ChaptersFragment extends Fragment { @Override public void onStart() { super.onStart(); - controller = new PlaybackController(getActivity(), false) { + controller = new PlaybackController(getActivity()) { @Override public boolean loadMediaInfo() { ChaptersFragment.this.loadMediaInfo(); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/CoverFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/CoverFragment.java index 4f8b4e971..eb8889fb7 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/CoverFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/CoverFragment.java @@ -97,7 +97,7 @@ public class CoverFragment extends Fragment { @Override public void onStart() { super.onStart(); - controller = new PlaybackController(getActivity(), false) { + controller = new PlaybackController(getActivity()) { @Override public boolean loadMediaInfo() { CoverFragment.this.loadMediaInfo(); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java index 03b1d6f8f..2626713c1 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java @@ -90,7 +90,7 @@ public class ExternalPlayerFragment extends Fragment { } private PlaybackController setupPlaybackController() { - return new PlaybackController(getActivity(), true) { + return new PlaybackController(getActivity()) { @Override public void onPositionObserverUpdate() { diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java index 58cc9290c..ba7ef169d 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java @@ -135,7 +135,7 @@ public class ItemDescriptionFragment extends Fragment { @Override public void onStart() { super.onStart(); - controller = new PlaybackController(getActivity(), false) { + controller = new PlaybackController(getActivity()) { @Override public boolean loadMediaInfo() { if (getMedia() == null) { diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java index fdb4ece20..f20b7f555 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java @@ -175,7 +175,7 @@ public class ItemFragment extends Fragment { public void onStart() { super.onStart(); EventBus.getDefault().register(this); - controller = new PlaybackController(getActivity(), false); + controller = new PlaybackController(getActivity()); controller.init(); } diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java b/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java index baf5d924f..eb189eb4e 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java @@ -11,35 +11,28 @@ import android.content.res.TypedArray; import android.media.MediaPlayer; import android.os.Build; import android.os.IBinder; -import androidx.annotation.NonNull; -import androidx.core.content.ContextCompat; import android.text.TextUtils; import android.util.Log; import android.util.Pair; import android.view.SurfaceHolder; import android.widget.ImageButton; -import android.widget.SeekBar; -import android.widget.TextView; - -import de.danoeh.antennapod.core.event.MessageEvent; -import de.danoeh.antennapod.core.util.ThemeUtils; -import java.util.concurrent.ScheduledThreadPoolExecutor; - +import androidx.annotation.NonNull; +import androidx.core.content.ContextCompat; import de.danoeh.antennapod.core.R; +import de.danoeh.antennapod.core.event.MessageEvent; import de.danoeh.antennapod.core.event.ServiceEvent; import de.danoeh.antennapod.core.feed.Chapter; import de.danoeh.antennapod.core.feed.FeedMedia; import de.danoeh.antennapod.core.feed.MediaType; -import de.danoeh.antennapod.core.preferences.PlaybackPreferences; import de.danoeh.antennapod.core.feed.util.PlaybackSpeedUtils; +import de.danoeh.antennapod.core.preferences.PlaybackPreferences; import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.service.playback.PlaybackService; import de.danoeh.antennapod.core.service.playback.PlaybackServiceMediaPlayer; import de.danoeh.antennapod.core.service.playback.PlayerStatus; import de.danoeh.antennapod.core.storage.DBTasks; -import de.danoeh.antennapod.core.util.Converter; import de.danoeh.antennapod.core.util.Optional; -import de.danoeh.antennapod.core.util.TimeSpeedConverter; +import de.danoeh.antennapod.core.util.ThemeUtils; import de.danoeh.antennapod.core.util.playback.Playable.PlayableUtils; import io.reactivex.Maybe; import io.reactivex.MaybeOnSubscribe; @@ -51,6 +44,8 @@ import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; +import java.util.concurrent.ScheduledThreadPoolExecutor; + /** * Communicates with the playback service. GUI classes should use this class to * control playback instead of communicating with the PlaybackService directly. @@ -78,16 +73,9 @@ public class PlaybackController { private Disposable serviceBinder; private Disposable mediaLoader; - /** - * True if controller should reinit playback service if 'pause' button is - * pressed. - */ - private final boolean reinitOnPause; - - public PlaybackController(@NonNull Activity activity, boolean reinitOnPause) { + public PlaybackController(@NonNull Activity activity) { this.activity = activity; - this.reinitOnPause = reinitOnPause; schedExecutor = new ScheduledThreadPoolExecutor(SCHED_EX_POOLSIZE, r -> { Thread t = new Thread(r); @@ -276,7 +264,7 @@ public class PlaybackController { @Override public void onReceive(Context context, Intent intent) { Log.d(TAG, "Received statusUpdate Intent."); - if (isConnectedToPlaybackService()) { + if (playbackService != null) { PlaybackServiceMediaPlayer.PSMPInfo info = playbackService.getPSMPInfo(); status = info.playerStatus; media = info.playable; @@ -307,7 +295,7 @@ public class PlaybackController { onBufferUpdate(progress); break; case PlaybackService.NOTIFICATION_TYPE_RELOAD: - if (!isConnectedToPlaybackService()) { + if (playbackService == null) { bindToService(); return; } @@ -343,7 +331,7 @@ public class PlaybackController { @Override public void onReceive(Context context, Intent intent) { - if (isConnectedToPlaybackService()) { + if (playbackService != null) { if (TextUtils.equals(intent.getAction(), PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE)) { release(); @@ -484,7 +472,6 @@ public class PlaybackController { PlaybackServiceMediaPlayer.PSMPInfo info = playbackService.getPSMPInfo(); status = info.playerStatus; media = info.playable; - onServiceQueried(); setupGUI(); handleStatus(); @@ -497,41 +484,6 @@ public class PlaybackController { } } - public void onServiceQueried() {} - - /** - * Should be used by classes which implement the OnSeekBarChanged interface. - */ - public float onSeekBarProgressChanged(SeekBar seekBar, int progress, - boolean fromUser, TextView txtvPosition) { - if (fromUser && playbackService != null && media != null) { - float prog = progress / ((float) seekBar.getMax()); - int duration = media.getDuration(); - TimeSpeedConverter converter = new TimeSpeedConverter(playbackService.getCurrentPlaybackSpeed()); - int position = converter.convert((int) (prog * duration)); - txtvPosition.setText(Converter.getDurationStringLong(position)); - return prog; - } - return 0; - - } - - /** - * Should be used by classes which implement the OnSeekBarChanged interface. - */ - public void onSeekBarStartTrackingTouch(SeekBar seekBar) { - // interrupt position Observer, restart later - } - - /** - * Should be used by classes which implement the OnSeekBarChanged interface. - */ - public void onSeekBarStopTrackingTouch(SeekBar seekBar, float prog) { - if (playbackService != null && media != null) { - seekTo((int) (prog * getDuration())); - } - } - /** * Should be implemented by classes that show a video. The default implementation * does nothing @@ -553,19 +505,14 @@ public class PlaybackController { } switch (status) { case PLAYING: - playbackService.pause(true, reinitOnPause); + playbackService.pause(true, false); break; case PAUSED: case PREPARED: playbackService.resume(); break; case PREPARING: - playbackService.setStartWhenPrepared(!playbackService - .isStartWhenPrepared()); - if (reinitOnPause - && !playbackService.isStartWhenPrepared()) { - playbackService.reinit(); - } + playbackService.setStartWhenPrepared(!playbackService.isStartWhenPrepared()); break; case INITIALIZED: playbackService.setStartWhenPrepared(true); @@ -574,10 +521,6 @@ public class PlaybackController { } } - public boolean serviceAvailable() { - return playbackService != null; - } - public int getPosition() { if (playbackService != null) { return playbackService.getCurrentPosition(); @@ -665,6 +608,7 @@ public class PlaybackController { onPlaybackSpeedChange(); } } + public void setSkipSilence(boolean skipSilence) { if (playbackService != null) { playbackService.skipSilence(skipSilence); @@ -691,7 +635,7 @@ public class PlaybackController { } public void setDownmix(boolean enable) { - if(playbackService != null) { + if (playbackService != null) { playbackService.setDownmix(enable); } } @@ -714,15 +658,6 @@ public class PlaybackController { } } - - /** - * Returns true if PlaybackController can communicate with the playback - * service. - */ - private boolean isConnectedToPlaybackService() { - return playbackService != null; - } - public void notifyVideoSurfaceAbandoned() { if (playbackService != null) { playbackService.notifyVideoSurfaceAbandoned();