start static method

  1. @Deprecated("Use init instead.")
Future<bool> start({
  1. required Function backgroundTaskEntrypoint,
  2. Map<String, dynamic>? params,
  3. String androidNotificationChannelName = "Notifications",
  4. String? androidNotificationChannelDescription,
  5. int? androidNotificationColor,
  6. String androidNotificationIcon = 'mipmap/ic_launcher',
  7. bool androidShowNotificationBadge = false,
  8. bool androidNotificationClickStartsActivity = true,
  9. bool androidNotificationOngoing = false,
  10. bool androidResumeOnClick = true,
  11. bool androidStopForegroundOnPause = false,
  12. bool androidEnableQueue = false,
  13. Size? androidArtDownscaleSize,
  14. Duration fastForwardInterval = const Duration(seconds: 10),
  15. Duration rewindInterval = const Duration(seconds: 10),
})

Deprecated. The new AudioHandler API now automatically starts the service when your implementation enters the playing state. Parameters can be passed via AudioHandler.customAction.

Implementation

@Deprecated("Use init instead.")
static Future<bool> start({
  required Function backgroundTaskEntrypoint,
  Map<String, dynamic>? params,
  String androidNotificationChannelName = "Notifications",
  String? androidNotificationChannelDescription,
  int? androidNotificationColor,
  String androidNotificationIcon = 'mipmap/ic_launcher',
  bool androidShowNotificationBadge = false,
  bool androidNotificationClickStartsActivity = true,
  bool androidNotificationOngoing = false,
  bool androidResumeOnClick = true,
  bool androidStopForegroundOnPause = false,
  bool androidEnableQueue = false,
  Size? androidArtDownscaleSize,
  Duration fastForwardInterval = const Duration(seconds: 10),
  Duration rewindInterval = const Duration(seconds: 10),
}) async {
  if (!androidEnableQueue) {
    // ignore: avoid_print
    print('NOTE: androidEnableQueue is always true from 0.18.0 onwards.');
  }
  if (_cacheManager != null && _handler.playbackState.hasValue) {
    if (_handler.playbackState.nvalue!.processingState !=
        AudioProcessingState.idle) {
      return false;
    }
  }

  AudioServiceBackground._startCompleter = Completer<BackgroundAudioTask>();
  backgroundTaskEntrypoint();
  final task = await AudioServiceBackground._startCompleter!.future;
  task._handler = _BackgroundAudioHandler();
  task._handler._task = task;
  AudioServiceBackground._startCompleter = null;

  if (_cacheManager == null) {
    _compatibilitySwitcher.inner = task._handler;
    await init(
      builder: () => _compatibilitySwitcher,
      config: AudioServiceConfig(
        androidResumeOnClick: androidResumeOnClick,
        androidNotificationChannelName: androidNotificationChannelName,
        androidNotificationChannelDescription:
            androidNotificationChannelDescription,
        notificationColor: androidNotificationColor != null
            ? Color(androidNotificationColor)
            : null,
        androidNotificationIcon: androidNotificationIcon,
        androidShowNotificationBadge: androidShowNotificationBadge,
        androidNotificationClickStartsActivity:
            androidNotificationClickStartsActivity,
        androidNotificationOngoing: androidNotificationOngoing,
        androidStopForegroundOnPause: androidStopForegroundOnPause,
        artDownscaleWidth: androidArtDownscaleSize?.width.round(),
        artDownscaleHeight: androidArtDownscaleSize?.height.round(),
        fastForwardInterval: fastForwardInterval,
        rewindInterval: rewindInterval,
      ),
    );
  } else {
    _compatibilitySwitcher.inner = task._handler;
  }
  await task.onStart(params);
  return true;
}