fix: player bar instant update + stop music on app close
player.js: move NSBridge.setQueue() into requestAnimationFrame so the updatePlayerUI DOM changes are committed and painted before the blocking @JavascriptInterface call. setQueue serializes a large JSON payload and blocks the JS/Blink main thread while Java parses it — deferring it one frame ensures the player bar visually updates immediately on tap. MusicService: onTaskRemoved now calls player.stop() + stopSelf() so swiping the app from recents stops playback instead of leaving it running in the background. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
7084fc4118
commit
8e752fa892
2 files changed
+12
-5
No files matched your search
@@ -101,8 +101,8 @@ class MusicService : MediaSessionService() {
|
|||||||
override fun onGetSession(controllerInfo: MediaSession.ControllerInfo) = mediaSession
|
override fun onGetSession(controllerInfo: MediaSession.ControllerInfo) = mediaSession
|
||||||
|
|
||||||
override fun onTaskRemoved(rootIntent: Intent?) {
|
override fun onTaskRemoved(rootIntent: Intent?) {
|
||||||
// Keep playing when swiped from recents; only stop if idle/empty
|
player.stop()
|
||||||
if (!player.playWhenReady || player.mediaItemCount == 0) stopSelf()
|
stopSelf()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
|
|||||||
+10
-3
@@ -244,9 +244,16 @@ export function playQueue(songs, startIdx) {
|
|||||||
const s = S.queue[S.qIdx];
|
const s = S.queue[S.qIdx];
|
||||||
if (s) { updatePlayerUI(s, true); onNpSongChange(s.id); }
|
if (s) { updatePlayerUI(s, true); onNpSongChange(s.id); }
|
||||||
renderQueue();
|
renderQueue();
|
||||||
try {
|
// Build the track list now (before rAF) while S.queue is current.
|
||||||
window.NSBridge.setQueue(JSON.stringify(buildTrackList()), startIdx, true);
|
const trackListJson = JSON.stringify(buildTrackList());
|
||||||
} catch (e) { console.warn('NSBridge.setQueue failed', e); }
|
// Defer the NSBridge call to AFTER the current render frame so the
|
||||||
|
// updatePlayerUI DOM changes are committed and visible before the
|
||||||
|
// @JavascriptInterface call (which blocks the JS thread while Java
|
||||||
|
// parses the JSON and creates MediaItems).
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
try { window.NSBridge.setQueue(trackListJson, startIdx, true); }
|
||||||
|
catch (e) { console.warn('NSBridge.setQueue failed', e); }
|
||||||
|
});
|
||||||
if (S.radioMode) fillRadioQueue();
|
if (S.radioMode) fillRadioQueue();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user