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

Flutter audio_service播放直播时如何隐藏锁屏控制区的进度条

解决方法

你遇到的问题是仅配置systemActions不足以控制系统锁屏进度条的显示,还需要补充两个核心配置:

  1. 标记当前播放内容为直播流
    在你更新PlaybackState的代码里新增isLive: true参数,系统识别到是直播内容后会默认隐藏进度条相关控件,修改后的代码参考:
playbackState.add(playbackState.value.copyWith(
            controls: [
              if (playing) MediaControl.pause else MediaControl.play,
            ],
            systemActions: {
              // 确认这里不要添加MediaAction.seek,不需要回放的话MediaAction.rewind也可以移除
              MediaAction.rewind,
            },
            processingState: const {
              ProcessingState.idle: AudioProcessingState.idle,
              ProcessingState.loading: AudioProcessingState.loading,
              ProcessingState.buffering: AudioProcessingState.buffering,
              ProcessingState.ready: AudioProcessingState.ready,
              ProcessingState.completed: AudioProcessingState.completed,
            }[_audioPlayer.processingState]!,
            playing: playing,
            updatePosition: Duration.zero,
            bufferedPosition: Duration.zero,
            speed: _audioPlayer.speed,
            // 新增这一行标记为直播内容
            isLive: true,
          ));
  1. 清空MediaItem的时长配置
    检查你构造MediaItem的代码,不要给duration参数赋值,或者显式设为null/Duration.zero。只要MediaItem携带非零时长,即使没有seek权限,部分系统版本还是会强制渲染进度条。
    如果是搭配just_audio使用,还要确保你的直播流AudioSource没有被播放器解析出固定时长,必要时可以自定义AudioSource覆盖duration的返回值为null。
  2. 特殊系统适配
    针对Android 12+及部分国产定制ROM如果还有进度条显示,可以额外移除所有和进度跳转相关的systemAction,包括你现在配置的MediaAction.rewind,同时确认没有配置队列跳转类的控制项。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.01 15:57:02