Release GPS2Audio v2.5.44 POI category fix
This commit is contained in:
@@ -3,6 +3,7 @@ package de.waypointaudio.service
|
||||
import android.content.Context
|
||||
import android.media.MediaPlayer
|
||||
import android.net.Uri
|
||||
import android.os.PowerManager
|
||||
import android.util.Log
|
||||
|
||||
/**
|
||||
@@ -22,6 +23,8 @@ class ManualAudioPlayer {
|
||||
|
||||
private var mediaPlayer: MediaPlayer? = null
|
||||
private var currentUri: String? = null
|
||||
/** v2.5.10 — App-Context für FGS-Stop aus releasePlayer/stop heraus. */
|
||||
private var lastAppContext: Context? = null
|
||||
|
||||
/**
|
||||
* Whether the player is currently in single-item mode.
|
||||
@@ -42,6 +45,24 @@ class ManualAudioPlayer {
|
||||
val hasTrack: Boolean
|
||||
get() = mediaPlayer != null
|
||||
|
||||
/**
|
||||
* v2.5.14 — Aktuelle Wiedergabeposition in Millisekunden. Liefert 0, wenn
|
||||
* kein Player geladen ist oder die Position (noch) nicht ermittelbar ist.
|
||||
*/
|
||||
fun getCurrentPositionMs(): Long = runCatching {
|
||||
mediaPlayer?.currentPosition?.toLong() ?: 0L
|
||||
}.getOrDefault(0L)
|
||||
|
||||
/**
|
||||
* v2.5.14 — Gesamtdauer der aktuell geladenen Datei in Millisekunden.
|
||||
* Liefert -1, wenn unbekannt (Streams, noch nicht geprepared, oder bereits
|
||||
* freigegeben). UI-Layer sollte einen `--:--`-Fallback rendern.
|
||||
*/
|
||||
fun getDurationMs(): Long = runCatching {
|
||||
val d = mediaPlayer?.duration ?: -1
|
||||
if (d <= 0) -1L else d.toLong()
|
||||
}.getOrDefault(-1L)
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Playlist mode (existing global manual player bar)
|
||||
// -------------------------------------------------------------------------
|
||||
@@ -169,6 +190,9 @@ class ManualAudioPlayer {
|
||||
mediaPlayer = MediaPlayer().apply {
|
||||
// Grant URI permission for content:// URIs originating from SAF
|
||||
setDataSource(context, uri)
|
||||
// v2.5.10 — MediaPlayer-eigener WakeLock als zweites Sicherheitsnetz.
|
||||
// Greift zusätzlich zum PARTIAL_WAKE_LOCK des ManualPlaybackService.
|
||||
setWakeMode(context.applicationContext, PowerManager.PARTIAL_WAKE_LOCK)
|
||||
prepare()
|
||||
start()
|
||||
setOnCompletionListener {
|
||||
@@ -183,12 +207,43 @@ class ManualAudioPlayer {
|
||||
}
|
||||
}
|
||||
currentUri = soundUri
|
||||
lastAppContext = context.applicationContext
|
||||
// v2.5.10 — Foreground-Service als Lebenshalter starten, sobald
|
||||
// tatsächlich Wiedergabe läuft. Updates der Notification-Texte
|
||||
// erfolgen aus dem ViewModel über setMeta/start.
|
||||
ManualPlaybackService.start(
|
||||
context.applicationContext,
|
||||
title = pendingTitle.takeIf { it.isNotBlank() } ?: "GPS2Audio",
|
||||
tour = pendingTour
|
||||
)
|
||||
}.onFailure { e ->
|
||||
Log.e(TAG, "Fehler beim Abspielen von $soundUri", e)
|
||||
releasePlayer()
|
||||
}
|
||||
}
|
||||
|
||||
// v2.5.10 — Optionale Anzeige-Metadaten für die Foreground-Notification.
|
||||
// Die ViewModel-Schicht setzt diese vor dem nächsten play()-Aufruf.
|
||||
@Volatile private var pendingTitle: String = ""
|
||||
@Volatile private var pendingTour: String = ""
|
||||
|
||||
/** Setzt Titel/Tour, die beim nächsten Start als Notification-Text erscheinen. */
|
||||
fun setNextNotificationMeta(title: String?, tour: String?) {
|
||||
pendingTitle = title.orEmpty()
|
||||
pendingTour = tour.orEmpty()
|
||||
}
|
||||
|
||||
/** Aktualisiert die Notification eines bereits laufenden ManualPlaybackService. */
|
||||
fun updateNotificationMeta(context: Context, title: String?, tour: String?) {
|
||||
pendingTitle = title.orEmpty()
|
||||
pendingTour = tour.orEmpty()
|
||||
if (mediaPlayer != null) {
|
||||
ManualPlaybackService.updateMeta(
|
||||
context.applicationContext, title, tour
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Pause / Stop / Release
|
||||
// -------------------------------------------------------------------------
|
||||
@@ -206,6 +261,21 @@ class ManualAudioPlayer {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resume a previously paused playback at the same position. Used by the
|
||||
* PTT interruption flow to bring back a waypoint audio that was paused
|
||||
* because the user pressed PTT. If the MediaPlayer has been released or is
|
||||
* already playing, this is a no-op.
|
||||
*/
|
||||
fun resume() {
|
||||
runCatching {
|
||||
val mp = mediaPlayer ?: return
|
||||
if (!mp.isPlaying) mp.start()
|
||||
}.onFailure { e ->
|
||||
Log.e(TAG, "Fehler beim Fortsetzen", e)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop and release resources. Clears current track and single-mode state.
|
||||
*/
|
||||
@@ -231,6 +301,9 @@ class ManualAudioPlayer {
|
||||
currentUri = null
|
||||
isSingleMode = false
|
||||
singleWaypointId = null
|
||||
// v2.5.10 — Foreground-Service stoppen, sobald keine manuelle
|
||||
// Wiedergabe mehr existiert. WakeLock wird vom Service freigegeben.
|
||||
lastAppContext?.let { ctx -> ManualPlaybackService.stop(ctx) }
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
Reference in New Issue
Block a user