Skip to content

After a certain time, I want to turn off audio_service in the background with the android_alarm_manager plugin. #54533

@aydinfatih

Description

@aydinfatih

After a certain time, I want to turn off audio_service in the background with the android_alarm_manager plugin. How can I solve this problem?

When I try to do this, I get the following error.

[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: MissingPluginException(No implementation found for method stop on channel ryanheise.com/audioService)

My code is as follows.

FlatButton(
     onPressed: () async {
          await AndroidAlarmManager.oneShot(Duration(minutes: _minute.floor().toInt()), 0, backgroundCallback);
          Navigator.pop(context);
     },
     child: Text(S.of(context).set),
)
void backgroundCallback() async {
  AudioService.connect();
  AudioService.stop();
}

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  init();
  await sl<DotEnv>().load('.env');

  //get theme
  bool _isDarkTheme = await sl<SharedPreferenceHelper>().isDarkTheme() ?? false;

  if (Platform.isAndroid) {
    AndroidAlarmManager.initialize();
  }

  runApp(MainApp());
}
[√] Flutter (Channel stable, v1.12.13+hotfix.9, on Microsoft Windows [Version 10.0.18362.720], locale tr-TR)
    • Flutter version 1.12.13+hotfix.9 at D:\flutter
    • Framework revision f139b11009 (11 days ago), 2020-03-30 13:57:30 -0700
    • Engine revision af51afceb8
    • Dart version 2.7.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectd: stackoverflowGood question for Stack Overflowp: android_alarm_managerThe Android background execution pluginpackageflutter/packages repository. See also p: labels.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions