feat: glass effect toggle, media refresh timing fix, page transition perf
This commit is contained in:
@@ -164,6 +164,10 @@ class MainActivity : Activity() {
|
||||
// Log when the main frame finishes loading, to help diagnose a black screen
|
||||
override fun onPageFinished(view: WebView?, url: String?) {
|
||||
Log.d(TAG, "onPageFinished: url=$url")
|
||||
// H5 就绪后重新拉取一次媒体,修复启动时推送早于页面渲染的时序问题
|
||||
// Re-pull media once H5 is ready: fixes the startup timing where the
|
||||
// media push happens before the page has rendered
|
||||
bridge.refreshMedia()
|
||||
}
|
||||
|
||||
// 主帧加载失败时展示错误页,避免白屏
|
||||
|
||||
@@ -68,6 +68,19 @@ class MediaSessionSource(context: Context) {
|
||||
callback = null
|
||||
}
|
||||
|
||||
// 主动拉取当前会话并回调(不重新注册监听),供 H5 页面就绪后刷新媒体卡
|
||||
// Actively pull the current session and notify (without re-registering), for
|
||||
// refreshing the media card once the H5 page is ready
|
||||
fun refresh() {
|
||||
val cb = callback ?: return
|
||||
try {
|
||||
val current = msm.getActiveSessions(listenerComponent).firstOrNull()
|
||||
notifyMedia(current, cb)
|
||||
} catch (e: SecurityException) {
|
||||
Log.w(TAG, "refresh: no notification access: ${e.message}")
|
||||
}
|
||||
}
|
||||
|
||||
// 从 controller 提取 metadata + playbackState 构造 MediaInfo 并回调
|
||||
// Build MediaInfo from the controller's metadata + playbackState and invoke the callback
|
||||
private fun notifyMedia(controller: MediaController?, cb: (MediaInfo?) -> Unit) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.util.Log
|
||||
import top.yeij.hearth.app.AppRepository
|
||||
import top.yeij.hearth.card.Card
|
||||
import top.yeij.hearth.card.CardRepository
|
||||
import top.yeij.hearth.media.MediaInfo
|
||||
import top.yeij.hearth.media.MediaSessionSource
|
||||
import top.yeij.hearth.webapp.Tab
|
||||
import top.yeij.hearth.webapp.WebApp
|
||||
@@ -283,15 +284,27 @@ class JsBridge(
|
||||
|
||||
// 注册媒体会话监听,回调推送给 H5(info 为 null 时推 "null")
|
||||
// Register media session listener; push callbacks to H5 (push "null" when info is null)
|
||||
private var mediaSourceRef: MediaSessionSource? = null
|
||||
|
||||
fun setMediaListener(source: MediaSessionSource, webView: android.webkit.WebView) {
|
||||
source.start { info ->
|
||||
webView.post {
|
||||
val json = info?.toJson() ?: "null"
|
||||
webView.evaluateJavascript(
|
||||
"window.HearthEvents && window.HearthEvents.mediaSessionChanged($json);",
|
||||
null
|
||||
)
|
||||
}
|
||||
mediaSourceRef = source
|
||||
source.start { info -> pushMedia(info, webView) }
|
||||
}
|
||||
|
||||
// H5 页面就绪后重新拉取一次媒体:修复启动时推送早于页面渲染的时序问题
|
||||
// Re-pull media once the H5 page is ready: fixes the startup timing where the
|
||||
// push happens before the page has rendered
|
||||
fun refreshMedia() {
|
||||
mediaSourceRef?.refresh()
|
||||
}
|
||||
|
||||
private fun pushMedia(info: MediaInfo?, webView: android.webkit.WebView) {
|
||||
webView.post {
|
||||
val json = info?.toJson() ?: "null"
|
||||
webView.evaluateJavascript(
|
||||
"window.HearthEvents && window.HearthEvents.mediaSessionChanged($json);",
|
||||
null
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user