-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
assetPath and audio file placement #41
Comments
It dont works for me. I Placed the Audiofiles in the src-capacitor/ios/App/App/public/assets/ Folder And my methode call is:
Error Message from XCode [error] - {"errorMessage":"Asset Path is missing - public/assets/NeueNachrichtWav.wav","message":"Asset Path is missing - public/assets/NeueNachrichtWav.wav"} Sorry i need help. |
I am experiencing this issue as well. |
Ok great I am not alone. Where do you placed, your audio files? |
It worked when I placed the sound file in the Then I was able to use the file like so: NativeAudio.preload({
assetPath: 'public/assets/test.mp4',
assetId: 'test',
isUrl: false
}) So far I have only tested this on iOS. I assume @HunSpeedi's note about a different path on Android is correct as well. |
@lordrepha1980 If you have followed my instructions under "Suggestion for a fix" it should work. if (this.platform.is('android')) {
NativeAudio.preload({
assetPath: 'sound.mp3',
assetId: 'my_sound',
volume: 1.0,
audioChannelNum: 1,
});
} else if (this.platform.is('ios')) {
NativeAudio.preload({
assetPath: 'public/assets/sound.mp3',
assetId: 'my_sound',
volume: 1.0,
audioChannelNum: 1,
});
} |
Sorry, it doesn't work. |
@lordrepha1980 And you have checked in your code editor if the files are in the given location within the ios and android folders? |
Sorry, it doesnt work i use Quasar. I have my files into root/src/assets/audio. All Background Audio Services are on. |
For me, it seems to only work using the same path on both Android and iOS. Not sure why mine is behaving different than @HunSpeedi. I did notice that if I place the audio file in a sub-folder of So for example, if I have a file,
And then I can use it like so: NativeAudio.preload({
assetId: 'sound',
assetPath: 'public/assets/sound.mp3',
audioChannelNum: 1,
isUrl: false,
}); |
Something that worked for me (for ios) :
Xcode seems to copy the file to the root of the project, you can now load and play the file using the following code :
|
I have checked, and my implementation works the same :) |
You need to check if your files are within the ios and android folders! |
In my case Capacitor didn't flatten the directories. After doing so the audio files is accessible from the public directory in both android and ios. |
If you want to download a mp3 file from a server, store it locally and play it, please see my code example here: #39 (comment) |
Same for me in android. Couldn't |
Worked for me with |
this worked fpr me #41 (comment) thank you guys |
@nprail's solution work for me, just one different is it not flatten my sounds folder. (I'm on ionic 6 and capacitor 3.4.1) Assume you place your sounds in Then run:
Ensure you won't forgot Then you can load it with something like:
Hope it help 🐱 |
I'm using Android, iOS and web with hopefully the same code. NativeAudio.preload({
assetId: 'music',
assetPath: `content/music.mp3`, // relative path to base URL on server and public folder on native
isUrl: false
}); As far as I understand, this is currently not the case. native-audio/android/src/main/java/com/getcapacitor/community/audio/NativeAudio.java Line 449 in b13bd91
This seems like a special way to get a resource, but I would expect it to be something like content: so that it doesn't mix with the relative folder hierarchy.
Let me know if there's anything I can do to help solve this (e.g. PR etc) |
In Android how I figured out what the path should be is by finding the audio file in the assets folder in the project file tree in Android Studio, right clicking on it, choosing "Copy Path / Reference", then choosing "Path from Source Root". Put that in my code, and presto I hear a sound played. |
i have publish |
Description of the bug:
In the Readme.md the following is stated:
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 iOSyou need to specify more details like:
assetPath: 'public/assets/sound.mp3'
The text was updated successfully, but these errors were encountered: