summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--playback/service/src/main/java/de/danoeh/antennapod/playback/service/PlaybackService.java28
1 files changed, 2 insertions, 26 deletions
diff --git a/playback/service/src/main/java/de/danoeh/antennapod/playback/service/PlaybackService.java b/playback/service/src/main/java/de/danoeh/antennapod/playback/service/PlaybackService.java
index 7d20124cf..0cf063138 100644
--- a/playback/service/src/main/java/de/danoeh/antennapod/playback/service/PlaybackService.java
+++ b/playback/service/src/main/java/de/danoeh/antennapod/playback/service/PlaybackService.java
@@ -238,8 +238,6 @@ public class PlaybackService extends MediaBrowserServiceCompat {
};
androidAutoConnectionState.observeForever(androidAutoConnectionObserver);
- ContextCompat.registerReceiver(this, autoStateUpdated,
- new IntentFilter("com.google.android.gms.car.media.STATUS"), ContextCompat.RECEIVER_EXPORTED);
ContextCompat.registerReceiver(this, shutdownReceiver,
new IntentFilter(PlaybackServiceInterface.ACTION_SHUTDOWN_PLAYBACK_SERVICE),
ContextCompat.RECEIVER_NOT_EXPORTED);
@@ -274,11 +272,11 @@ public class PlaybackService extends MediaBrowserServiceCompat {
PendingIntent.FLAG_UPDATE_CURRENT | (Build.VERSION.SDK_INT >= 31 ? PendingIntent.FLAG_MUTABLE : 0));
mediaSession = new MediaSessionCompat(getApplicationContext(), TAG, eventReceiver, buttonReceiverIntent);
- setSessionToken(mediaSession.getSessionToken());
mediaSession.setCallback(sessionCallback);
mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
recreateMediaPlayer();
mediaSession.setActive(true);
+ setSessionToken(mediaSession.getSessionToken());
}
void recreateMediaPlayer() {
@@ -298,6 +296,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
mediaPlayer.playMediaObject(media, !media.localFileAvailable(), wasPlaying, true);
}
isCasting = mediaPlayer.isCasting();
+ updateMediaSession(mediaPlayer.getPlayerStatus());
}
@Override
@@ -324,7 +323,6 @@ public class PlaybackService extends MediaBrowserServiceCompat {
mediaSession.release();
mediaSession = null;
}
- unregisterReceiver(autoStateUpdated);
unregisterReceiver(headsetDisconnected);
unregisterReceiver(shutdownReceiver);
unregisterReceiver(bluetoothStateUpdated);
@@ -1491,28 +1489,6 @@ public class PlaybackService extends MediaBrowserServiceCompat {
}
}
- private final BroadcastReceiver autoStateUpdated = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- String status = intent.getStringExtra("media_connection_status");
- boolean isConnectedToCar = "media_connected".equals(status);
- Log.d(TAG, "Received Auto Connection update: " + status);
- if (!isConnectedToCar) {
- Log.d(TAG, "Car was unplugged during playback.");
- } else {
- PlayerStatus playerStatus = mediaPlayer.getPlayerStatus();
- if (playerStatus == PlayerStatus.PAUSED || playerStatus == PlayerStatus.PREPARED) {
- mediaPlayer.resume();
- } else if (playerStatus == PlayerStatus.PREPARING) {
- mediaPlayer.setStartWhenPrepared(!mediaPlayer.isStartWhenPrepared());
- } else if (playerStatus == PlayerStatus.INITIALIZED) {
- mediaPlayer.setStartWhenPrepared(true);
- mediaPlayer.prepare();
- }
- }
- }
- };
-
/**
* Pauses playback when the headset is disconnected and the preference is
* set