flutter audioplayer error when playing audio - flutter

im triyng to play a sound on a button click using the package audio player 0.18.0, but every time i press the button to make the sound play i get this error.
E/flutter ( 4036): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: MissingPluginException(No implementation found for method getTemporaryDirectory on channel plugins.flutter.io/path_provider)
E/flutter ( 4036): #0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:154:7)
E/flutter ( 4036):
E/flutter ( 4036): #1 getTemporaryDirectory (package:path_provider/path_provider.dart:55:24)
E/flutter ( 4036):
E/flutter ( 4036): #2 AudioCache.fetchToMemory (package:audioplayers/audio_cache.dart:79:27)
E/flutter ( 4036):
E/flutter ( 4036): #3 AudioCache.load (package:audioplayers/audio_cache.dart:97:31)
E/flutter ( 4036):
E/flutter ( 4036): #4 AudioCache.getAbsoluteUrl (package:audioplayers/audio_cache.dart:192:17)
E/flutter ( 4036):
E/flutter ( 4036): #5 AudioCache.play (package:audioplayers/audio_cache.dart:122:18)
E/flutter ( 4036):
what do i do to fix this?

I got this error and I did the same thing but I found the solution :
You need to use
audioplayers:^1.0.1
then if you want to play an asset audio
just type:
final audio2= AudioPlayer();
audio2.play(AssetSource('Your wav file or your mp3 file '));
and thats it and it will work perfectly:).

It is because of the recent update of the package, the solution is: use audioplayers as package & AudioPlayer() as constructor & this method play(AssetSource('')) .

Related

Is there a way to eliminate the error when clicking the button fast

I have this code below which plays a sound every time I hit a button.
AudioPlayer player = AudioPlayer();
Future<void> playSound({required String soundStr}) async {
player.setAsset(soundStr);
player.play();
}
But whenever I hit the button fast, sometimes it will show this error. How can I eliminate this error? I tried adding player.stop(); but it still the same.
E/flutter ( 4312): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(abort, Loading interrupted, null, null)
E/flutter ( 4312): #0 AudioPlayer._setPlatformActive.checkInterruption (package:just_audio/just_audio.dart:1236:7)
E/flutter ( 4312): #1 AudioPlayer._setPlatformActive.setPlatform (package:just_audio/just_audio.dart:1347:11)
E/flutter ( 4312): <asynchronous suspension>
E/flutter ( 4312):
E/flutter ( 4312): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(abort, Loading interrupted, null, null)
E/flutter ( 4312):
Edit: I tried adding await.
Future<void> playSound({required String soundStr}) async {
await player.setAsset(soundStr);
await player.play();
}
If I hit the buttons fast, it will still have error. Though it is now different.
E/flutter (21654): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Connection aborted
E/flutter (21654): #0 AudioPlayer._load (package:just_audio/just_audio.dart:843:11)
E/flutter (21654): <asynchronous suspension>
E/flutter (21654): #1 AudioPlayer.load (package:just_audio/just_audio.dart:770:14)
E/flutter (21654): <asynchronous suspension>
E/flutter (21654): #2 AudioPlayer.setAudioSource (package:just_audio/just_audio.dart:745:18)
E/flutter (21654): <asynchronous suspension>
E/flutter (21654): #3 playSound (package:super_pinoy_quiz/common/generic_methods.dart:396:3)
E/flutter (21654): <asynchronous suspension>
E/flutter (21654):
I'm using this package: just_audio: ^0.9.29
Though I tried using different package but it also encounters the same error when hitting the button fast: audioplayers: ^1.1.1
Both setAsset and play are future method, you can await for setting assets
Future<void> playSound({required String soundStr}) async {
await player.setAsset(soundStr);
await player.play();
}

ERROR:flutter/lib/ui/ui_dart_state.cc(209) Unhandled Exception: PlatformException

I have my flutter App integrated with firebase, everything was fine but after i integrate firebase i got error whenever I try to run my app.
My main method looks like this:
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
runApp(child: MyApp());
}
Error:
E/flutter ( 7922): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception:
PlatformException(firebase_core, FirebaseApp name [DEFAULT] already exists!, null, null)
E/flutter ( 7922): #0 StandardMethodCodec.decodeEnvelope
(package:flutter/src/services/message_codecs.dart:607:7)
E/flutter ( 7922): #1 MethodChannel._invokeMethod
(package:flutter/src/services/platform_channel.dart:177:18)
E/flutter ( 7922): <asynchronous suspension>
E/flutter ( 7922): #2 MethodChannel.invokeMapMethod
(package:flutter/src/services/platform_channel.dart:377:43)
E/flutter ( 7922): <asynchronous suspension>
E/flutter ( 7922): #3 MethodChannelFirebase.initializeApp (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:100:40)
E/flutter ( 7922): <asynchronous suspension>
E/flutter ( 7922): #4 Firebase.initializeApp
(package:firebase_core/src/firebase.dart:40:31)
E/flutter ( 7922): <asynchronous suspension>
E/flutter ( 7922): #5 main (package:zunada/main.dart:11:3)
E/flutter ( 7922): <asynchronous suspension>
E/flutter ( 7922):
I had similar issue when create firebase app by flavors using flutterfire CLI. I realized that flutterfire create apps with same name in different projects. Then I tried 2 ways and it works.
1st: manually change app name in each firebase project.
2nd: add param name when initialize such as in main_dev.dart
Example:
await Firebase.initializeApp(
name: "dev-project",
options: DefaultFirebaseOptions.currentPlatform);
I used the same name used in the firebase console as my project ID for consistency, keep in mind that you cannot add spaces to the name (only dashes -).

Unhandled Exception: MissingPluginException(No implementation found for method initialize on channel awesome_notifications)

i already initialized awesome_notifications plugin in main.dart When i hot restart, in debug console i'm getting this error:
E/flutter ( 4447): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: MissingPluginException(No implementation found for method initialize on channel awesome_notifications)
E/flutter ( 4447): #0 MethodChannel._invokeMethod
package:flutter/…/services/platform_channel.dart:165
E/flutter ( 4447): <asynchronous suspension>
E/flutter ( 4447): #1 AwesomeNotifications.initialize (package:awesome_notifications/src/awesome_notifications_core.dart:174:18)
E/flutter ( 4447): <asynchronous suspension>
E/flutter ( 4447):
E/flutter ( 4447): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: MissingPluginException(No implementation found for method isNotificationAllowed on channel awesome_notifications)
E/flutter ( 4447): #0 MethodChannel._invokeMethod
package:flutter/…/services/platform_channel.dart:165
E/flutter ( 4447): <asynchronous suspension>
Here's my code :
main.dart
Future<void> main() async {
WidgetsFlutterBinding();
await Hive.initFlutter();
if (!Hive.isAdapterRegistered(AddEventModelAdapter().typeId)) {
Hive.registerAdapter(AddEventModelAdapter());
}
AwesomeNotifications()
.initialize('resource://drawable/res_notification_app_icon', [
NotificationChannel(
channelKey: 'schedule_channel',
channelName: 'scheduled_channel',
channelDescription: 'descroiption',
locked: true,
importance: NotificationImportance.High,
),
]);
runApp(const MyApp());
}
Whenever you add a plugin in your pubspec.yaml, you need to stop the app and re-run it again because the plugin contains native code on both platforms.
If it still does not work, then do flutter clean and run.

Unhandled Exception: MissingPluginException(No implementation found for method log on channel testfairy)

I'm trying to build an Android app, but receive an error MissingPluginException(No implementation found for method log on channel testfairy):
E/flutter ( 8121): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: MissingPluginException(No implementation found for method initialize on channel dexterous.com/flutter/local_notifications)
E/flutter ( 8121): #0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:157:7)
E/flutter ( 8121): <asynchronous suspension>
E/flutter ( 8121): #1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:332:12)
E/flutter ( 8121): #2 AndroidFlutterLocalNotificationsPlugin.initialize (package:flutter_local_notifications/src/platform_flutter_local_notifications.dart:67:27)
E/flutter ( 8121): #3 FlutterLocalNotificationsPlugin.initialize (package:flutter_local_notifications/src/flutter_local_notifications_plugin.dart:97:13)
E/flutter ( 8121): #4 NotificationHelper.initNotifications (package:boxview_mobile_flutter/services/notification_helper.dart:23:37)
E/flutter ( 8121): #5 new Routes (package:boxview_mobile_flutter/routes.dart:49:26)
E/flutter ( 8121): #6 main (package:boxview_mobile_flutter/main.dart:4:7)
E/flutter ( 8121): #7 _runMainZoned.<anonymous closure>.<anonymous closure> (dart:ui/hooks.dart:231:25)
E/flutter ( 8121): #8 _rootRun (dart:async/zone.dart:1190:13)
E/flutter ( 8121): #9 _CustomZone.run (dart:async/zone.dart:1093:19)
E/flutter ( 8121): #10 _runZoned (dart:async/zone.dart:1630:10)
E/flutter ( 8121): #11 runZonedGuarded (dart:async/zone.dart:1618:12)
E/flutter ( 8121): #12 _runMainZoned.<anonymous closure> (dart:ui/hooks.dart:223:5)
E/flutter ( 8121): #13 _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:301:19)
E/flutter ( 8121): #14 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)
Current version of TestFairy plugin: testfairy: ^2.0.1
Flutter (Channel stable, 1.22.2)
Dart version 2.10.2.
Also, I've added analysis_options.yaml:
analyzer:
enable-experiment:
- non-nullable
I run the app with the command flutter run --enable-experiment=non-nullable --no-sound-null-safety.
How to resolve this error?
#Akif has pointed in the right direction of a reason for the problem. In fact, this was due to the local_notifications plugin. I managed to solve this problem by switching the flutter to the beta channel (Flutter 1.23.0-18.1.pre • channel beta).

MissingPluginException(No implementation found for method check on channel plugins.flutter.io/connectivity

I'm using this connectivity plugin to check the internet connectivity status. It works fine with the flutter dart code but when I called the flutter dart code from native android kotlin code this missingplugin exception occurs. So for me this error occurs only when the flutter code is called from native android kotlin code using platform channel.
[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: MissingPluginException(No implementation found for method check on channel plugins.flutter.io/connectivity)
E/flutter ( 7294): #0 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:319:7)
E/flutter ( 7294): <asynchronous suspension>
E/flutter ( 7294): #1 MethodChannelConnectivity.checkConnectivity (package:connectivity_platform_interface/src/method_channel_connectivity.dart:42:10)
E/flutter ( 7294): #2 Connectivity.checkConnectivity (package:connectivity/connectivity.dart:47:22)
E/flutter ( 7294): #3 isConnectivityAvailable (package:kalyan_matrimony/utils/app_utils.dart:872:50)
E/flutter ( 7294): #4 _BasePackageState._callMembershipDetailsApi (package:kalyan_matrimony/screens/payment/base_package.dart:55:16)
E/flutter ( 7294): #5 _BasePackageState.getMembershipDetailsFromAPI (package:kalyan_matrimony/screens/payment/base_package.dart:51:5)
E/flutter ( 7294): <asynchronous suspension>
E/flutter ( 7294): #6 _BasePackageState.initState (package:kalyan_matrimony/screens/payment/base_package.dart:39:5)
E/flutter ( 7294): #7 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4355:58)
E/flutter ( 7294): #8 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
E/flutter ( 7294): #9 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
E/flutter ( 7294): #10 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
E/flutter ( 7294): #11 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
Also, The GeneratedPluginRegistrant.java file is called from mainactivity.kt file but in the file there is no registerwith code for connectivity and many other plugins. I don't understand why it is not generated automatically?
package io.flutter.plugins;
import androidx.annotation.Keep;
import androidx.annotation.NonNull;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.plugins.shim.ShimPluginRegistry;
/**
* Generated file. Do not edit.
* This file is generated by the Flutter tool based on the
* plugins that support the Android platform.
*/
#Keep
public final class GeneratedPluginRegistrant {
public static void registerWith(#NonNull FlutterEngine flutterEngine) {
ShimPluginRegistry shimPluginRegistry = new ShimPluginRegistry(flutterEngine);
flutterEngine.getPlugins().add(new io.flutter.plugins.camera.CameraPlugin());
ConnectivityPlugin.registerWith(shimPluginRegistry.registrarFor("io.flutter.plugins.connectivity.ConnectivityPlugin"));
flutterEngine.getPlugins().add(new io.flutter.plugins.connectivity.ConnectivityPlugin());
flutterEngine.getPlugins().add(new io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin());
flutterEngine.getPlugins().add(new com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin());
io.flutter.plugins.flutter_plugin_android_lifecycle.FlutterAndroidLifecyclePlugin.registerWith(shimPluginRegistry.registrarFor("io.flutter.plugins.flutter_plugin_android_lifecycle.FlutterAndroidLifecyclePlugin"));
com.fuyumi.flutterstatusbarcolor.flutterstatusbarcolor.FlutterStatusbarcolorPlugin.registerWith(shimPluginRegistry.registrarFor("com.fuyumi.flutterstatusbarcolor.flutterstatusbarcolor.FlutterStatusbarcolorPlugin"));
com.aldiferdiyan.xmpp.flutter_xmpp.FlutterXmppPlugin.registerWith(shimPluginRegistry.registrarFor("com.aldiferdiyan.xmpp.flutter_xmpp.FlutterXmppPlugin"));
com.aloisdeniel.geocoder.GeocoderPlugin.registerWith(shimPluginRegistry.registrarFor("com.aloisdeniel.geocoder.GeocoderPlugin"));
flutterEngine.getPlugins().add(new vn.hunghd.flutter.plugins.imagecropper.ImageCropperPlugin());
flutterEngine.getPlugins().add(new io.flutter.plugins.imagepicker.ImagePickerPlugin());
flutterEngine.getPlugins().add(new io.flutter.plugins.inapppurchase.InAppPurchasePlugin());
flutterEngine.getPlugins().add(new com.lyokone.location.LocationPlugin());
com.baseflow.location_permissions.LocationPermissionsPlugin.registerWith(shimPluginRegistry.registrarFor("com.baseflow.location_permissions.LocationPermissionsPlugin"));
flutterEngine.getPlugins().add(new io.flutter.plugins.packageinfo.PackageInfoPlugin());
flutterEngine.getPlugins().add(new io.flutter.plugins.pathprovider.PathProviderPlugin());
flutterEngine.getPlugins().add(new io.flutter.plugins.sharedpreferences.SharedPreferencesPlugin());
flutterEngine.getPlugins().add(new com.tekartik.sqflite.SqflitePlugin());
com.danieldallos.storeredirect.StoreRedirectPlugin.registerWith(shimPluginRegistry.registrarFor("com.danieldallos.storeredirect.StoreRedirectPlugin"));
flutterEngine.getPlugins().add(new io.flutter.plugins.urllauncher.UrlLauncherPlugin());
flutterEngine.getPlugins().add(new io.flutter.plugins.webviewflutter.WebViewFlutterPlugin());
}
}
Any suggestions would be really helpful. Thanks in advance.
The connectivity plugin doesn't seem to require writing any platform-specific code. Have you tried running a restart after adding the plugin? A hot reload may have yet to include the plugin that you've added.
If you're still having issues, it's best to share a minimal repro for us to be able to better understand the issue.