I am building a sample app to play mp3 file. I do have successfully added nativescript-sound module to my project, however, it is failing when it is trying to find the requested mp3 file. I added a new file to my project app/sounds/file.mp3.
I believe the mp3 file is not getting bundled to the android package and it is not being installed on my phone.
Where should I create new file and add mp3 file, under nativescript folder structure, so my app can find the needed mp3 file.
It will be great help.
Thanks,
Samir
5 Answers, 1 is accepted
I don't believe the issue is with the file location. As I was debugging the app I noticed that the adb tool detects the following error: SoundPool: sample 1 not READY. It seems that you need to delay the play() method to play the audio.
That resolved the issue in my sample project but then it didn't play the entire sound. I will therefore need a bit more time to further investigate the issue. I will get back to you as soon as I have more informaiton on the best approach to use the source package on an Android device.
Regards,
Tina Stancheva
Telerik

Thank you Tina for your feedback. I will take a look at it, however, I am could not see my custom mp3 file on my android device when I deploy the package to the device. What's the correct path/folder to put mp3 files so those will be deployed to the device? Do I have to change anything in configuration to make the folder included in package?
Let me know.
Samir
Thank you for your patience. I investigated this a bit further. The NativeScript-Sound module uses SoundPool to play a sound on Android. This imposes a few limitations on the app:
- SoundPool decompresses the loaded audio to 16-bit PCM mono or stereo stream and that takes a certain amount of time, depending on the size of sound file. This is why if you try to play the sound before that process is over, an error "sample x not ready" is thrown. Read more here and here.
- SoundPool seems to be designed to play short sound effects which is why if you play a larger file, it would only play about 5 seconds of it. Read more here and here.
As for deploying the file on the device, I am not sure why you believe the file is not loaded on the device. When you add the audio file under the app folder in the Project Navigator, then it is deployed on the device along with the entire content of the app. However, as the sound file is part of the application package you can't actually see it on a non-rooted Android device.
Since you submitted this ticket under the Telerik Platform product line, I've prepared a sample NativeScript app built in Telerik Platform that demonstrates the usage of the nativescript-sound module. Note that the media object is initialized when the start-up page loads and played on button click.
Please have a look at it and let me know if it helps.
Regards,
Tina Stancheva
Telerik

I cannot get a sound to play on my android app. The mp3 file appears to be located correctly (no error messages upon build)
Is it absolutely necessary to use:
global.media = sound.create("~/sounds/alarm.mp3"); <---- ??
the README docs in nativescript-sound do not indicate that this is a requirement
var tada = sound.create("~/sounds/tada.mp3"); // preload the audio file <---??

Update: the volume on my media player was turned off! My bad. I could hear all the click events (i.e.tap event, list item tap, etc) - so I assumed (never assume!!) that the media sounds would be occurring as well.
So, to recap - sound works. Hurrah!