PhoneGap Media API (cannot get audio to work on IOS using it)

1,345 views
Skip to first unread message

Raffeg

unread,
Feb 27, 2012, 7:46:43 PM2/27/12
to phonegap
Hi,

I am making apps for IOS and Android (using PhoneGap) and I have a
functioning set for playing audio basically on any browser. I should
be satisfied and stop right here but I cannot:
I would like to use the PhoneGap Media object for both Android and
IOS. I had it working right off with Android like so:
Creating the Media Object e.g. at init
var soundSrc = "/android_asset/www/audio/soundclip.m4a;
soundObject = new Media( soundSrc, onSuccess, onError, null, null );

The playing my different clips somewhere else ( here the clips are
a.m4a, b.m4a, c.m4a etc. - the letter variable contains the letter
constructing the filename for the clip to be played)
...
soundObject.src = "/android_asset/www/audio/letters/" + letter +
"m4a";
soundObject.play();
...

I would like to do the same on IOS but I haven't been able to figure
out the path to my clips despite all advice I have run over so far. I
tried absolute path's, I tried file:///, http://localhost, http://127.0.0.1.
PhoneGap (js) produces a pop-up with the message:

gap:["Media","startPlayingAudio","Media1","true"]

together with a message containing an "ID-string","Mypath" like so:
["33c503dd7-fc2a-067a--7ea8-365d01271740","/audio/letters/y.m4a"]

Any ideas?

If not I guess I continue using the HTML5 part of my audio function.

/Ralf

Devgeeks

unread,
Feb 27, 2012, 10:19:43 PM2/27/12
to phon...@googlegroups.com
If the file is in your www folder (www/audio like your example), try using a relative URL like you would for images, etc.

var soundSrc = "audio/a.m4a"

Raffeg

unread,
Feb 28, 2012, 7:05:49 AM2/28/12
to phonegap
Hi,

My audiofiles are in the "www" folder as shown in the above example
and I adress them exactly as you suggest:

var soundSrc ="/audio/letters/a.m4a";

and it does not work. I get that pop-up I mentioned in the previous
post and no sound.

I also noted that "notification" and in my case "vibrate" does not
work either.

Could this problem have to do with an upgrade from an earlier PG to
PG 1.3 without having
taken care of the upgrade properly?

/Ralf

On 28 Feb, 04:19, Devgeeks <to...@devgeeks.org> wrote:
> If the file is in your www folder (www/audio like your example), try using
> a relative URL like you would for images, etc.
>
> var soundSrc = "audio/a.m4a";
>
>
>
>
>
>
>
> On Tuesday, 28 February 2012 11:46:43 UTC+11, Raffeg wrote:
>
> > Hi,
>
> > I am making apps for IOS and Android (using PhoneGap) and I have a
> > functioning set for playing audio basically on any browser. I should
> > be satisfied and stop right here but I cannot:
> > I would like to use the PhoneGap Media object for both Android and
> > IOS. I had it working right off with Android like so:
> > Creating the Media Object e.g. at init
> >   var soundSrc = "/android_asset/www/audio/soundclip.m4a;
> >   soundObject = new Media( soundSrc, onSuccess, onError, null, null );
>
> > The playing my different clips somewhere else ( here the clips are
> > a.m4a, b.m4a, c.m4a etc. - the letter variable contains the letter
> > constructing the filename for the clip to be played)
> > ...
> > soundObject.src = "/android_asset/www/audio/letters/" + letter +
> > "m4a";
> > soundObject.play();
> > ...
>
> > I would like to do the same on IOS but I haven't been able to figure
> > out the path to my clips despite all advice I have run over so far. I
> > tried absolute path's, I tried file:///,http://localhost,
> > tried absolute path's, I tried file:///,http://localhost,

Raffeg

unread,
Feb 29, 2012, 5:04:12 AM2/29/12
to phonegap
Hi,

I cleaned out XCODE, upgraded to PG 1.4.1, moved in my HTML5 apps and
reconfigured data from scratch and everything is working: MediaObject,
Notifications everything.

It must have gone wrong when i upgraded from from PG 1.2 to PG 1.3. I
was not aware of everything I needed to do at that time.

Anyway,

A big Thanks for your support,

/Ralf

On 28 Feb, 04:19, Devgeeks <to...@devgeeks.org> wrote:
> If the file is in your www folder (www/audio like your example), try using
> a relative URL like you would for images, etc.
>
> var soundSrc = "audio/a.m4a";
>
>
>
>
>
>
>
> On Tuesday, 28 February 2012 11:46:43 UTC+11, Raffeg wrote:
>
> > Hi,
>
> > I am making apps for IOS and Android (using PhoneGap) and I have a
> > functioning set for playing audio basically on any browser. I should
> > be satisfied and stop right here but I cannot:
> > I would like to use the PhoneGap Media object for both Android and
> > IOS. I had it working right off with Android like so:
> > Creating the Media Object e.g. at init
> >   var soundSrc = "/android_asset/www/audio/soundclip.m4a;
> >   soundObject = new Media( soundSrc, onSuccess, onError, null, null );
>
> > The playing my different clips somewhere else ( here the clips are
> > a.m4a, b.m4a, c.m4a etc. - the letter variable contains the letter
> > constructing the filename for the clip to be played)
> > ...
> > soundObject.src = "/android_asset/www/audio/letters/" + letter +
> > "m4a";
> > soundObject.play();
> > ...
>
> > I would like to do the same on IOS but I haven't been able to figure
> > out the path to my clips despite all advice I have run over so far. I
> > tried absolute path's, I tried file:///,http://localhost,
> > tried absolute path's, I tried file:///,http://localhost,

Devgeeks

unread,
Feb 29, 2012, 3:56:08 PM2/29/12
to phon...@googlegroups.com
Awesome. Glad it's working.

AaronOnTilt

unread,
Mar 1, 2012, 1:31:14 PM3/1/12
to phonegap
Is anyone aware of how to use the media object (or any other method)
to enable multitasking audio for ios and android?

Devgeeks

unread,
Mar 1, 2012, 5:26:07 PM3/1/12
to phon...@googlegroups.com
HTML5/JavaScript Audio (and I believe the Media API, though I used JS) on iOS play background audio just fine.

In iOS you have to set the allowed background modes as per iOS developers documentation: 

"Support for some types of background execution must be declared in advance by the app that uses them. An app declares support for a service using its Info.plist file. Add the UIBackgroundModes key to your Info.plist file and set its value to an array containing one or more of the following strings:

audio—The app plays audible content to the user while in the background. (This content includes streaming audio or video content using AirPlay.)"

As for Android, I used the Media API and didn't have to do anything in particular to support playing in the background there.
Reply all
Reply to author
Forward
0 new messages