populateMediaSources method

void populateMediaSources()

Populate maps for media sources at startup to optimise performance.

Implementation

void populateMediaSources() async {
  /// A list of media sources that the app will support at runtime.
  final Map<MediaType, List<MediaSource>> availableMediaSources = {
    PlayerMediaType.instance: [
      PlayerLocalMediaSource.instance,
      PlayerYoutubeSource.instance,
      PlayerNetworkStreamSource.instance
    ],
    ReaderMediaType.instance: [
      ReaderTtuSource.instance,
      ReaderMokuroSource.instance,
      ReaderBrowserSource.instance,
      ReaderLyricsSource.instance,
      ReaderChatgptSource.instance,
      ReaderClipboardSource.instance,
      ReaderWebsocketSource.instance,
    ],
    ViewerMediaType.instance: [
      ViewerCameraSource.instance,
    ],
    DictionaryMediaType.instance: [],
  };

  mediaSources = Map<MediaType, Map<String, MediaSource>>.unmodifiable(
    availableMediaSources.map(
      (type, sources) => MapEntry(
        type,
        Map<String, MediaSource>.unmodifiable(
          Map<String, MediaSource>.fromEntries(
            sources.map(
              (source) => MapEntry(source.uniqueKey, source),
            ),
          ),
        ),
      ),
    ),
  );
}