fix: grid minmax, media polling fallback, content webview layout, swipe timeout
This commit is contained in:
@@ -8,6 +8,8 @@ import android.media.MediaMetadata
|
||||
import android.media.session.MediaController
|
||||
import android.media.session.MediaSessionManager
|
||||
import android.media.session.PlaybackState
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.util.Base64
|
||||
import android.util.Log
|
||||
import java.io.ByteArrayOutputStream
|
||||
@@ -33,6 +35,18 @@ class MediaSessionSource(context: Context) {
|
||||
private var registered = false
|
||||
private val controllers = mutableListOf<MediaController>()
|
||||
|
||||
// 轮询兜底:registerCallback 在部分场景不触发(如歌词实时更新时),
|
||||
// 每 2 秒主动拉取一次进度/状态,保证进度条与信息持续更新
|
||||
// Polling fallback: registerCallback doesn't always fire (e.g. live lyrics),
|
||||
// so actively pull progress/state every 2s to keep the bar and info fresh
|
||||
private val pollHandler = Handler(Looper.getMainLooper())
|
||||
private val pollRunnable = object : Runnable {
|
||||
override fun run() {
|
||||
refresh()
|
||||
pollHandler.postDelayed(this, 2000)
|
||||
}
|
||||
}
|
||||
|
||||
// 元数据/播放状态变化回调:切歌、暂停/播放时实时推送
|
||||
// Metadata/playback-state change callback: push in real time on track switch or play/pause
|
||||
private val mediaCallback = object : MediaController.Callback() {
|
||||
@@ -69,6 +83,9 @@ class MediaSessionSource(context: Context) {
|
||||
Log.d(TAG, "start: media session listener registered")
|
||||
updateControllers(msm.getActiveSessions(listenerComponent))
|
||||
pushCurrent()
|
||||
// 启动轮询兜底
|
||||
pollHandler.removeCallbacks(pollRunnable)
|
||||
pollHandler.postDelayed(pollRunnable, 2000)
|
||||
} catch (e: SecurityException) {
|
||||
// 未授权「通知使用权」时系统抛 SecurityException:媒体监听降级为不可用,不崩溃。
|
||||
// MediaSessionService throws SecurityException without notification access;
|
||||
@@ -87,6 +104,7 @@ class MediaSessionSource(context: Context) {
|
||||
Log.d(TAG, "stop: media session listener removed")
|
||||
}
|
||||
unregisterCallbacks()
|
||||
pollHandler.removeCallbacks(pollRunnable)
|
||||
callback = null
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user