Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Platform Exception Error when playing audio file Android, Vscode (0.17.3) #752

Closed
plyrek opened this issue Feb 3, 2021 · 7 comments
Closed
Labels
bug platform-android Affects the android platform

Comments

@plyrek
Copy link

plyrek commented Feb 3, 2021

Playing an audio file causes a Platform Exception Error.

Full Description
Playing an audio file _player.play('BG.mp3', mode: PlayerMode.LOW_LATENCY); causes a the following error.

Exception has occurred.
PlatformException (PlatformException(Unexpected error!, Operation is not supported for read-only collection, java.lang.UnsupportedOperationException: Operation is not supported for read-only collection
at kotlin.collections.EmptyMap.put(Unknown Source:4)
at java.util.Collections$SynchronizedMap.put(Collections.java:2639)
at xyz.luan.audioplayers.WrappedSoundPool.setUrl(WrappedSoundPool.kt:247)
at xyz.luan.audioplayers.AudioplayersPlugin.handleMethodCall(AudioplayersPlugin.kt:62)
at xyz.luan.audioplayers.AudioplayersPlugin.onMethodCall(AudioplayersPlugin.kt:37)
at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:692)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:335)
at android.os.Looper.loop(Looper.java:183)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
, null))

Code to Reproduce
Play any audio file with the play method.

Log Errors
Exception has occurred.
PlatformException (PlatformException(Unexpected error!, Operation is not supported for read-only collection, java.lang.UnsupportedOperationException: Operation is not supported for read-only collection
at kotlin.collections.EmptyMap.put(Unknown Source:4)
at java.util.Collections$SynchronizedMap.put(Collections.java:2639)
at xyz.luan.audioplayers.WrappedSoundPool.setUrl(WrappedSoundPool.kt:247)
at xyz.luan.audioplayers.AudioplayersPlugin.handleMethodCall(AudioplayersPlugin.kt:62)
at xyz.luan.audioplayers.AudioplayersPlugin.onMethodCall(AudioplayersPlugin.kt:37)
at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:692)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:335)
at android.os.Looper.loop(Looper.java:183)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
, null))

Platforms
Android only.

Flutter Doctor Output

[✓] Flutter (Channel stable, 1.22.6, on macOS 11.1 20C69 darwin-x64, locale en-US)

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 12.4)
[!] Android Studio (version 4.1)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] VS Code (version 1.52.1)
[✓] Connected device (2 available)
! Error: iPhone is busy: Copying cache files from device. Xcode will continue when Paul’s iPhone is finished. (code -10)

! Doctor found issues in 1 category.
immergenmac2@Pauls-MacBook-Pro mobile-flutter-afx2020 % flutter doctor -v
[✓] Flutter (Channel stable, 1.22.6, on macOS 11.1 20C69 darwin-x64, locale en-US)
• Flutter version 1.22.6 at /Users/development/flutter
• Framework revision 9b2d32b605 (11 days ago), 2021-01-22 14:36:39 -0800
• Engine revision 2f0af37152
• Dart version 2.10.5

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at /Users/immergenmac2/Library/Android/sdk
• Platform android-30, build-tools 30.0.3
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
• All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 12.4)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 12.4, Build version 12D4e
• CocoaPods version 1.10.0

[!] Android Studio (version 4.1)
• Android Studio at /Applications/Android Studio.app/Contents
✗ Flutter plugin not installed; this adds Flutter specific functionality. (FYI this is know VScode issue with Flutter doctor has always been this way even when build was working).
✗ Dart plugin not installed; this adds Dart specific functionality. (FYI this is know VScode issue with Flutter doctor has always been this way even when build was working).
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)

[✓] VS Code (version 1.52.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.19.0

@plyrek plyrek added the bug label Feb 3, 2021
@plyrek
Copy link
Author

plyrek commented Feb 4, 2021

After doing some more searching I did find this entry in the forum that addressed my issue. #734 (comment) however this is a workaround not a fix so I would suggest that this issue remains open. This workaround can also cause an error if sounds are played to quickly in succession or overlap.

Error: I/ExoPlayerImpl( 7743): Release 26b0552 [ExoPlayerLib/2.12.1] [generic_x86_arm, sdk_gphone_x86_arm, Google, 30] [goog.exo.core]
E/MediaPlayerNative( 7743): error (1, -19)
E/MediaPlayer( 7743): Error (1,-19)
E/MediaPlayerNative( 7743): pause called in state 0, mPlayer(0xc79e53f0)
E/MediaPlayerNative( 7743): error (-38, 0)
E/MediaPlayerNative( 7743): Attempt to perform seekTo in wrong state: mPlayer=0xc79e53f0, mCurrentState=0
E/MediaPlayerNative( 7743): error (-38, 0)

@midi1007
Copy link

midi1007 commented Feb 10, 2021

same for me on android simulator:

E/flutter (23956): at kotlin.collections.EmptyMap.put(Unknown Source:4)
E/flutter (23956): at java.util.Collections$SynchronizedMap.put(Collections.java:2639)
E/flutter (23956): at xyz.luan.audioplayers.WrappedSoundPool.setUrl(WrappedSoundPool.kt:247)
E/flutter (23956): at xyz.luan.audioplayers.AudioplayersPlugin.handleMethodCall(AudioplayersPlugin.kt:62)
E/flutter (23956): at xyz.luan.audioplayers.AudioplayersPlugin.onMethodCall(AudioplayersPlugin.kt:37)
E/flutter (23956): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
E/flutter (23956): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
E/flutter (23956): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:818)
E/flutter (23956): at android.os.MessageQueue.nativePollOnce(Native Method)
E/flutter (23956): at android.os.MessageQueue.next(MessageQueue.java:335)
E/flutter (23956): at android.os.Looper.loop(Looper.java:183)
E/flutter (23956): at android.app.ActivityThread.main(ActivityThread.java:7656)
E/flutter (23956): at java.lang.reflect.Method.invoke(Native Method)
E/flutter (23956): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
E/flutter (23956): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
E/flutter (23956): , null)
E/flutter (23956): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:581:7)
E/flutter (23956): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:158:18)
E/flutter (23956):
E/flutter (23956): #2 AudioPlayer.play (package:audioplayers/audioplayers.dart:404:24)
E/flutter (23956):
E/flutter (23956): #3 AudioCache.play (package:audioplayers/audio_cache.dart:125:5)
E/flutter (23956):

@mikeesouth
Copy link

I'm also seeing this when upgrading from 0.16.1 to 0.17.3, #734 (comment) does work (i.e. send MEDIA_PLAYER instead of LOW_LATENCY) but I would like to use LOW_LATENCY on Android.

I'm getting tired that there are so many bugs in this repo. Can anyone recommend alternative solutions for playing sound effects and short mp3 files in Flutter (must work well in iOS)?

@erickzanardo
Copy link
Member

Closing this due to reports of this being fixed on newer versions. Feel free to open a new issue in case of this still happening

@egaga
Copy link

egaga commented Oct 11, 2021

Does not work on 0.20.1 on Android. Changing to type MediaPlayer works but not what I'd like to have.

Platform android version 31.

@filiph
Copy link

filiph commented Feb 28, 2024

I'm not sure if this is worthy of a new issue but: I just saw this issue when testing endless_runner (from https://github.com/flutter/games) on Google Play Games on PC Developer Emulator. After a while, the game started logging this error, not generating any new sounds. Once the current music loop was done, there was silence.

I/flutter ( 6030): AudioPlayers Exception: AudioPlayerException(
I/flutter ( 6030):     AssetSource(path: sfx/jump1.mp3),
I/flutter ( 6030):     PlatformException(AndroidAudioError, MEDIA_ERROR_UNKNOWN {what:1}, MEDIA_ERROR_UNKNOWN {extra:-19}, null)
V/MediaPlayer( 6030): resetDrmState:  mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false
V/MediaPlayer( 6030): cleanDrmObj: mDrmObj=null mDrmSessionId=null
E/MediaPlayerNative( 6030): error (1, -19)
E/MediaPlayer( 6030): Error (1,-19)
E/MediaPlayerNative( 6030): stop called in state 0, mPlayer(0x762ba9acc590)
E/MediaPlayerNative( 6030): error (-38, 0)
V/MediaPlayer( 6030): resetDrmState:  mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false
V/MediaPlayer( 6030): cleanDrmObj: mDrmObj=null mDrmSessionId=null
V/MediaPlayer( 6030): resetDrmState:  mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false
V/MediaPlayer( 6030): cleanDrmObj: mDrmObj=null mDrmSessionId=null

@Gustl22
Copy link
Collaborator

Gustl22 commented Feb 29, 2024

I personally don't plan to fix Android specific bugs, until we have ExoPlayer landed, which again depends on Flutter. We're happy for Pull-Requests though.

@Gustl22 Gustl22 added the platform-android Affects the android platform label Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug platform-android Affects the android platform
Projects
None yet
Development

No branches or pull requests

7 participants