init static method
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,
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,
);
}