Merge branch 'mediasession' of https://github.com/DDRBoxman/MPD
This commit is contained in:
@@ -16,11 +16,16 @@ import android.content.ServiceConnection;
|
||||
import android.media.AudioManager;
|
||||
import android.os.Build;
|
||||
import android.os.IBinder;
|
||||
import android.os.Looper;
|
||||
import android.os.PowerManager;
|
||||
import android.os.RemoteCallbackList;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.OptIn;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import androidx.media3.session.MediaSession;
|
||||
|
||||
import org.musicpd.data.LoggingRepository;
|
||||
import org.musicpd.ui.SettingsActivity;
|
||||
|
||||
@@ -51,6 +56,8 @@ public class Main extends Service implements Runnable {
|
||||
private boolean mPauseOnHeadphonesDisconnect = false;
|
||||
private PowerManager.WakeLock mWakelock = null;
|
||||
|
||||
private MediaSession mMediaSession = null;
|
||||
|
||||
@Inject
|
||||
LoggingRepository logging;
|
||||
|
||||
@@ -184,6 +191,7 @@ public class Main extends Service implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(markerClass = UnstableApi.class)
|
||||
private void start() {
|
||||
if (mThread != null)
|
||||
return;
|
||||
@@ -225,11 +233,16 @@ public class Main extends Service implements Runnable {
|
||||
mThread = new Thread(this);
|
||||
mThread.start();
|
||||
|
||||
MPDPlayer player = new MPDPlayer(Looper.getMainLooper());
|
||||
mMediaSession = new MediaSession.Builder(this, player).build();
|
||||
|
||||
startForeground(R.string.notification_title_mpd_running, notification);
|
||||
startService(new Intent(this, Main.class));
|
||||
}
|
||||
|
||||
private void stop() {
|
||||
mMediaSession.release();
|
||||
mMediaSession = null;
|
||||
if (mThread != null) {
|
||||
if (mThread.isAlive()) {
|
||||
synchronized (this) {
|
||||
|
||||
Reference in New Issue
Block a user