native-audio icon indicating copy to clipboard operation
native-audio copied to clipboard

on android it doesn't work

Open LuisAlvaradoMtz97 opened this issue 1 year ago • 4 comments

I have a method which is responsible for playing the sound, place the mp3 file in the folders indicated in the documentation, when compiling on the web if the sound plays successfully, but when synchronizing the android application nothing is heard, now I tried with previous versions and I didn't get any results.

The following is the declaration I have at the beginning of my component image

Once the component is mounted I preload the .mp3 file image

Below I attach the button code and the method that calls the sound image

image

I am attaching the location of the file in my ionic project image

Below I show you where I have the file for the Android application located. image

I don't have any problems on the website, since it works perfectly, but on Android is where I haven't been able to play the sound

I attach the result that Android Studio returns when clicking the button image

Smartphone :

  • Device: Samsung A51
  • OS: Android 13

I hope you can help me, or detect what my error is.

LuisAlvaradoMtz97 avatar Dec 13 '23 17:12 LuisAlvaradoMtz97

To work on android I had to use the assetPathpublic/assets/beep.mp3 then ensure the file gets published there as well. I found that in this open issue https://github.com/capacitor-community/native-audio/issues/41

robbpjr avatar Dec 15 '23 02:12 robbpjr

Any resolution to this. I am also having the issue where it is working for the web but not for Android.

I have tried a lot of locations.

The documentation has the following location for Android:

Andoid: android/app/src/assets

here is my corresponding code:

constructor() { NativeAudio.preload({ assetId: "green_noise", assetPath: "green_noise.mp3", audioChannelNum: 1, isUrl: false }).catch(err => console.log(err)); }

The last one I tried the following per the above suggestion which did not help:

NativeAudio.preload({ assetId: "noise", assetPath: "public/assets/sounds/green_noise.mp3", audioChannelNum: 1, isUrl: false }).catch(err => console.log(err));

With the .wav file at the following location:

Screenshot 2024-09-03 at 7 27 51 AM

Any insight as to what I am doing wrong would be greatly appreciated.

Thanks

ASHBAW avatar Sep 03 '24 12:09 ASHBAW

@ASHBAW I could not get mine to work either when I placed them in a sounds directory under assets. I wanted to organize the assets directory a bit more as well but ultimately I kept it flat for the sounds so it was all in the assets dir. In your case you would then use assetPath: "public/assets/green_noise.mp3" (remove the sounds/ part). It's frustrating to have to do it like this but eventually I didn't want to fight it any longer (or deal with a pre-build script that flattened everything to one assets dir) just so I could have my assets organized more.

robbpjr avatar Sep 03 '24 23:09 robbpjr

Thanks for the comment. I had also tried that seeing it in the reference you had for #41 above. Unfortunately it did not help.

Any other suggestions?

Screenshot 2024-09-04 at 6 58 19 AM

constructor() { console.log('BAW OPENING FILE'); NativeAudio.preload({ assetId: "green_noise", assetPath: 'public/assets/green_noise.mp3', audioChannelNum: 1, isUrl: false }).catch(err => console.log('BAW 1 - ' + err)); }

ASHBAW avatar Sep 04 '24 11:09 ASHBAW