Merge pull request #3967 from ByteHamster/make-controller-smaller
Removed unused code from PlaybackController
This commit is contained in:
commit
ddc8cc7cba
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue