audioplayers icon indicating copy to clipboard operation
audioplayers copied to clipboard

Crash on Android Error: java.util.ConcurrentModificationException

Open hammadbawara opened this issue 3 years ago • 1 comments

Checklist

  • [x] I read the troubleshooting guide before raising this issue
  • [x] I made sure that the issue I am raising doesn't already exist

Current bug behaviour

App crahses when user press many buttons at once in Xylophone app.

Expected behaviour

I made a Xylophone App on flutter. You can click different buttons and it play different audios. But when use press many buttons in fast speed this app crashes and show this error. I only tested this app on Android.

Steps to reproduce

void playNote(int noteNumber){
    final player = AudioPlayer();
    player.play(AssetSource('note$noteNumber.wav'));
  }
Code sample
void main() {
}

Logs

E/AndroidRuntime( 6063): java.util.ConcurrentModificationException
E/AndroidRuntime( 6063): 	at java.util.LinkedHashMap$LinkedHashIterator.nextEntry(LinkedHashMap.java:411)
E/AndroidRuntime( 6063): 	at java.util.LinkedHashMap$ValueIterator.next(LinkedHashMap.java:426)
E/AndroidRuntime( 6063): 	at xyz.luan.audioplayers.AudioplayersPlugin$UpdateCallback.run(AudioplayersPlugin.kt:208)
E/AndroidRuntime( 6063): 	at android.os.Handler.handleCallback(Handler.java:751)
E/AndroidRuntime( 6063): 	at android.os.Handler.dispatchMessage(Handler.java:95)
E/AndroidRuntime( 6063): 	at android.os.Looper.loop(Looper.java:154)
E/AndroidRuntime( 6063): 	at android.app.ActivityThread.main(ActivityThread.java:6077)
E/AndroidRuntime( 6063): 	at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 6063): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
E/AndroidRuntime( 6063): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
Full Logs
my full logs or a link to a gist

Flutter doctor:

Output of: flutter doctor -v

Audio Files/URLs/Sources

  • Audio Files : https://drive.google.com/drive/folders/1Hf5sWMtroSgYJGV3NSlLQCwO6Q0EDbES?usp=sharing

Screenshots

Environment information

  • audioplayers version: 1.0.1

Platform 1:

  • OS name and version: Android 9 (Physical), Android 6 (Emulator)
  • Device: Mobile
  • build mode: debug
  • error peculiarities (optional):

Platforms tested without any issue (optional):

  • test peculiarities:

More information

hammadbawara avatar Sep 09 '22 13:09 hammadbawara

Can you test with current main branch:

dependency_overrides:
  audioplayers:
    git:
      url: https://github.com/bluefireteam/audioplayers.git
      path: 'packages/audioplayers'
  audioplayers_platform_interface:
    git:
      url: https://github.com/bluefireteam/audioplayers.git
      path: 'packages/audioplayers_platform_interface'
  audioplayers_web:
    git:
      url: https://github.com/bluefireteam/audioplayers.git
      path: 'packages/audioplayers_web'
  audioplayers_linux:
    git:
      url: https://github.com/bluefireteam/audioplayers.git
      path: 'packages/audioplayers_linux'
  audioplayers_android:
    git:
      url: https://github.com/bluefireteam/audioplayers.git
      path: 'packages/audioplayers_android'

Gustl22 avatar Sep 21 '22 13:09 Gustl22

You can also test now with the newest release audioplayers: ^1.1.0

Gustl22 avatar Sep 27 '22 21:09 Gustl22

I have the same issue; I am using the latest version of audioplayers and Flame_Audio and this error appears when I play bgm with sound effects. But when I play sound effects only, no error occurs

Sherif-2001 avatar Sep 30 '22 08:09 Sherif-2001

@luanpotter @Gustl22 any clue how this could be solved? I'm not proficient enough with how the map is passed between Dart and Kotlin, it seems like it's not possible to pass a ConcurrentMap at least and I've also tried to make a copy of the map before looping it but without success, it still throws the ConcurrentModificationException. We have a lot of people reporting this error on Discord.

spydon avatar Oct 07 '22 07:10 spydon

I occasionally also get the same error on a fairly simple invocation of audioplayers. This is a problem on both v1.1.0 and earlier versions. The majority of time, this works fine, but this error does seem to come up with 5-10% of android users or so. Currently, I have only noticed this error on Android. After audio is loaded, the app makes use of 'seek', 'play', 'pause', which can be pressed in fast succession - guess this is the same problem that @hammadbawara has mentioned.

Framework invocation

AudioPlayer player = AudioPlayer();
await player.setSource(DeviceFileSource(audioFile.path));

Error code

Fatal Exception: java.util.ConcurrentModificationException
       at java.util.LinkedHashMap$LinkedHashIterator.nextNode(LinkedHashMap.java:760)
       at java.util.LinkedHashMap$LinkedValueIterator.next(LinkedHashMap.java:788)
       at xyz.luan.audioplayers.AudioplayersPlugin$UpdateRunnable.run(AudioplayersPlugin.kt:212)
       at android.os.Handler.handleCallback(Handler.java:938)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loopOnce(Looper.java:226)
       at android.os.Looper.loop(Looper.java:313)
       at android.app.ActivityThread.main(ActivityThread.java:8751)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)

mzkai avatar Oct 07 '22 10:10 mzkai

I just released v1.1.1 with a fix for this, @Gustl22 saves the day again! image

spydon avatar Oct 08 '22 15:10 spydon