init static method

Future<void> init({
  1. bool androidResumeOnClick = true,
  2. String? androidNotificationChannelId,
  3. String androidNotificationChannelName = 'Notifications',
  4. String? androidNotificationChannelDescription,
  5. Color? notificationColor,
  6. String androidNotificationIcon = 'mipmap/ic_launcher',
  7. bool androidShowNotificationBadge = false,
  8. bool androidNotificationClickStartsActivity = true,
  9. bool androidNotificationOngoing = false,
  10. bool androidStopForegroundOnPause = true,
  11. int? artDownscaleWidth,
  12. int? artDownscaleHeight,
  13. Duration fastForwardInterval = const Duration(seconds: 10),
  14. Duration rewindInterval = const Duration(seconds: 10),
  15. bool preloadArtwork = false,
  16. Map<String, dynamic>? androidBrowsableRootExtras,
})

Initialise just_audio for background playback. This should be called from your app's main method. e.g.:

Future<void> main() async {
  await JustAudioBackground.init(
    androidNotificationChannelId: 'com.ryanheise.bg_demo.channel.audio',
    androidNotificationChannelName: 'Audio playback',
    androidNotificationOngoing: true,
  );
  runApp(MyApp());
}

Each parameter controls a behaviour in audio_service. Consult audio_service's AudioServiceConfig API documentation for more information.

Implementation

static Future<void> init({
  bool androidResumeOnClick = true,
  String? androidNotificationChannelId,
  String androidNotificationChannelName = 'Notifications',
  String? androidNotificationChannelDescription,
  Color? notificationColor,
  String androidNotificationIcon = 'mipmap/ic_launcher',
  bool androidShowNotificationBadge = false,
  bool androidNotificationClickStartsActivity = true,
  bool androidNotificationOngoing = false,
  bool androidStopForegroundOnPause = true,
  int? artDownscaleWidth,
  int? artDownscaleHeight,
  Duration fastForwardInterval = const Duration(seconds: 10),
  Duration rewindInterval = const Duration(seconds: 10),
  bool preloadArtwork = false,
  Map<String, dynamic>? androidBrowsableRootExtras,
}) async {
  WidgetsFlutterBinding.ensureInitialized();
  await _JustAudioBackgroundPlugin.setup(
    androidResumeOnClick: androidResumeOnClick,
    androidNotificationChannelId: androidNotificationChannelId,
    androidNotificationChannelName: androidNotificationChannelName,
    androidNotificationChannelDescription:
        androidNotificationChannelDescription,
    notificationColor: notificationColor,
    androidNotificationIcon: androidNotificationIcon,
    androidShowNotificationBadge: androidShowNotificationBadge,
    androidNotificationClickStartsActivity:
        androidNotificationClickStartsActivity,
    androidNotificationOngoing: androidNotificationOngoing,
    androidStopForegroundOnPause: androidStopForegroundOnPause,
    artDownscaleWidth: artDownscaleWidth,
    artDownscaleHeight: artDownscaleHeight,
    fastForwardInterval: fastForwardInterval,
    rewindInterval: rewindInterval,
    preloadArtwork: preloadArtwork,
    androidBrowsableRootExtras: androidBrowsableRootExtras,
  );
}