handleNativeMediaEventCallback method

void handleNativeMediaEventCallback(
  1. Map arguments
)

Handle the MethodCalls from the native implementation layer.

Implementation

void handleNativeMediaEventCallback(Map<dynamic, dynamic> arguments) {
  const Map<String, MediaActionType> stringToMediaActionType =
      <String, MediaActionType>{
    mediaPause: MediaActionType.pause,
    mediaPlay: MediaActionType.play,
    mediaPlayPause: MediaActionType.playPause,
    mediaStop: MediaActionType.stop,
    mediaNext: MediaActionType.next,
    mediaPrevious: MediaActionType.previous,
    mediaSeekForward: MediaActionType.seekForward,
    mediaSeekBackward: MediaActionType.seekBackward,
    mediaSeekTo: MediaActionType.seekTo,
    mediaSkipForward: MediaActionType.skipForward,
    mediaSkipBackward: MediaActionType.skipBackward,
    mediaCustom: MediaActionType.custom
  };

  final String? mediaEventTypeString = arguments[mediaEventTypeKey];
  if (mediaEventTypeString == null) {
    _logger
        .severe('[arguments] did not contain value for [mediaEventTypeKey]');
    return;
  }
  final MediaActionType? type = stringToMediaActionType[mediaEventTypeString];
  if (type == null) {
    _logger
        .severe('Unknown MediaActionType for string $mediaEventTypeString');
    return;
  }
  final MediaEvent event = MediaEvent(type,
      customEventId: arguments[mediaCustomEventIdKey],
      seekToPositionSeconds: arguments[mediaSeekToPositionSecondsKey],
      skipIntervalSeconds: arguments[mediaSkipIntervalSecondsKey]);
  for (final ValueChanged<MediaEvent> mediaEventListener
      in _mediaEventListeners) {
    mediaEventListener(event);
  }
}