audioplayers
audioplayers copied to clipboard
earpieceOrSpeakersToggle always giving error
when press earpieceOrSpeakersToggle always giving error ? my device real and android
E/AudioplayersPlugin(21936): Unexpected error!
E/AudioplayersPlugin(21936): java.lang.NullPointerException: uriString
E/AudioplayersPlugin(21936): at android.net.Uri$StringUri.<init>(Uri.java:481)
E/AudioplayersPlugin(21936): at android.net.Uri$StringUri.<init>(Unknown Source:0)
E/AudioplayersPlugin(21936): at android.net.Uri.parse(Uri.java:443)
E/AudioplayersPlugin(21936): at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1175)
E/AudioplayersPlugin(21936): at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1169)
E/AudioplayersPlugin(21936): at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1136)
E/AudioplayersPlugin(21936): at xyz.luan.audioplayers.WrappedMediaPlayer.setSource(WrappedMediaPlayer.java:287)
E/AudioplayersPlugin(21936): at xyz.luan.audioplayers.WrappedMediaPlayer.setPlayingRoute(WrappedMediaPlayer.java:88)
E/AudioplayersPlugin(21936): at xyz.luan.audioplayers.AudioplayersPlugin.handleMethodCall(AudioplayersPlugin.java:125)
E/AudioplayersPlugin(21936): at xyz.luan.audioplayers.AudioplayersPlugin.onMethodCall(AudioplayersPlugin.java:44)
E/AudioplayersPlugin(21936): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:231)
E/AudioplayersPlugin(21936): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:93)
E/AudioplayersPlugin(21936): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:642)
E/AudioplayersPlugin(21936): at android.os.MessageQueue.nativePollOnce(Native Method)
E/AudioplayersPlugin(21936): at android.os.MessageQueue.next(MessageQueue.java:379)
E/AudioplayersPlugin(21936): at android.os.Looper.loop(Looper.java:144)
E/AudioplayersPlugin(21936): at android.app.ActivityThread.main(ActivityThread.java:7529)
E/AudioplayersPlugin(21936): at java.lang.reflect.Method.invoke(Native Method)
E/AudioplayersPlugin(21936): at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
E/AudioplayersPlugin(21936): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
E/MethodChannel#xyz.luan/audioplayers(21936): Failed to handle method call
E/MethodChannel#xyz.luan/audioplayers(21936): java.lang.IllegalArgumentException: Unsupported value: java.lang.NullPointerException: uriString
E/MethodChannel#xyz.luan/audioplayers(21936): at io.flutter.plugin.common.StandardMessageCodec.writeValue(StandardMessageCodec.java:294)
E/MethodChannel#xyz.luan/audioplayers(21936): at io.flutter.plugin.common.StandardMethodCodec.encodeErrorEnvelope(StandardMethodCodec.java:70)
E/MethodChannel#xyz.luan/audioplayers(21936): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.error(MethodChannel.java:239)
E/MethodChannel#xyz.luan/audioplayers(21936): at xyz.luan.audioplayers.AudioplayersPlugin.onMethodCall(AudioplayersPlugin.java:47)
E/MethodChannel#xyz.luan/audioplayers(21936): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:231)
E/MethodChannel#xyz.luan/audioplayers(21936): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:93)
E/MethodChannel#xyz.luan/audioplayers(21936): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:642)
E/MethodChannel#xyz.luan/audioplayers(21936): at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#xyz.luan/audioplayers(21936): at android.os.MessageQueue.next(MessageQueue.java:379)
E/MethodChannel#xyz.luan/audioplayers(21936): at android.os.Looper.loop(Looper.java:144)
E/MethodChannel#xyz.luan/audioplayers(21936): at android.app.ActivityThread.main(ActivityThread.java:7529)
E/MethodChannel#xyz.luan/audioplayers(21936): at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#xyz.luan/audioplayers(21936): at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
E/MethodChannel#xyz.luan/audioplayers(21936): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
E/flutter (21936): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(error, Unsupported value: java.lang.NullPointerException: uriString, null)
E/flutter (21936): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7)
E/flutter (21936): #1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:321:33)
E/flutter (21936): <asynchronous suspension>
E/flutter (21936): #2 AudioPlayer._invokeMethod (package:audioplayers/audioplayers.dart:319:10)
E/flutter (21936): #3 AudioPlayer.earpieceOrSpeakersToggle (package:audioplayers/audioplayers.dart:637:30)
E/flutter (21936): #4 _PlayerWidgetState._earpieceOrSpeakersToggle (package:retyol/helpers/player_widget.dart:240:39)
E/flutter (21936): #5 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
E/flutter (21936): #6 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:486:11)
E/flutter (21936): #7 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:264:5)
E/flutter (21936): #8 BaseTapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:236:7)
E/flutter (21936): #9 GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:156:27)
E/flutter (21936): #10 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:222:20)
E/flutter (21936): #11 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22)
E/flutter (21936): #12 GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7)
E/flutter (21936): #13 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7)
E/flutter (21936): #14 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7)
E/flutter (21936): #15 _rootRunUnary (dart:async/zone.dart:1138:13)
E/flutter (21936): #16 _CustomZone.runUnary (dart:async/zone.dart:1031:19)
E/flutter (21936): #17 _CustomZone.runUnaryGuarded (dart:async/zone.dart:933:7)
E/flutter (21936): #18 _invoke1 (dart:ui/hooks.dart:273:10)
E/flutter (21936): #19 _dispatchPointerDataPacket (dart:ui/hooks.dart:182:5)
E/flutter (21936):
Same problem here, my code :
`AudioCache audioCache = new AudioCache(prefix: 'assets/audio/', respectSilence: widget.settings.respectSilence); File audiofile = await audioCache.load('alarm.mp3');
AudioPlayer advancedPlayer = AudioPlayer();
final result = await advancedPlayer.earpieceOrSpeakersToggle();
if (Platform.isIOS) advancedPlayer.monitorNotificationStateChanges(monitorNotificationStateHandler);
await advancedPlayer.play(audiofile.path, isLocal: true, respectSilence: widget.settings.respectSilence, volume: widget.settings.chronoVolume);`
The only solution i found : do the earpieceOrSpeakersToggle
method in a try/catch in init.
Maybe allow to define the PlayingRouteState in constructor ?
you have to call play or setUrl first I think. definitely a bug, you should be able to call it whenever like the other methods.
Hello! Unfortunately this bug still exists, so I have to use platform native code to deal with switching to earpiece and back.
earpieceOrSpeakersToggle
method in a try/catch also not working at all.
Please answer me if there is any simple workaround/solution.
This method doesn't exist anymore. Closing in favor of #1240