New way to detect car mode to fix skip to next episode (#7442)
This commit is contained in:
parent
a0d9f2aa7e
commit
51f92e94eb
|
@ -1,8 +1,6 @@
|
|||
package de.danoeh.antennapod.playback.service.internal;
|
||||
|
||||
import android.app.UiModeManager;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.media.AudioManager;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
@ -10,6 +8,9 @@ import android.util.Log;
|
|||
import android.util.Pair;
|
||||
import android.view.SurfaceHolder;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.car.app.connection.CarConnection;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.media.AudioAttributesCompat;
|
||||
import androidx.media.AudioFocusRequestCompat;
|
||||
import androidx.media.AudioManagerCompat;
|
||||
|
@ -58,6 +59,9 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer {
|
|||
private final Handler audioFocusCanceller;
|
||||
private boolean isShutDown = false;
|
||||
private CountDownLatch seekLatch;
|
||||
private LiveData<Integer> androidAutoConnectionState;
|
||||
private boolean androidAutoConnected;
|
||||
private Observer<Integer> androidAutoConnectionObserver;
|
||||
|
||||
public LocalPSMP(@NonNull Context context,
|
||||
@NonNull PlaybackServiceMediaPlayer.PSMPCallback callback) {
|
||||
|
@ -71,6 +75,12 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer {
|
|||
mediaType = MediaType.UNKNOWN;
|
||||
videoSize = null;
|
||||
|
||||
androidAutoConnectionState = new CarConnection(context).getType();
|
||||
androidAutoConnectionObserver = connectionState -> {
|
||||
androidAutoConnected = connectionState == CarConnection.CONNECTION_TYPE_PROJECTION;
|
||||
};
|
||||
androidAutoConnectionState.observeForever(androidAutoConnectionObserver);
|
||||
|
||||
AudioAttributesCompat audioAttributes = new AudioAttributesCompat.Builder()
|
||||
.setUsage(AudioAttributesCompat.USAGE_MEDIA)
|
||||
.setContentType(AudioAttributesCompat.CONTENT_TYPE_SPEECH)
|
||||
|
@ -182,8 +192,8 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer {
|
|||
} else {
|
||||
throw new IOException("Unable to read local file " + media.getLocalFileUrl());
|
||||
}
|
||||
UiModeManager uiModeManager = (UiModeManager) context.getSystemService(Context.UI_MODE_SERVICE);
|
||||
if (uiModeManager.getCurrentModeType() != Configuration.UI_MODE_TYPE_CAR) {
|
||||
|
||||
if (!androidAutoConnected) {
|
||||
setPlayerStatus(PlayerStatus.INITIALIZED, media);
|
||||
}
|
||||
|
||||
|
@ -525,6 +535,7 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer {
|
|||
mediaPlayer = null;
|
||||
playerStatus = PlayerStatus.STOPPED;
|
||||
}
|
||||
androidAutoConnectionState.removeObserver(androidAutoConnectionObserver);
|
||||
isShutDown = true;
|
||||
abandonAudioFocus();
|
||||
releaseWifiLockIfNecessary();
|
||||
|
|
Loading…
Reference in New Issue