diff --git a/lib/services/audio_player_handler.dart b/lib/services/audio_player_handler.dart index a993daf..339da65 100644 --- a/lib/services/audio_player_handler.dart +++ b/lib/services/audio_player_handler.dart @@ -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, diff --git a/tools/device-check.ps1 b/tools/device-check.ps1 index dc68991..96eb07f 100644 --- a/tools/device-check.ps1 +++ b/tools/device-check.ps1 @@ -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 }