You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Google Assistant媒体应用搜索失效,onPlayFromSearch未调用求助

Google Assistant 搜索播放回调未触发问题

我按照《Google Assistant 与媒体应用》官方指南实现功能,但onPrepareFromSearch()或onPlayFromSearch()始终未被调用。使用DHU测试Google Assistant时,日志输出如下:

Unable to perform playFromMedia because the mediaId is missing from the MediaItem.
Could not execute playFromUri, playFromMediaId or playFromSearch

我的实现参考了UMP和VLC(二者均可正常运行),使用com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector。奇怪的是,通过media controller test app可以成功测试所有功能,包括按搜索播放、按媒体ID播放、按URI播放等;而且语音命令下媒体处于活跃状态时,暂停、播放、切歌等功能都正常,媒体会话也能被正常识别。

已确认助手设置未指定默认播放器,请问是否需要额外的特殊注册步骤?

相关代码片段

onGetRoot 实现

override fun onGetRoot(
    clientPackageName: String,
    clientUid: Int,
    rootHints: Bundle?
): BrowserRoot {
    val maximumRootChildLimit = rootHints?.getInt(
        MediaConstants.BROWSER_ROOT_HINTS_KEY_ROOT_CHILDREN_LIMIT,
        /* defaultValue= */ 4)
    val supportedRootChildFlags = rootHints?.getInt(
        MediaConstants.BROWSER_ROOT_HINTS_KEY_ROOT_CHILDREN_SUPPORTED_FLAGS,
        /* defaultValue= */ MediaBrowser.MediaItem.FLAG_BROWSABLE)

    val rootExtras = Bundle().apply {
        putBoolean(
            "android.media.browse.SEARCH_SUPPORTED",
            true
        )
    }

    return BrowserRoot(ALBUMS_ROOT, rootExtras)
}

Manifest 中的服务配置

<service
    android:name=".service.MediaPlaybackService"
    android:exported="true"
    android:enabled="true"
    tools:ignore="ExportedService"
    android:foregroundServiceType="mediaPlayback"
    <intent-filter>
        <action android:name="android.media.browse.MediaBrowserService" />
        <action android:name="android.intent.action.MEDIA_BUTTON" />
    </intent-filter>
</service>

内容的提问来源于stack exchange,提问作者Tim Begander

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.15 01:20:21