setPlaybackState method

void setPlaybackState(
  1. bool isPlaying,
  2. double positionSeconds
)

Inform the OS's background audio system about the playback state; used to set the progress bar in lockscreen/notification.

When using background audio, this should be called every time the playback starts/stops, or there is discontinuity in playback progress (i.e. a seek or loop restart). It should not be called regularly (i.e. do not call it every second).

Implementation

void setPlaybackState(bool isPlaying, double positionSeconds) async {
  try {
    await audioMethodChannel.invokeMethod<dynamic>(
        setPlaybackStateMethod, <String, dynamic>{
      playbackIsPlayingKey: isPlaying,
      playbackPositionSeconds: positionSeconds
    });
  } on PlatformException catch (e) {
    _logger.severe('setPlaybackState error, category: ', e);
  }
}