native-audio
native-audio copied to clipboard
on android it doesn't work
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
Once the component is mounted I preload the .mp3 file
Below I attach the button code and the method that calls the sound
I am attaching the location of the file in my ionic project
Below I show you where I have the file for the Android application located.
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
Smartphone :
- Device: Samsung A51
- OS: Android 13
I hope you can help me, or detect what my error is.
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
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:
Any insight as to what I am doing wrong would be greatly appreciated.
Thanks
@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.
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?
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)); }