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

如何在Media3的PlayerNotificationManager中隐藏直播音频通知进度条?

关于PlayerNotificationManager直播音频通知隐藏进度条的解决方案

是的,完全可以通过自定义通知实现隐藏进度条的需求,以下是具体实现思路和步骤:

  • 自定义通知布局(推荐方案)
    默认的Media3通知布局包含进度相关控件,直播场景下不需要,最稳妥的方式是自定义一个不含进度条的通知布局:

    1. 新建XML布局文件(比如res/layout/custom_live_media_notification.xml),只保留你需要的元素(播放/暂停按钮、直播标题、主播名称等),移除进度条(ProgressBar)和时间显示控件。
    2. 初始化PlayerNotificationManager时,通过setCustomContentView和setCustomBigContentView替换默认布局:
      val playerNotificationManager = PlayerNotificationManager.Builder(context, LIVE_NOTIFICATION_ID, LIVE_CHANNEL_ID)
          .setMediaDescriptionAdapter(object : PlayerNotificationManager.MediaDescriptionAdapter {
              override fun getCurrentContentTitle(player: Player): CharSequence {
                  return "你的直播标题"
              }
      
              override fun createCurrentContentIntent(player: Player): PendingIntent? {
                  // 返回直播页面的跳转Intent
                  return null
              }
      
              override fun getCurrentContentText(player: Player): CharSequence? {
                  return "主播名称"
              }
      
              override fun getCurrentLargeIcon(player: Player, callback: PlayerNotificationManager.BitmapCallback): Bitmap? {
                  // 返回直播封面图标
                  return null
              }
          })
          .setCustomContentView(RemoteViews(context.packageName, R.layout.custom_live_media_notification))
          .setCustomBigContentView(RemoteViews(context.packageName, R.layout.custom_live_media_notification))
          .build()
      
    3. 如需绑定播放/暂停等按钮事件,可通过RemoteViews的setOnClickPendingIntent方法为自定义布局中的按钮设置点击逻辑。
  • 不推荐的替代方式
    如果你不想自定义完整布局,尝试通过反射找到默认布局中的进度条控件并设置为GONE,但这种方式风险较高——Media3的默认布局结构可能随版本更新变化,导致代码失效,因此不建议使用。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.13 12:40:55