Implemented missing PlaybackController state handling

This commit is contained in:
ByteHamster 2020-03-25 16:09:39 +01:00
parent 982ce61b3f
commit a989db586a
8 changed files with 42 additions and 106 deletions

View File

@ -137,16 +137,6 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
return butPlay;
}
@Override
public void postStatusMsg(int msg, boolean showToast) {
MediaplayerActivity.this.postStatusMsg(msg, showToast);
}
@Override
public void clearStatusMsg() {
MediaplayerActivity.this.clearStatusMsg();
}
@Override
public boolean loadMediaInfo() {
return MediaplayerActivity.this.loadMediaInfo();
@ -248,12 +238,16 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
* Should be used to inform the user that the PlaybackService is currently
* buffering.
*/
protected abstract void onBufferStart();
protected void onBufferStart() {
}
/**
* Should be used to hide the view that was showing the 'buffering'-message.
*/
protected abstract void onBufferEnd();
protected void onBufferEnd() {
}
private void onBufferUpdate(float progress) {
if (sbPosition != null) {
@ -468,10 +462,6 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
*/
protected abstract void onAwaitingVideoSurface();
protected abstract void postStatusMsg(int resId, boolean showToast);
protected abstract void clearStatusMsg();
void onPositionObserverUpdate() {
if (controller == null || txtvPosition == null || txtvLength == null) {
return;

View File

@ -126,24 +126,6 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity {
startActivity(new Intent(this, VideoplayerActivity.class));
}
@Override
protected void postStatusMsg(int resId, boolean showToast) {
if (resId == R.string.player_preparing_msg
|| resId == R.string.player_seeking_msg
|| resId == R.string.player_buffering_msg) {
// TODO Show progress bar here
}
if (showToast) {
Toast.makeText(this, resId, Toast.LENGTH_SHORT).show();
}
}
@Override
protected void clearStatusMsg() {
// TODO Hide progress bar here
}
@Override
protected void setupGUI() {
super.setupGUI();
@ -199,16 +181,6 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity {
}
}
@Override
protected void onBufferStart() {
postStatusMsg(R.string.player_buffering_msg, false);
}
@Override
protected void onBufferEnd() {
clearStatusMsg();
}
public PlaybackController getPlaybackController() {
return controller;
}

View File

@ -171,20 +171,6 @@ public class VideoplayerActivity extends MediaplayerActivity {
}
}
@Override
protected void postStatusMsg(int resId, boolean showToast) {
if (resId == R.string.player_preparing_msg) {
progressIndicator.setVisibility(View.VISIBLE);
} else {
progressIndicator.setVisibility(View.INVISIBLE);
}
}
@Override
protected void clearStatusMsg() {
progressIndicator.setVisibility(View.INVISIBLE);
}
private final View.OnTouchListener onVideoviewTouched = (v, event) -> {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (PictureInPictureUtil.isInPictureInPictureMode(this)) {

View File

@ -10,9 +10,11 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ProgressBar;
import android.widget.SeekBar;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
@ -33,6 +35,7 @@ import de.danoeh.antennapod.core.service.playback.PlaybackService;
import de.danoeh.antennapod.core.util.Converter;
import de.danoeh.antennapod.core.util.IntentUtils;
import de.danoeh.antennapod.core.util.TimeSpeedConverter;
import de.danoeh.antennapod.core.util.playback.MediaPlayerError;
import de.danoeh.antennapod.core.util.playback.Playable;
import de.danoeh.antennapod.core.util.playback.PlaybackController;
import de.danoeh.antennapod.dialog.PlaybackControlsDialog;
@ -77,6 +80,7 @@ public class AudioPlayerFragment extends Fragment implements
private TextView txtvFF;
private ImageButton butSkip;
private Toolbar toolbar;
private ProgressBar progressIndicator;
private PlaybackController controller;
private boolean showTimeLeft;
@ -108,6 +112,7 @@ public class AudioPlayerFragment extends Fragment implements
butFF = root.findViewById(R.id.butFF);
txtvFF = root.findViewById(R.id.txtvFF);
butSkip = root.findViewById(R.id.butSkip);
progressIndicator = root.findViewById(R.id.progLoading);
setupLengthTextView();
setupControlButtons();
@ -249,27 +254,32 @@ public class AudioPlayerFragment extends Fragment implements
@Override
public void onBufferStart() {
//MediaplayerActivity.this.onBufferStart();
progressIndicator.setVisibility(View.VISIBLE);
}
@Override
public void onBufferEnd() {
//MediaplayerActivity.this.onBufferEnd();
progressIndicator.setVisibility(View.GONE);
}
@Override
public void onBufferUpdate(float progress) {
//MediaplayerActivity.this.onBufferUpdate(progress);
sbPosition.setSecondaryProgress((int) (progress * sbPosition.getMax()));
}
@Override
public void handleError(int code) {
//MediaplayerActivity.this.handleError(code);
}
@Override
public void onReloadNotification(int code) {
//MediaplayerActivity.this.onReloadNotification(code);
final AlertDialog.Builder errorDialog = new AlertDialog.Builder(getContext());
errorDialog.setTitle(R.string.error_label);
errorDialog.setMessage(MediaPlayerError.getErrorString(getContext(), code));
errorDialog.setNeutralButton(android.R.string.ok,
(dialog, which) -> {
dialog.dismiss();
((MainActivity) getActivity()).getBottomSheet()
.setState(BottomSheetBehavior.STATE_COLLAPSED);
}
);
errorDialog.create().show();
}
@Override
@ -282,36 +292,21 @@ public class AudioPlayerFragment extends Fragment implements
return butPlay;
}
@Override
public void postStatusMsg(int msg, boolean showToast) {
//MediaplayerActivity.this.postStatusMsg(msg, showToast);
}
@Override
public void clearStatusMsg() {
//MediaplayerActivity.this.clearStatusMsg();
}
@Override
public boolean loadMediaInfo() {
updateUi();
return true;
}/*
@Override
public void onServiceQueried() {
MediaplayerActivity.this.onServiceQueried();
}
@Override
public void onShutdownNotification() {
finish();
((MainActivity) getActivity()).getBottomSheet().setState(BottomSheetBehavior.STATE_COLLAPSED);
}
@Override
public void onPlaybackEnd() {
finish();
}*/
((MainActivity) getActivity()).getBottomSheet().setState(BottomSheetBehavior.STATE_COLLAPSED);
}
@Override
public void onPlaybackSpeedChange() {
@ -344,7 +339,6 @@ public class AudioPlayerFragment extends Fragment implements
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRetainInstance(true);
//setHasOptionsMenu(true);
}
@Override

View File

@ -134,6 +134,15 @@
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"/>
<ProgressBar
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:id="@+id/progLoading"
android:visibility="gone"/>
<ImageButton
android:id="@+id/butRev"
android:layout_width="@dimen/audioplayer_playercontrols_length"

View File

@ -181,11 +181,6 @@ public class PlaybackService extends MediaBrowserServiceCompat {
*/
public static final int NOTIFICATION_TYPE_SET_SPEED_ABILITY_CHANGED = 9;
/**
* Send a message to the user (with provided String resource id)
*/
public static final int NOTIFICATION_TYPE_SHOW_TOAST = 10;
/**
* Returned by getPositionSafe() or getDurationSafe() if the playbackService
* is in an invalid state.

View File

@ -21,6 +21,7 @@ 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;
@ -333,8 +334,6 @@ public class PlaybackController {
case PlaybackService.NOTIFICATION_TYPE_SET_SPEED_ABILITY_CHANGED:
onSetSpeedAbilityChanged();
break;
case PlaybackService.NOTIFICATION_TYPE_SHOW_TOAST:
postStatusMsg(code, true);
}
}
@ -411,11 +410,10 @@ public class PlaybackController {
Log.d(TAG, "status: " + status.toString());
switch (status) {
case ERROR:
postStatusMsg(R.string.player_error_msg, false);
EventBus.getDefault().post(new MessageEvent(activity.getString(R.string.player_error_msg)));
handleError(MediaPlayer.MEDIA_ERROR_UNKNOWN);
break;
case PAUSED:
clearStatusMsg();
checkMediaInfoLoaded();
onPositionObserverUpdate();
updatePlayButtonAppearance(playResource, playText);
@ -425,7 +423,6 @@ public class PlaybackController {
}
break;
case PLAYING:
clearStatusMsg();
checkMediaInfoLoaded();
if (!PlaybackService.isCasting() &&
PlaybackService.getCurrentMediaType() == MediaType.VIDEO) {
@ -435,7 +432,6 @@ public class PlaybackController {
updatePlayButtonAppearance(pauseResource, pauseText);
break;
case PREPARING:
postStatusMsg(R.string.player_preparing_msg, false);
checkMediaInfoLoaded();
if (playbackService != null) {
if (playbackService.isStartWhenPrepared()) {
@ -446,21 +442,17 @@ public class PlaybackController {
}
break;
case STOPPED:
postStatusMsg(R.string.player_stopped_msg, false);
break;
case PREPARED:
checkMediaInfoLoaded();
postStatusMsg(R.string.player_ready_msg, false);
updatePlayButtonAppearance(playResource, playText);
onPositionObserverUpdate();
break;
case SEEKING:
onPositionObserverUpdate();
postStatusMsg(R.string.player_seeking_msg, false);
break;
case INITIALIZED:
checkMediaInfoLoaded();
clearStatusMsg();
updatePlayButtonAppearance(playResource, playText);
break;
}
@ -482,10 +474,6 @@ public class PlaybackController {
return null;
}
public void postStatusMsg(int msg, boolean showToast) {}
public void clearStatusMsg() {}
public boolean loadMediaInfo() {
return false;
}

View File

@ -26,9 +26,11 @@ import java.util.concurrent.TimeoutException;
import de.danoeh.antennapod.core.cast.CastConsumer;
import de.danoeh.antennapod.core.cast.CastManager;
import de.danoeh.antennapod.core.cast.DefaultCastConsumer;
import de.danoeh.antennapod.core.event.MessageEvent;
import de.danoeh.antennapod.core.feed.MediaType;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.util.NetworkUtils;
import org.greenrobot.eventbus.EventBus;
/**
* Class intended to work along PlaybackService and provide support for different flavors.
@ -106,7 +108,7 @@ public class PlaybackServiceFlavorHelper {
}
switch (code) {
case RemotePSMP.CAST_ERROR:
callback.sendNotificationBroadcast(PlaybackService.NOTIFICATION_TYPE_SHOW_TOAST, resourceId);
EventBus.getDefault().post(new MessageEvent(context.getString(resourceId)));
return true;
case RemotePSMP.CAST_ERROR_PRIORITY_HIGH:
Toast.makeText(context, resourceId, Toast.LENGTH_SHORT).show();