feat: media session source and media card
This commit is contained in:
@@ -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.MediaSessionSource
|
||||
import top.yeij.hearth.webapp.WebApp
|
||||
import top.yeij.hearth.webapp.WebAppRepository
|
||||
|
||||
@@ -55,4 +56,18 @@ class JsBridge(
|
||||
Log.d("HearthBridge", "fetchCards: ${cards.size} cards")
|
||||
return gson.toJson(cards)
|
||||
}
|
||||
|
||||
// 注册媒体会话监听,回调推送给 H5(info 为 null 时推 "null")
|
||||
// Register media session listener; push callbacks to H5 (push "null" when info is 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
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user