Skip to content

PlatformException(AndroidAudioError, null, java.lang.IllegalArgumentException when calling "setPlaybackRate" more than once on android #1959

Description

@novas1r1

Checklist

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

Current bug behaviour

I created an audioplayer where users are able to change speed based on a multipier (from 0.5 to 2.0x). On iOS everything works fine - on android the second time I try to update the speed, I'm getting the following exception and the speed is not updating. I made sure I passed valid values between 0.0 and 2.0 and no null values. I tried pausing the player before changing the speed - also didn't help. Any help on this is highly appreciated <3!

ERROR: PlatformException(AndroidAudioError, null, java.lang.IllegalArgumentException
      	at android.media.MediaPlayer.setPlaybackParams(Native Method)
      	at xyz.luan.audioplayers.player.MediaPlayerWrapper.setRate(MediaPlayerWrapper.kt:41)
      	at xyz.luan.audioplayers.player.WrappedPlayer.setRate(WrappedPlayer.kt:71)
      	at xyz.luan.audioplayers.AudioplayersPlugin.methodHandler(AudioplayersPlugin.kt:153)
      	at xyz.luan.audioplayers.AudioplayersPlugin.access$methodHandler(AudioplayersPlugin.kt:21)
2
      	at xyz.luan.audioplayers.AudioplayersPlugin$onAttachedToEngine$1$1.invoke(AudioplayersPlugin.kt:37)
      	at xyz.luan.audioplayers.AudioplayersPlugin.safeCall(AudioplayersPlugin.kt:56)
      	at xyz.luan.audioplayers.AudioplayersPlugin.onAttachedToEngine$lambda$0(AudioplayersPlugin.kt:37)
      	at xyz.luan.audioplayers.AudioplayersPlugin.$r8$lambda$1vepZk-E6R5vmkq5YXudNp2pY8I(Unknown Source:0)
      	at xyz.luan.audioplayers.AudioplayersPlugin$$ExternalSyntheticLambda0.onMethodCall(D8$$SyntheticClass:0)
      	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:267)
      	at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:292)
      	at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
      	at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(D8$$SyntheticClass:0)
      	at android.os.Handler.handleCallback(Handler.java:1041)
      	at android.os.Handler.dispatchMessage(Handler.java:103)
      	at android.os.Looper.dispatchMessage(Looper.java:315)
      	at android.os.Looper.loopOnce(Looper.java:251)
      	at android.os.Looper.loop(Looper.java:349)
      	at android.app.ActivityThread.main(ActivityThread.java:9041)
      	at java.lang.reflect.Method.invoke(Native Method)
      	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:593)
      	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:929)
      , null)

Expected behaviour

I would expect to be able to change the speedRate multiple times without running into exceptions.

Steps to reproduce

I could reproduce the exact same behavior on the official audioplayers example.

  1. Open the officicial audioplayers example and run it
  2. Play a local wav datasource
  3. Change speedRate to 1.5, afterwards change to 2.0 or something else -> Exception occurs

Code sample

Official code example:
https://github.com/bluefireteam/audioplayers/tree/main/packages/audioplayers/example

Affected platforms

Android

Platform details

  • Platform 1: Android, Pixel 8a, Android SDK 36

AudioPlayers Version

main

Build mode

debug, release

Audio Files/URLs/Sources

I used the once from the audioplayers example: "asset MP3 nasa.mp3"

Screenshots

No response

Logs

Full Logs

Flutter doctor:

flutter doctor -v 
[✓] Flutter (Channel stable, 3.35.4, on macOS 26.0.1 25A362 darwin-arm64, locale de-DE) [1.178ms]
  • Flutter version 3.35.4 on channel stable at /Users/verenazaiser/development/flutter
  • Upstream repository https://github.com/flutter/flutter.git
  • Framework revision d693b4b9db (7 weeks ago), 2025-09-16 14:27:41 +0000
  • Engine revision c298091351
  • Dart version 3.9.2
  • DevTools version 2.48.0
  • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop,
    enable-android, enable-ios, cli-animations, enable-lldb-debugging

[✓] Android toolchain - develop for Android devices (Android SDK version 36.0.0-rc4) [2,5s]
  • Android SDK at /Users/verenazaiser/Library/Android/sdk
  • Emulator version 35.3.11.0 (build_id 12836668) (CL:N/A)
  • Platform android-36, build-tools 36.0.0-rc4
  • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    This is the JDK bundled with the latest Android Studio installation on this machine.
    To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
  • Java version OpenJDK Runtime Environment (build 21.0.3+-79915917-b509.11)
  • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 26.0.1) [2,6s]
  • Xcode at /Applications/Xcode-26.0.1.app/Contents/Developer
  • Build 17A400
  • CocoaPods version 1.16.2

[✓] Chrome - develop for the web [10ms]
  • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2024.2) [9ms]
  • Android Studio at /Applications/Android Studio.app/Contents
  • Flutter plugin can be installed from:
    🔨 https://plugins.jetbrains.com/plugin/9212-flutter
  • Dart plugin can be installed from:
    🔨 https://plugins.jetbrains.com/plugin/6351-dart
  • Java version OpenJDK Runtime Environment (build 21.0.3+-79915917-b509.11)

[✓] VS Code (version 1.98.1) [7ms]
  • VS Code at /Applications/Visual Studio Code.app/Contents
  • Flutter extension version 3.106.0

[✓] Connected device (3 available) [6,8s]
  • Pixel 8a (mobile) • 3C251JEKB15306 • android-arm64  • Android 16 (API 36)
  • macOS (desktop)   • macos          • darwin-arm64   • macOS 26.0.1 25A362 darwin-arm64
  • Chrome (web)      • chrome         • web-javascript • Google Chrome 141.0.7390.123

[✓] Network resources [329ms]
  • All expected network resources are available.

Related issues / more information

No response

Working on PR

no way

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions