feat: server-side romaji overrides (shared list); preload ExoPlayer from SharedPreferences on cold start
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
b924f01b2a
commit
36a0b38eca
9 files changed
+116
-14
No files matched your search
@@ -135,6 +135,19 @@ class MusicService : MediaSessionService() {
|
||||
.build()
|
||||
|
||||
player.addListener(PlayerListener())
|
||||
|
||||
// Pre-warm: load the last played track immediately so ExoPlayer starts
|
||||
// buffering while the WebView is still loading — reduces startup latency.
|
||||
try {
|
||||
val prefs = getSharedPreferences("ns_prefs", android.content.Context.MODE_PRIVATE)
|
||||
val trackJson = prefs.getString("last_played_track", null)
|
||||
if (!trackJson.isNullOrBlank()) {
|
||||
val track = Track.fromJson(org.json.JSONObject(trackJson))
|
||||
player.setMediaItem(track.toMediaItem())
|
||||
player.prepare()
|
||||
// No play() — wait for JS to decide whether to auto-play
|
||||
}
|
||||
} catch (_: Exception) {}
|
||||
}
|
||||
|
||||
override fun onGetSession(controllerInfo: MediaSession.ControllerInfo) = mediaSession
|
||||
|
||||
@@ -134,6 +134,21 @@ class WebBridge(private val controllerProvider: () -> MediaController?) {
|
||||
@JavascriptInterface
|
||||
fun getState(): String = stateSnapshot
|
||||
|
||||
// ─── Last played (persisted for startup preload) ──────────────────────────
|
||||
|
||||
// Called by JS whenever the current song changes — persists to SharedPreferences
|
||||
// so MusicService can start buffering immediately on next launch before JS loads.
|
||||
@JavascriptInterface
|
||||
fun saveLastPlayed(trackJson: String) {
|
||||
runOnMain {
|
||||
try {
|
||||
val ctx = MusicService.instance ?: return@runOnMain
|
||||
ctx.getSharedPreferences("ns_prefs", android.content.Context.MODE_PRIVATE)
|
||||
.edit().putString("last_played_track", trackJson).apply()
|
||||
} catch (_: Exception) {}
|
||||
}
|
||||
}
|
||||
|
||||
// ─── Overlay state (for back-button routing) ──────────────────────────────
|
||||
|
||||
// Written by WebView thread; read by UI thread — must be @Volatile.
|
||||
|
||||
Reference in new issue
Block a user