setMediaLibrary method

  1. @override
Future<void> setMediaLibrary(
  1. MediaLibraryChildrenProvider? getChildren
)
override

Opts into a browsable media library (Android Auto and other Media3 browsers), whose items getChildren provides; null opts out. Has no effect on platforms without media browsers.

Implementation

@override
Future<void> setMediaLibrary(
    MediaLibraryChildrenProvider? getChildren) async {
  // Media browsers (Android Auto) exist on Android only.
  if (defaultTargetPlatform != TargetPlatform.android) return;
  _libraryChildren = getChildren;
  methodChannel
      .setMethodCallHandler(getChildren == null ? null : _onNativeCall);
  await methodChannel.invokeMethod(
      'setMediaLibraryEnabled', getChildren != null);
}