0

I am using package audio_service

Issue - when I use the audio service package and try to run the app it returns an error where firebase is initialized.

Error Log

If I do not use the audio service package, the app is working fine, meaning no error message related to firebase.

Firebase Initialization Code:

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  if (Firebase.apps.isEmpty) {
    await Firebase.initializeApp(
      options: DefaultFirebaseOptions.currentPlatform,
    ).then((value) {
      logger.i('Firebase Initialized:${value.options}');
    });
  }
  runApp(const MyApp());
}

If possible please guide me regarding this issue.

main() should get called once and firebase must initialize once.

vimuth
  • 5,064
  • 33
  • 79
  • 116

1 Answers1

1

Use this instead

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );
_audioHandler = await AudioService.init(
    builder: () => MyAudioHandler(),
    config: AudioServiceConfig(
      androidNotificationChannelId: 'com.mycompany.myapp.channel.audio',
      androidNotificationChannelName: 'Music playback',
    ),
  );
  runApp(MyApp());
}
MrShakila
  • 874
  • 1
  • 4
  • 19