'(flutter): audio cache not playing a specific sound (.mp3) in android version > 9

I am using audioplayers 0.20.1 for playing sound on button press in my flutter app. For a specific sound, it is giving me some error only on android version > 9 and rest of the sounds are being played. And when I use android version <= 9, every sound is being played and there is no error for any sound.

Code:

Future<AudioPlayer> playLocalAsset() async {

    //method 1
    AudioCache cache = new AudioCache();
    String audioasset = "Sounds_Button_Press.mp3";
    ByteData bytes = await rootBundle.load(audioasset);
    Uint8List soundBytes = bytes.buffer.asUint8List(bytes.offsetInBytes, bytes.lengthInBytes);
    return await cache.playBytes(soundBytes);

    //method 2
    // AudioCache cache = new AudioCache();
    // return await cache.play("Sounds_Button_Press.mp3");

  }

Error(only on android version > 9):

E/MediaPlayerNative(31362): error (1, -2147483648)
E/MediaPlayer(31362): Error (1,-2147483648)
E/MediaPlayerNative(31362): stop called in state 0, mPlayer(0x7b81527f80)
E/MediaPlayerNative(31362): error (-38, 0)
V/MediaPlayer(31362): resetDrmState:  mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false
V/MediaPlayer(31362): cleanDrmObj: mDrmObj=null mDrmSessionId=null
V/MediaPlayer(31362): resetDrmState:  mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false
V/MediaPlayer(31362): cleanDrmObj: mDrmObj=null mDrmSessionId=null
D/MediaPlayer(31362): _release native called
D/MediaPlayer(31362): _release native finished


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source