Hello,
I am trying to use the capacitor-community/native-audio plugin in an Ionic Android app that plays .wav file.
I can get the plugin to play in a web browser on my computer, but when running on an Android device I am not able to hear anything being played.
The documentation has the location for the .wav file for Android as
Android: android/app/src/assets
I have tried it here.
NativeAudio.preload({
assetId: "green_noise",
assetPath: "green_noise.mp3",
audioChannelNum: 1,
isUrl: false
}).catch(err => console.log(err));
I have also seen it in the Android folder - public/assets/
NativeAudio.preload({
assetId: "green_noise",
assetPath: "public/assets/sounds/green_noise.mp3",
audioChannelNum: 1,
isUrl: false
}).cat
ch(err => console.log(err));
Both places I have not been able to hear the .wav file being played. I am not getting any errors.
Any insight on the what I might be doing incorrectly?
Thanks,
Brent
You say you are trying to play a wav file yet your assetPath
is a mp3
Looking at the docs, if the file is in android/app/src/assets
, you just reference it via the file name, not the entire file path.
Sorry I meant .mp3 not a .wav, my bad!
Yes the docs do have that though I was looking at this:
assetPath and audio file placement · Issue #41 · capacitor-community/native-audio · GitHub
where it states:
Description of the bug:
In the Readme.md the following is stated:
All audio place in specific platform folder
Andoid: android/app/src/assets
iOS: ios/App/App/sounds
This seems to be incorrect!
Suggestion for a fix:
All audio should be placed inside the specific folders:
Android: android/app/src/main/assets
iOS: ios/App/App/public/assets/
Note: in the case of Android the assethPath
is just the filename with the extension like 'sound.mp3'
but in the case of iOS
you need to specify more details like: assetPath: 'public/assets/sound.mp3'
I did create a new assets folder at android/app/src/ as documentation states and at android/app/src/main/assets as was suggested but still have the same issue.
I also tried performing a npx copy as someone else suggested and it copies the assets including the .mp3 file here:
android/app/src/main/assets/public/assets/
I have tried both
assetPath: ‘green_noise.mp3’,
assetPath: ‘public/assets/green_noise.mp3’,
Neither one works.
Any other suggestions?
Thanks,
Brent