0

I use android_alarm_manager_plus 2.0.2 plugin in my project and on Call back I use A Function And I Play a Sound With assets_audio_player_3.0.6.

But I Faced with This Error

MissingPluginException(No implementation found for method stop on channel assets_audio_player)
MissingPluginException(No implementation found for method open on channel assets_audio_player)
[ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: MissingPluginException(No implementation found for method open on channel assets_audio_player)

this Error reported on this Places But I cant Find Any solutoin

MissingPluginException When Using Plugins in Flutter Alarm Manager Callbacks

Flutter-AssetsAudioPlayer/issues/523

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 2.5.2, on Microsoft Windows [Version 10.0.19043.1237], locale en-US)
[!] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    ! Some Android licenses not accepted.  To resolve this, run: flutter doctor --android-licenses
[√] Chrome - develop for the web
[√] Android Studio (version 4.2)
[√] Connected device (3 available)

this code produce this Error

import 'package:android_alarm_manager_plus/android_alarm_manager_plus.dart';
import 'package:assets_audio_player/assets_audio_player.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

void printHello() async{
  final DateTime now = DateTime.now();
  print("[$now] Hello, world! function='$printHello'");

  ///play audio
  AssetsAudioPlayer assetsAudioPlayer =
  AssetsAudioPlayer.withId("App_ID");

  var audio = Audio(
    "assets/audios/music.mp3",
  );

  assetsAudioPlayer.open(audio,
      autoStart: true,
      showNotification: true,
  );
}


main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await AndroidAlarmManager.initialize();
  runApp(MyApp());
  await AndroidAlarmManager.oneShotAt(DateTime.now().add(Duration(seconds: 15)), 123456789, printHello);
}


class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Welcome to Flutter',
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Welcome to Flutter'),
        ),
        body: const Center(
          child: Text('Hello World'),
        ),
      ),
    );
  }
}

Result

[2021-10-11 13:35:27.441400] Hello, world! function='Closure: () => void from Function 'printHello': static.'
 MissingPluginException(No implementation found for method stop on channel assets_audio_player)
 MissingPluginException(No implementation found for method open on channel assets_audio_player)
 [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: MissingPluginException(No implementation found for method open on channel assets_audio_player)

Sajjad
  • 2,593
  • 16
  • 26
  • try `flutter clean` and then run again, or you can run which will download all your packages again `flutter pub cache repair` may it will solve your problem – Ruchit Oct 15 '21 at 10:15
  • try gradlew clean and gradlew build from the android folder. I think you need to sync or build the android project first. Then try again in the flutter project. – Meet Prajapati Oct 18 '21 at 03:35
  • did you solve the problem? – ch271828n Oct 18 '21 at 13:02
  • Hey @mohandesR . I just saw in flutter doctor some android licences are not accepted. Just run ```flutter doctor --android-licenses``` and the licenses. If this does not help let me know. – Shahryar Rafique Oct 19 '21 at 00:13
  • @ch271828n no I can't find any solution yet. – Sajjad Oct 19 '21 at 05:10
  • @ShahryarRafique Thank you. but its not solve my problem. – Sajjad Oct 19 '21 at 05:35
  • @mohandesR have you tried local_notification package. because it support both the notification schedule daily basis and also other time duration in the app and also the sound also you can change the sound you like. If you are into this I will answer the question. – Shahryar Rafique Oct 20 '21 at 13:33

2 Answers2

1

For anyone finding this: I'm pretty sure that that's a bug in the assert_audio_player library: At this point it does not play well with multiple isolates (which happens when you try to do stuff in the background).

I've documented my findings in the plugin's repository:

https://github.com/florent37/Flutter-AssetsAudioPlayer/issues/523

Hoperfully, it will be fixed by the author.

0

You need to move the three variables into the main method. something like this:

void printHello() async {
  final DateTime now = DateTime.now();
  print("[$now] Hello, world! function='$printHello'");
}

main() async {
  WidgetsFlutterBinding.ensureInitialized();
  AssetsAudioPlayer assetsAudioPlayer = AssetsAudioPlayer.withId('1234');
  var audio = Audio(
    "assets/audio/music.mp3",
  );
  await assetsAudioPlayer.open(
    audio,
    autoStart: true,
    showNotification: true,
  );
  await AndroidAlarmManager.initialize();
  runApp(MyApp());
  await AndroidAlarmManager.oneShotAt(DateTime.now().add(Duration(seconds: 15)), 123456789, printHello);
}

class MyApp extends StatelessWidget {
...
}
  • Thank you for your answer. but I need to play the sound in the specific time . (in the Background) . some Thing Like Alarm . For Example 4 hours later . not immediately. – Sajjad Oct 20 '21 at 05:53