fix(playback): 播放中不再向系统上报 idle,修复播放设备页显示未在播放
audio_service 把 idle 映射成 PlaybackState.STATE_NONE,之前用 duration>0 判断, 时长尚未解析出来时会一直上报 NONE。改为 playing || duration>0 即视为 ready。 设备验证(MEIZU 21 Pro / Android 16): 播放 -> state=PLAYING(3),暂停 -> state=PAUSED(2),不再出现 NONE(0)。 同时加固 device-check.ps1:确认进程真正退出后再抓冷启动日志,最多重试两次。
This commit is contained in:
@@ -116,9 +116,13 @@ class AudioPlayerHandler extends audio_service.BaseAudioHandler {
|
||||
|
||||
try {
|
||||
final controls = _buildControls(playing);
|
||||
// audio_service 侧映射:idle -> STATE_NONE,ready -> PLAYING/PAUSED。
|
||||
// 之前只按 duration>0 判断,直播流/时长未解析出来时会被系统判定为"未在播放"
|
||||
// (播放设备选择页、部分车机与耳机都会读到这个状态)。
|
||||
final prepared = playing || duration.inMilliseconds > 0;
|
||||
final state = audio_service.PlaybackState(
|
||||
controls: controls,
|
||||
processingState: duration.inMilliseconds > 0
|
||||
processingState: prepared
|
||||
? audio_service.AudioProcessingState.ready
|
||||
: audio_service.AudioProcessingState.idle,
|
||||
playing: playing,
|
||||
|
||||
+19
-10
@@ -72,22 +72,31 @@ Write-Ok '安装成功'
|
||||
|
||||
# ---------- 冷启动 ----------
|
||||
Write-Step '冷启动并抓取日志'
|
||||
& adb -s $DeviceId shell am force-stop $pkg | Out-Null
|
||||
& adb -s $DeviceId logcat -c
|
||||
& adb -s $DeviceId shell monkey -p $pkg -c android.intent.category.LAUNCHER 1 2>&1 | Out-Null
|
||||
Start-Sleep -Seconds $WaitSeconds
|
||||
& adb -s $DeviceId logcat -d -v time > (Join-Path $root 'build\device-check-last.log')
|
||||
|
||||
$logPath = Join-Path $root 'build\device-check-last.log'
|
||||
# 注意:PS 5.1 的 > 重定向写出的是 UTF-16LE(带 BOM),这里不要强制 utf8
|
||||
$log = Get-Content $logPath
|
||||
$text = $log -join "`n"
|
||||
$creates = 0
|
||||
# Flyme 有时不会立刻杀掉带前台服务的进程,导致抓不到启动日志:确认进程消失 + 最多重试两次
|
||||
for ($attempt = 1; $attempt -le 2; $attempt++) {
|
||||
& adb -s $DeviceId shell am force-stop $pkg | Out-Null
|
||||
$deadline = (Get-Date).AddSeconds(6)
|
||||
while ((& adb -s $DeviceId shell pidof $pkg) -and (Get-Date) -lt $deadline) {
|
||||
Start-Sleep -Milliseconds 300
|
||||
}
|
||||
& adb -s $DeviceId logcat -c
|
||||
& adb -s $DeviceId shell am start -W -n "$pkg/.MainActivity" 2>&1 | Out-Null
|
||||
Start-Sleep -Seconds $WaitSeconds
|
||||
& adb -s $DeviceId logcat -d -v time > $logPath
|
||||
# 注意:PS 5.1 的 > 重定向写出的是 UTF-16LE(带 BOM),读取时不要强制 utf8
|
||||
$log = Get-Content $logPath
|
||||
$text = $log -join "`n"
|
||||
$creates = ([regex]::Matches($text, '\[PlaybackService\] 单例创建')).Count
|
||||
if ($creates -ge 1) { break }
|
||||
Write-Host " (第 $attempt 次没抓到冷启动日志,进程可能没退干净,重试)" -ForegroundColor DarkYellow
|
||||
}
|
||||
|
||||
# ---------- 判定 ----------
|
||||
Write-Step '实例检查'
|
||||
$serviceIds = @([regex]::Matches($text, 'serviceId=(\d+)') | ForEach-Object { $_.Groups[1].Value } | Sort-Object -Unique)
|
||||
$players = @([regex]::Matches($text, 'Player 已创建.*?player=(\d+)') | ForEach-Object { $_.Groups[1].Value } | Sort-Object -Unique)
|
||||
$creates = ([regex]::Matches($text, '\[PlaybackService\] 单例创建')).Count
|
||||
|
||||
$failed = $false
|
||||
if ($creates -eq 1) { Write-Ok "PlaybackService 单例创建 x$creates" } else { Write-Bad "PlaybackService 单例创建 x$creates(应为 1)"; $failed = $true }
|
||||
|
||||
Reference in New Issue
Block a user