Flutter audio_service控制暂停/播放按钮不可见

kqqjbcuj  于 2023-06-30  发布在  Flutter
关注(0)|答案(1)|浏览(163)

我在我的应用程序中使用了audio_service和just_audio,这是源代码:

class PAudioHandler extends BaseAudioHandler{
    PAudioHandler() {
        // these are used to connect just_audio with audio_service
        // audio_service is needed to control the audio in the background
        bgPlayer.playbackEventStream.map(_transformEvent).pipe(playbackState);
        _listenForDurationChanges();
        _listenForCurrentSongIndexChanges();
        _listenForSequenceStateChanges();
      }
      PlaybackState _transformEvent(PlaybackEvent event) {
        return PlaybackState(
          controls: [
            bgPlayer.playing ? MediaControl.pause : MediaControl.play,
          ],
          androidCompactActionIndices: const [0, 1],
          processingState: const {
            ProcessingState.idle: AudioProcessingState.idle,
            ProcessingState.loading: AudioProcessingState.loading,
            ProcessingState.buffering: AudioProcessingState.buffering,
            ProcessingState.ready: AudioProcessingState.ready,
            ProcessingState.completed: AudioProcessingState.completed,
          }[bgPlayer.processingState]!,
          playing: true,
          updatePosition: bgPlayer.position,
          bufferedPosition: bgPlayer.bufferedPosition,
          speed: bgPlayer.speed,
          queueIndex: bgPlayer.currentIndex,
        );
      }
}

但是,媒体控件看起来像这样:

暂停和播放按钮不可见。关于这个bug还有两件有趣的事情。第一个是当我加上

systemActions: const {
          MediaAction.rewind,
        },


第二个有趣的事情是,即使播放/暂停按钮不可见,它们也是可以点击的:

灰色圆圈是我单击按钮时的圆圈。我在网上搜索了一下,但找不到有类似问题的人。

xwbd5t1u

xwbd5t1u1#

这是一个模拟器问题。在真实的设备上正常运行。

相关问题