EARHORNMUSIC UPnP · Android TV · Phones · Android Auto · GNU/Linux
Release 0.5.0

EarhornMediaButtonReceiver.kt

Each line, with the release that last changed it.

0.5.01package dev.stave.playback
2
3import android.content.Intent
4import androidx.annotation.OptIn
5import androidx.media3.common.util.UnstableApi
6import androidx.media3.session.MediaButtonReceiver
7import dev.stave.data.QueuePersistenceStore
8
9/**
10 * Maintainer, 2026-10-29: headset / Bluetooth / car Play while Earhorn isn't
11 * running. Media3's receiver starts PlaybackService as a FOREGROUND service;
12 * if there is nothing to resume the player stays empty, no notification is
13 * posted, and Android kills the app with ForegroundServiceDidNotStartInTime.
14 * So only start the service when the last saved queue has something playable.
15 */
16@OptIn(UnstableApi::class)
17class EarhornMediaButtonReceiver : MediaButtonReceiver() {
18 override fun shouldStartForegroundService(intent: Intent): Boolean {
19 // shouldStartForegroundService gets no Context, and onReceive is final;
20 // the Application is always created before a receiver runs.
21 val app = dev.stave.EarhornApp.instance ?: return false
22 return QueuePersistenceStore.hasResumableQueue(app)
23 }
24}