This is a migrated thread and some comments may be shown as answers.

NativeScript need to add mp3 files to Android package

5 Answers 205 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Samir
Top achievements
Rank 1
Samir asked on 14 Jan 2016, 04:32 PM

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

Sort by
0
Tina Stancheva
Telerik team
answered on 19 Jan 2016, 04:20 PM
Hello Samir,

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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Samir
Top achievements
Rank 1
answered on 19 Jan 2016, 08:21 PM

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

0
Tina Stancheva
Telerik team
answered on 20 Jan 2016, 12:22 PM
Hello 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.
If you have to play a longer or larger file, I would recommend that you use an older version of the module where the Android implementation uses MediaPlayer.

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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
michael
Top achievements
Rank 1
answered on 16 Feb 2016, 04:50 PM

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  <---??

 

0
michael
Top achievements
Rank 1
answered on 16 Feb 2016, 07:04 PM

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!

Tags
General Discussions
Asked by
Samir
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Samir
Top achievements
Rank 1
michael
Top achievements
Rank 1
Share this question
or