Page 1 of 1

Run a sound file located on client phone with javascript

Posted: Wed Oct 09, 2013 3:48 pm
by osiris1@yahoo.com

Hello. I'm finishing up my app and have a question...

I need to run a sound file on the client handset (iphone). How would I go about doing this in javascript?

I have a timer app, at a set time, the app needs to run a specific WAV file that is located on the users phone. Can you show me the simple code to do this?

Thanks.


Run a sound file located on client phone with javascript

Posted: Wed Oct 09, 2013 4:38 pm
by Kateryna Grynko

Hi,

There are two ways to implement this:

1) Via PhoneGap http://docs.phonegap.com/en/2.7.0/cor...

2) Using 'audio' HTML tag
code<audio src="URL"><&#47;audio>/codewhere URL is a link to audio file.


Run a sound file located on client phone with javascript

Posted: Wed Oct 09, 2013 5:17 pm
by osiris1@yahoo.com

Thanks Katya. But these examples assumes that the audio file lives on a server. Is there anyway to have it look locally, like where all your other music files are stored?


Run a sound file located on client phone with javascript

Posted: Wed Oct 09, 2013 6:58 pm
by Kateryna Grynko

Please take a look at the instruction:

order of file search

When only a file name or simple path is provided, iOS will search in the www for the file and then in the application documents/tmp directory.

codevar myMedia = new Media("audio&#47;beer&#46;mp3")
myMedia&#46;play() &#47;&#47; will first look for file in www&#47;audio&#47;beer&#46;mp3 then in <application>&#47;documents&#47;tmp&#47;audio&#47;beer&#46;mp3/code


Run a sound file located on client phone with javascript

Posted: Thu Oct 10, 2013 2:53 pm
by osiris1@yahoo.com

Since I'm testing my appery app as a web app, how would it know to check /documents/tmp/audio/

Should I upload the file to my appery project?


Run a sound file located on client phone with javascript

Posted: Thu Oct 10, 2013 4:04 pm
by Kateryna Grynko

Hi,

For testing you can upload a file to database, but local path for iPhone should be specified just before testing on device.