No need to have other classes depend on the entire playback service when they just need one constant
This commit is contained in:
parent
323149642a
commit
ae3971a58f
@ -35,6 +35,7 @@ import de.danoeh.antennapod.core.event.DownloadEvent;
|
||||
import de.danoeh.antennapod.core.service.download.DownloadService;
|
||||
import de.danoeh.antennapod.core.service.download.DownloadRequestCreator;
|
||||
import de.danoeh.antennapod.core.feed.FeedUrlNotFoundException;
|
||||
import de.danoeh.antennapod.core.service.playback.PlaybackServiceInterface;
|
||||
import de.danoeh.antennapod.core.util.DownloadErrorLabel;
|
||||
import de.danoeh.antennapod.event.FeedListUpdateEvent;
|
||||
import de.danoeh.antennapod.event.PlayerStatusEvent;
|
||||
@ -46,7 +47,6 @@ import de.danoeh.antennapod.core.service.download.DownloadRequest;
|
||||
import de.danoeh.antennapod.model.download.DownloadStatus;
|
||||
import de.danoeh.antennapod.core.service.download.Downloader;
|
||||
import de.danoeh.antennapod.core.service.download.HttpDownloader;
|
||||
import de.danoeh.antennapod.core.service.playback.PlaybackService;
|
||||
import de.danoeh.antennapod.core.storage.DBReader;
|
||||
import de.danoeh.antennapod.core.storage.DBWriter;
|
||||
import de.danoeh.antennapod.net.discovery.CombinedSearcher;
|
||||
@ -465,7 +465,7 @@ public class OnlineFeedViewActivity extends AppCompatActivity {
|
||||
|
||||
viewBinding.stopPreviewButton.setOnClickListener(v -> {
|
||||
PlaybackPreferences.writeNoMediaPlaying();
|
||||
IntentUtils.sendLocalBroadcast(this, PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE);
|
||||
IntentUtils.sendLocalBroadcast(this, PlaybackServiceInterface.ACTION_SHUTDOWN_PLAYBACK_SERVICE);
|
||||
});
|
||||
|
||||
if (UserPreferences.isEnableAutodownload()) {
|
||||
|
@ -17,7 +17,7 @@ import de.danoeh.antennapod.activity.MainActivity;
|
||||
import de.danoeh.antennapod.core.preferences.PlaybackPreferences;
|
||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||
import de.danoeh.antennapod.core.receiver.MediaButtonReceiver;
|
||||
import de.danoeh.antennapod.core.service.playback.PlaybackService;
|
||||
import de.danoeh.antennapod.core.service.playback.PlaybackServiceInterface;
|
||||
import de.danoeh.antennapod.core.storage.DBWriter;
|
||||
import de.danoeh.antennapod.core.sync.SynchronizationSettings;
|
||||
import de.danoeh.antennapod.core.sync.queue.SynchronizationQueueSink;
|
||||
@ -188,7 +188,7 @@ public class FeedItemMenuHandler {
|
||||
selectedItem.getMedia().setPosition(0);
|
||||
if (PlaybackPreferences.getCurrentlyPlayingFeedMediaId() == selectedItem.getMedia().getId()) {
|
||||
PlaybackPreferences.writeNoMediaPlaying();
|
||||
IntentUtils.sendLocalBroadcast(context, PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE);
|
||||
IntentUtils.sendLocalBroadcast(context, PlaybackServiceInterface.ACTION_SHUTDOWN_PLAYBACK_SERVICE);
|
||||
}
|
||||
DBWriter.markItemPlayed(selectedItem, FeedItem.UNPLAYED, true);
|
||||
} else if (menuItemId == R.id.visit_website_item) {
|
||||
|
@ -109,53 +109,21 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
||||
*/
|
||||
private static final String TAG = "PlaybackService";
|
||||
|
||||
public static final String EXTRA_PLAYABLE = "PlaybackService.PlayableExtra";
|
||||
public static final String EXTRA_ALLOW_STREAM_THIS_TIME = "extra.de.danoeh.antennapod.core.service.allowStream";
|
||||
public static final String EXTRA_ALLOW_STREAM_ALWAYS = "extra.de.danoeh.antennapod.core.service.allowStreamAlways";
|
||||
|
||||
public static final String ACTION_PLAYER_STATUS_CHANGED = "action.de.danoeh.antennapod.core.service.playerStatusChanged";
|
||||
private static final String AVRCP_ACTION_PLAYER_STATUS_CHANGED = "com.android.music.playstatechanged";
|
||||
private static final String AVRCP_ACTION_META_CHANGED = "com.android.music.metachanged";
|
||||
|
||||
public static final String ACTION_PLAYER_NOTIFICATION = "action.de.danoeh.antennapod.core.service.playerNotification";
|
||||
public static final String EXTRA_NOTIFICATION_CODE = "extra.de.danoeh.antennapod.core.service.notificationCode";
|
||||
public static final String EXTRA_NOTIFICATION_TYPE = "extra.de.danoeh.antennapod.core.service.notificationType";
|
||||
|
||||
/**
|
||||
* If the PlaybackService receives this action, it will stop playback and
|
||||
* try to shutdown.
|
||||
*/
|
||||
public static final String ACTION_SHUTDOWN_PLAYBACK_SERVICE = "action.de.danoeh.antennapod.core.service.actionShutdownPlaybackService";
|
||||
|
||||
/**
|
||||
* Custom action used by Android Wear, Android Auto
|
||||
*/
|
||||
private static final String CUSTOM_ACTION_FAST_FORWARD = "action.de.danoeh.antennapod.core.service.fastForward";
|
||||
private static final String CUSTOM_ACTION_REWIND = "action.de.danoeh.antennapod.core.service.rewind";
|
||||
|
||||
|
||||
/**
|
||||
* Used in NOTIFICATION_TYPE_RELOAD.
|
||||
*/
|
||||
public static final int EXTRA_CODE_AUDIO = 1;
|
||||
public static final int EXTRA_CODE_VIDEO = 2;
|
||||
public static final int EXTRA_CODE_CAST = 3;
|
||||
|
||||
/**
|
||||
* Receivers of this intent should update their information about the curently playing media
|
||||
*/
|
||||
public static final int NOTIFICATION_TYPE_RELOAD = 3;
|
||||
|
||||
/**
|
||||
* Set a max number of episodes to load for Android Auto, otherwise there could be performance issues
|
||||
*/
|
||||
public static final int MAX_ANDROID_AUTO_EPISODES_PER_FEED = 100;
|
||||
|
||||
/**
|
||||
* No more episodes are going to be played.
|
||||
*/
|
||||
public static final int NOTIFICATION_TYPE_PLAYBACK_END = 7;
|
||||
|
||||
/**
|
||||
* Is true if service is running.
|
||||
*/
|
||||
@ -243,7 +211,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
||||
|
||||
registerReceiver(autoStateUpdated, new IntentFilter("com.google.android.gms.car.media.STATUS"));
|
||||
registerReceiver(headsetDisconnected, new IntentFilter(Intent.ACTION_HEADSET_PLUG));
|
||||
registerReceiver(shutdownReceiver, new IntentFilter(ACTION_SHUTDOWN_PLAYBACK_SERVICE));
|
||||
registerReceiver(shutdownReceiver, new IntentFilter(PlaybackServiceInterface.ACTION_SHUTDOWN_PLAYBACK_SERVICE));
|
||||
registerReceiver(bluetoothStateUpdated, new IntentFilter(BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED));
|
||||
registerReceiver(audioBecomingNoisy, new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY));
|
||||
EventBus.getDefault().register(this);
|
||||
@ -478,7 +446,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
||||
|
||||
final int keycode = intent.getIntExtra(MediaButtonReceiver.EXTRA_KEYCODE, -1);
|
||||
final boolean hardwareButton = intent.getBooleanExtra(MediaButtonReceiver.EXTRA_HARDWAREBUTTON, false);
|
||||
Playable playable = intent.getParcelableExtra(EXTRA_PLAYABLE);
|
||||
Playable playable = intent.getParcelableExtra(PlaybackServiceInterface.EXTRA_PLAYABLE);
|
||||
if (keycode == -1 && playable == null) {
|
||||
Log.e(TAG, "PlaybackService was started with no arguments");
|
||||
stateManager.stopService();
|
||||
@ -505,9 +473,11 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
||||
}
|
||||
} else {
|
||||
stateManager.validStartCommandWasReceived();
|
||||
boolean allowStreamThisTime = intent.getBooleanExtra(EXTRA_ALLOW_STREAM_THIS_TIME, false);
|
||||
boolean allowStreamAlways = intent.getBooleanExtra(EXTRA_ALLOW_STREAM_ALWAYS, false);
|
||||
sendNotificationBroadcast(NOTIFICATION_TYPE_RELOAD, 0);
|
||||
boolean allowStreamThisTime = intent.getBooleanExtra(
|
||||
PlaybackServiceInterface.EXTRA_ALLOW_STREAM_THIS_TIME, false);
|
||||
boolean allowStreamAlways = intent.getBooleanExtra(
|
||||
PlaybackServiceInterface.EXTRA_ALLOW_STREAM_ALWAYS, false);
|
||||
sendNotificationBroadcast(PlaybackServiceInterface.NOTIFICATION_TYPE_RELOAD, 0);
|
||||
if (allowStreamAlways) {
|
||||
UserPreferences.setAllowMobileStreaming(true);
|
||||
}
|
||||
@ -561,8 +531,8 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
||||
|
||||
private void displayStreamingNotAllowedNotification(Intent originalIntent) {
|
||||
Intent intentAllowThisTime = new Intent(originalIntent);
|
||||
intentAllowThisTime.setAction(EXTRA_ALLOW_STREAM_THIS_TIME);
|
||||
intentAllowThisTime.putExtra(EXTRA_ALLOW_STREAM_THIS_TIME, true);
|
||||
intentAllowThisTime.setAction(PlaybackServiceInterface.EXTRA_ALLOW_STREAM_THIS_TIME);
|
||||
intentAllowThisTime.putExtra(PlaybackServiceInterface.EXTRA_ALLOW_STREAM_THIS_TIME, true);
|
||||
PendingIntent pendingIntentAllowThisTime;
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
||||
pendingIntentAllowThisTime = PendingIntent.getForegroundService(this,
|
||||
@ -575,8 +545,8 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
||||
}
|
||||
|
||||
Intent intentAlwaysAllow = new Intent(intentAllowThisTime);
|
||||
intentAlwaysAllow.setAction(EXTRA_ALLOW_STREAM_ALWAYS);
|
||||
intentAlwaysAllow.putExtra(EXTRA_ALLOW_STREAM_ALWAYS, true);
|
||||
intentAlwaysAllow.setAction(PlaybackServiceInterface.EXTRA_ALLOW_STREAM_ALWAYS);
|
||||
intentAlwaysAllow.putExtra(PlaybackServiceInterface.EXTRA_ALLOW_STREAM_ALWAYS, true);
|
||||
PendingIntent pendingIntentAlwaysAllow;
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
||||
pendingIntentAlwaysAllow = PendingIntent.getForegroundService(this,
|
||||
@ -766,7 +736,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
||||
|
||||
@Override
|
||||
public void onChapterLoaded(Playable media) {
|
||||
sendNotificationBroadcast(NOTIFICATION_TYPE_RELOAD, 0);
|
||||
sendNotificationBroadcast(PlaybackServiceInterface.NOTIFICATION_TYPE_RELOAD, 0);
|
||||
}
|
||||
};
|
||||
|
||||
@ -848,7 +818,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
||||
public void onMediaChanged(boolean reloadUI) {
|
||||
Log.d(TAG, "reloadUI callback reached");
|
||||
if (reloadUI) {
|
||||
sendNotificationBroadcast(NOTIFICATION_TYPE_RELOAD, 0);
|
||||
sendNotificationBroadcast(PlaybackServiceInterface.NOTIFICATION_TYPE_RELOAD, 0);
|
||||
}
|
||||
updateNotificationAndMediaSession(getPlayable());
|
||||
}
|
||||
@ -1011,11 +981,12 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
||||
}
|
||||
}
|
||||
if (mediaType == null) {
|
||||
sendNotificationBroadcast(NOTIFICATION_TYPE_PLAYBACK_END, 0);
|
||||
sendNotificationBroadcast(PlaybackServiceInterface.NOTIFICATION_TYPE_PLAYBACK_END, 0);
|
||||
} else {
|
||||
sendNotificationBroadcast(NOTIFICATION_TYPE_RELOAD,
|
||||
isCasting ? EXTRA_CODE_CAST :
|
||||
(mediaType == MediaType.VIDEO) ? EXTRA_CODE_VIDEO : EXTRA_CODE_AUDIO);
|
||||
sendNotificationBroadcast(PlaybackServiceInterface.NOTIFICATION_TYPE_RELOAD,
|
||||
isCasting ? PlaybackServiceInterface.EXTRA_CODE_CAST :
|
||||
(mediaType == MediaType.VIDEO) ? PlaybackServiceInterface.EXTRA_CODE_VIDEO :
|
||||
PlaybackServiceInterface.EXTRA_CODE_AUDIO);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1114,9 +1085,9 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
||||
}
|
||||
|
||||
private void sendNotificationBroadcast(int type, int code) {
|
||||
Intent intent = new Intent(ACTION_PLAYER_NOTIFICATION);
|
||||
intent.putExtra(EXTRA_NOTIFICATION_TYPE, type);
|
||||
intent.putExtra(EXTRA_NOTIFICATION_CODE, code);
|
||||
Intent intent = new Intent(PlaybackServiceInterface.ACTION_PLAYER_NOTIFICATION);
|
||||
intent.putExtra(PlaybackServiceInterface.EXTRA_NOTIFICATION_TYPE, type);
|
||||
intent.putExtra(PlaybackServiceInterface.EXTRA_NOTIFICATION_CODE, code);
|
||||
intent.setPackage(getPackageName());
|
||||
sendBroadcast(intent);
|
||||
}
|
||||
@ -1521,7 +1492,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (TextUtils.equals(intent.getAction(), ACTION_SHUTDOWN_PLAYBACK_SERVICE)) {
|
||||
if (TextUtils.equals(intent.getAction(), PlaybackServiceInterface.ACTION_SHUTDOWN_PLAYBACK_SERVICE)) {
|
||||
EventBus.getDefault().post(new PlaybackServiceEvent(PlaybackServiceEvent.Action.SERVICE_SHUT_DOWN));
|
||||
stateManager.stopService();
|
||||
}
|
||||
|
@ -0,0 +1,20 @@
|
||||
package de.danoeh.antennapod.core.service.playback;
|
||||
|
||||
public abstract class PlaybackServiceInterface {
|
||||
public static final String EXTRA_PLAYABLE = "PlaybackService.PlayableExtra";
|
||||
public static final String EXTRA_ALLOW_STREAM_THIS_TIME = "extra.de.danoeh.antennapod.core.service.allowStream";
|
||||
public static final String EXTRA_ALLOW_STREAM_ALWAYS = "extra.de.danoeh.antennapod.core.service.allowStreamAlways";
|
||||
|
||||
public static final String ACTION_PLAYER_NOTIFICATION
|
||||
= "action.de.danoeh.antennapod.core.service.playerNotification";
|
||||
public static final String EXTRA_NOTIFICATION_CODE = "extra.de.danoeh.antennapod.core.service.notificationCode";
|
||||
public static final String EXTRA_NOTIFICATION_TYPE = "extra.de.danoeh.antennapod.core.service.notificationType";
|
||||
public static final int NOTIFICATION_TYPE_PLAYBACK_END = 7;
|
||||
public static final int NOTIFICATION_TYPE_RELOAD = 3;
|
||||
public static final int EXTRA_CODE_AUDIO = 1; // Used in NOTIFICATION_TYPE_RELOAD
|
||||
public static final int EXTRA_CODE_VIDEO = 2;
|
||||
public static final int EXTRA_CODE_CAST = 3;
|
||||
|
||||
public static final String ACTION_SHUTDOWN_PLAYBACK_SERVICE
|
||||
= "action.de.danoeh.antennapod.core.service.actionShutdownPlaybackService";
|
||||
}
|
@ -9,6 +9,7 @@ import androidx.annotation.Nullable;
|
||||
import androidx.core.app.NotificationManagerCompat;
|
||||
|
||||
import de.danoeh.antennapod.core.service.download.DownloadService;
|
||||
import de.danoeh.antennapod.core.service.playback.PlaybackServiceInterface;
|
||||
import de.danoeh.antennapod.storage.database.PodDBAdapter;
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
@ -36,7 +37,6 @@ import de.danoeh.antennapod.core.feed.FeedEvent;
|
||||
import de.danoeh.antennapod.core.preferences.PlaybackPreferences;
|
||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||
import de.danoeh.antennapod.model.download.DownloadStatus;
|
||||
import de.danoeh.antennapod.core.service.playback.PlaybackService;
|
||||
import de.danoeh.antennapod.core.sync.queue.SynchronizationQueueSink;
|
||||
import de.danoeh.antennapod.core.util.FeedItemPermutors;
|
||||
import de.danoeh.antennapod.core.util.IntentUtils;
|
||||
@ -128,7 +128,7 @@ public class DBWriter {
|
||||
|
||||
if (media.getId() == PlaybackPreferences.getCurrentlyPlayingFeedMediaId()) {
|
||||
PlaybackPreferences.writeNoMediaPlaying();
|
||||
IntentUtils.sendLocalBroadcast(context, PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE);
|
||||
IntentUtils.sendLocalBroadcast(context, PlaybackServiceInterface.ACTION_SHUTDOWN_PLAYBACK_SERVICE);
|
||||
|
||||
NotificationManagerCompat nm = NotificationManagerCompat.from(context);
|
||||
nm.cancel(R.id.notification_playing);
|
||||
@ -201,7 +201,7 @@ public class DBWriter {
|
||||
if (item.getMedia().getId() == PlaybackPreferences.getCurrentlyPlayingFeedMediaId()) {
|
||||
// Applies to both downloaded and streamed media
|
||||
PlaybackPreferences.writeNoMediaPlaying();
|
||||
IntentUtils.sendLocalBroadcast(context, PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE);
|
||||
IntentUtils.sendLocalBroadcast(context, PlaybackServiceInterface.ACTION_SHUTDOWN_PLAYBACK_SERVICE);
|
||||
}
|
||||
if (item.getMedia().isDownloaded()) {
|
||||
deleteFeedMediaSynchronous(context, item.getMedia());
|
||||
|
@ -4,8 +4,6 @@ import androidx.annotation.NonNull;
|
||||
|
||||
import de.danoeh.antennapod.model.feed.FeedMedia;
|
||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||
import de.danoeh.antennapod.core.preferences.PlaybackPreferences;
|
||||
import de.danoeh.antennapod.core.service.playback.PlaybackService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -12,6 +12,7 @@ import android.util.Log;
|
||||
import android.util.Pair;
|
||||
import android.view.SurfaceHolder;
|
||||
import androidx.annotation.NonNull;
|
||||
import de.danoeh.antennapod.core.service.playback.PlaybackServiceInterface;
|
||||
import de.danoeh.antennapod.core.storage.DBWriter;
|
||||
import de.danoeh.antennapod.event.playback.PlaybackPositionEvent;
|
||||
import de.danoeh.antennapod.model.feed.FeedMedia;
|
||||
@ -84,10 +85,9 @@ public abstract class PlaybackController {
|
||||
initialized = true;
|
||||
|
||||
activity.registerReceiver(statusUpdate, new IntentFilter(
|
||||
PlaybackService.ACTION_PLAYER_STATUS_CHANGED));
|
||||
|
||||
PlaybackService.ACTION_PLAYER_STATUS_CHANGED));
|
||||
activity.registerReceiver(notificationReceiver, new IntentFilter(
|
||||
PlaybackService.ACTION_PLAYER_NOTIFICATION));
|
||||
PlaybackServiceInterface.ACTION_PLAYER_NOTIFICATION));
|
||||
|
||||
if (!released) {
|
||||
bindToService();
|
||||
@ -202,14 +202,14 @@ public abstract class PlaybackController {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
int type = intent.getIntExtra(PlaybackService.EXTRA_NOTIFICATION_TYPE, -1);
|
||||
int code = intent.getIntExtra(PlaybackService.EXTRA_NOTIFICATION_CODE, -1);
|
||||
int type = intent.getIntExtra(PlaybackServiceInterface.EXTRA_NOTIFICATION_TYPE, -1);
|
||||
int code = intent.getIntExtra(PlaybackServiceInterface.EXTRA_NOTIFICATION_CODE, -1);
|
||||
if (code == -1 || type == -1) {
|
||||
Log.d(TAG, "Bad arguments. Won't handle intent");
|
||||
return;
|
||||
}
|
||||
switch (type) {
|
||||
case PlaybackService.NOTIFICATION_TYPE_RELOAD:
|
||||
case PlaybackServiceInterface.NOTIFICATION_TYPE_RELOAD:
|
||||
if (playbackService == null && PlaybackService.isRunning) {
|
||||
bindToService();
|
||||
return;
|
||||
@ -217,7 +217,7 @@ public abstract class PlaybackController {
|
||||
mediaInfoLoaded = false;
|
||||
queryService();
|
||||
break;
|
||||
case PlaybackService.NOTIFICATION_TYPE_PLAYBACK_END:
|
||||
case PlaybackServiceInterface.NOTIFICATION_TYPE_PLAYBACK_END:
|
||||
onPlaybackEnd();
|
||||
break;
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import android.os.Parcelable;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import de.danoeh.antennapod.core.service.playback.PlaybackService;
|
||||
import de.danoeh.antennapod.core.service.playback.PlaybackServiceInterface;
|
||||
import de.danoeh.antennapod.model.playback.Playable;
|
||||
|
||||
public class PlaybackServiceStarter {
|
||||
@ -34,8 +35,8 @@ public class PlaybackServiceStarter {
|
||||
|
||||
public Intent getIntent() {
|
||||
Intent launchIntent = new Intent(context, PlaybackService.class);
|
||||
launchIntent.putExtra(PlaybackService.EXTRA_PLAYABLE, (Parcelable) media);
|
||||
launchIntent.putExtra(PlaybackService.EXTRA_ALLOW_STREAM_THIS_TIME, shouldStreamThisTime);
|
||||
launchIntent.putExtra(PlaybackServiceInterface.EXTRA_PLAYABLE, (Parcelable) media);
|
||||
launchIntent.putExtra(PlaybackServiceInterface.EXTRA_ALLOW_STREAM_THIS_TIME, shouldStreamThisTime);
|
||||
return launchIntent;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user