Merged
fix(ohos): register AVSession play/pause commands as a pair; add skip controls to example #68
xileileiAdd on 23 hours ago
fix(ohos): register AVSession play/pause commands as a pair; add skip controls to example #68
Merged
Pull Request has been successfully merged by openharmony_ci.
(Thank you for xileilei's contribution.)23 hours ago Associated issue: fix(ohos): register AVSession play/pause commands as a pair; add skip controls to example
23 hours ago Associated issue: fix(ohos): register AVSession play/pause commands as a pair; add skip controls to example
23 hours ago Added label: AI检视中
xileilei
23 hours ago Comments:
23 hours ago Comments:
start build


openharmony_ci
23 hours ago Comments:
23 hours ago Comments:
感谢提交 Pull Requests!
Thanks for submitting a pull request.


23 hours ago Added label: dco检查成功
openharmony_ci
23 hours ago Comments:
23 hours ago Comments:
首次触发
门禁构建开始,包含静态检查、代码编译和测试【ftpc_all_3.35_dev测试, ftpc_all_3.35_dev编译】,预计在60分钟内完成,门禁结果会同步发送到注册邮箱。您可以通过如下链接跟踪门禁进展:http://dcp.openharmony.cn/workbench/cicd/detail/6b06a32464650f998bc04154/runlist


23 hours ago Modify description of pull request
8 event messages are collapsed here。 See more
22 hours ago Test passed
openharmony_ci
22 hours ago Comments:
22 hours ago Comments:
代码门禁通过
您可以通过如下链接查看门禁报告:http://dcp.openharmony.cn/workbench/cicd/detail/6b06a32464650f998bc04154/runlist
静态检查:
| # | check type | result | report |
|---|---|---|---|
| 1 | codeCheck | pass | >>> |
编译测试:
| # | Device | build result | test result | package |
|---|---|---|---|---|
| 1 | ftpc_all_3.35_dev | success | success | >>> |


4 hours ago Set hezySign as approver
4 hours ago Approval passed
56 minutes ago Set zzx89757 as approver
56 minutes ago Approval passed
56 minutes ago Added label: AI检视复核中
56 minutes ago Reset test status
cpf-manager
54 minutes ago Comments:
54 minutes ago Comments:
54 minutes ago Test passed
54 minutes ago Removed label: AI检视复核中
54 minutes ago Added label: AI检视复核通过
54 minutes ago Closed associated issue
54 minutes ago Merged pull request, merge node SHA: 9ff0f5d521ebf2255d8480fd87d00cb858ad1882
54 minutes ago Merged pull request, merge node SHA: 9ff0f5d521ebf2255d8480fd87d00cb858ad1882
变更描述
本 PR 修复
audio_service鸿蒙适配中 OHOS 播控中心播放/暂停单键在状态切换后失灵 的问题,并补齐 example 的上一曲/下一曲控制、修复收藏按钮点击丢失。核心原因是:OHOS 播控中心(AVSession)的播放/暂停是同一个按钮,由系统按其自身对播放状态的判断发送play或pause命令;而 Dart 侧惯用的if (playing) MediaControl.pause else MediaControl.play条件式 controls 每次广播只声明其中一个,导致每次播放切换后另一个命令未注册、单键点击无响应(真机复现:每次切换注册列表 del play / add pause,点击 no-op)。audio_service/ohos/src/main/ets/AudioService.ets,addCommandForAction):play/pause命令成对注册:声明MediaControl.play或MediaControl.pause任一个,即同时向 AVSession 注册play和pause,保证播控中心单键在任意状态下都可响应(playPause(9)原有的双命令映射保持不变)。audio_service/ohos/src/main/ets/AudioServicePlugin.ets,onToggleFavorite):toggleFavorite自定义动作的extras由原始 assetId 字符串改为 Map({ assetId: <id> },对齐 Android 端bundleToMap行为):Dart 侧customAction回调将 extras 强转为Map<String, dynamic>?,字符串载荷会转换失败,收藏点击被静默丢弃,从未到达 handler。audio_service/example/lib/main.dart):MediaControl.skipToPrevious/skipToNext(4 → 6 个控制按钮),handler 实现skipToNext/skipToPrevious(单曲 demo:seek 回起点后重新播放),使上一曲/下一曲按钮在 OHOS 播控中心/通知/锁屏上渲染并可响应;androidCompactActionIndices重排为[1, 2, 3]保持紧凑栏布局不变(OHOS 忽略该字段);stop()改为 await 后 seek 回起点,使下次play()从头播放。CHANGELOG.OpenHarmony.md):新增 3 条 Fixed 条目(均引用 !68);版本小节由0.18.18-ohos-1.0.1-2026.10更名为0.18.18-ohos-1.0.1-2026.11。影响范围:4 个文件(+58 / −11);插件 Dart 公开 API(
lib/)无变更;鸿蒙原生层仅调整 AVSession 命令注册策略与 extras 载荷格式。同一修复已移植 br_3.41_dev(!67)。变更类型
fix(缺陷修复;example 新增 skip 控制为缺陷修复配套的演示完善)
破坏性更新
本 PR 不包含破坏性变更。
插件 Dart 层 API 签名与调用方式不变(
lib/无改动)。鸿蒙原生层两处行为修复均是把原先失效的控件恢复可用(play/pause 单键失灵、收藏点击丢失),不存在依赖旧坏行为的应用;play/pause 成对注册与 !64 引入的按需注册(controls∪systemActions决定命令集)机制保持一致,只会使命令集更可用,不会隐藏任何已配置的功能。关联Issue
https://gitcode.com/CPF-Flutter/fluttertpc_audio_service/issues/74
相关历史 issue:[40](鸿蒙播控中心强制显示收藏/循环按钮,已由 !64 修复关闭)——本次
toggleFavoriteextras 修复是其收藏按钮链路的收尾:按钮已按systemActions显示,但点击此前无法到达 Dart handler。测试情况
测试步骤:
main入口):toggleFavorite正常到达 Dart 侧customActionhandler(extras 已为 Map)。main.dart/example_playlist.dart等各自带main()),真机验证时需确认运行的是本次修改的main入口(可经 hilog 的syncEventListeners: desired=[...]日志反推设备上实际运行的 handler)。assembleHar编译通过;插件 Dart 层(lib/)无改动,存量 Dart 单元测试(audio_service/test/unit)与 example 冒烟(integration_test/app_test.dart)不受本次改动影响。conditionalPlayControlEnablesBothPlayAndPause等)在 br_3.41_dev 的姊妹 MR !67 中补充。Changelog 条目
## 0.18.18-ohos-1.0.1-2026.11 ### Fixed * Register the AVSession `play` and `pause` commands as a pair: the media-control-center play/pause is a single button that sends either command according to its own view of the playback state, so declaring only `MediaControl.play` or `MediaControl.pause` (the canonical `if (playing) pause else play` conditional) left the button dead after each play toggle. Declaring either one now keeps both valid. ([!68](https://gitcode.com/CPF-Flutter/fluttertpc_audio_service/merge_requests/68)) * Declare `MediaControl.skipToPrevious` / `skipToNext` in the example's controls and implement `skipToNext` / `skipToPrevious` in the example handler, so the skip buttons render and respond on the OHOS media surfaces. ([!68](https://gitcode.com/CPF-Flutter/fluttertpc_audio_service/merge_requests/68)) * Send the `toggleFavorite` custom action's extras as a map (matching Android's `bundleToMap`) instead of the raw asset id string: the Dart-side `customAction` callback casts extras to `Map<String, dynamic>?`, so the string payload failed the cast and favorite taps never reached the handler. ([!68](https://gitcode.com/CPF-Flutter/fluttertpc_audio_service/merge_requests/68))单元测试:


集成测试:
