How can I play the online music by the Phonegap2.0 in IOS? who can help me??????

695 views
Skip to first unread message

PhoneGap Fans

unread,
Sep 5, 2012, 11:59:45 PM9/5/12
to phon...@googlegroups.com
The Phonegap 2.0 for IOS can play the locale music file ,but can't play the online music file.
 
it shows the error : Failed to initialize AVAudioPlayer
 
the online music file based on the http,such as :http://222.222.222.222/paly.wav
if put "paly.wav" file into the www folder, phonegap can work,

Shazron

unread,
Sep 6, 2012, 12:25:56 AM9/6/12
to phon...@googlegroups.com
Did you add your remote host to the whitelist?:
http://docs.phonegap.com/en/2.0.0/guide_whitelist_index.md.html#Domain%20Whitelist%20Guide
> --
> -- You received this message because you are subscribed to the Google
> Groups "phonegap" group.
> To post to this group, send email to phon...@googlegroups.com
> To unsubscribe from this group, send email to
> phonegap+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/phonegap?hl=en?hl=en
>
> For more info on PhoneGap or to download the code go to www.phonegap.com
>
> To compile in the cloud, check out build.phonegap.com
>
>

PhoneGap Fans

unread,
Sep 6, 2012, 12:37:18 AM9/6/12
to phon...@googlegroups.com
I add the ip into the whilelist in Cordova.plist
:(
 

在 2012年9月6日星期四UTC+8上午11时59分45秒,PhoneGap Fans写道:

Shazron

unread,
Sep 6, 2012, 12:50:27 AM9/6/12
to phon...@googlegroups.com
Check your console log just in case, for any whitelist errors and report back.

PhoneGap Fans

unread,
Sep 6, 2012, 1:10:57 AM9/6/12
to phon...@googlegroups.com
when play the online music, the console log showed :
 
2012-09-06 13:07:13.020 SmartAnswer[6663:13e03] Failed to initialize AVAudioPlayer: The operation couldn't be completed. (OSStatus error 1685348671.)
 
the ip already write into the whilelist
 

在 2012年9月6日星期四UTC+8上午11时59分45秒,PhoneGap Fans写道:

Shazron

unread,
Sep 6, 2012, 1:27:04 AM9/6/12
to phon...@googlegroups.com
Wait a minute, which API call are you using?

PhoneGap Fans

unread,
Sep 6, 2012, 1:59:00 AM9/6/12
to phon...@googlegroups.com
I use the Phonegap 2.0, the API showed as follow
 
media = new Media(uri,playSuccess,playError);
 
 
if i set uri=nocall_db.wav   and put the nocall_db.wav into the www folder,it can work
 

在 2012年9月6日星期四UTC+8上午11时59分45秒,PhoneGap Fans写道:

Shazron

unread,
Sep 6, 2012, 2:56:38 AM9/6/12
to phon...@googlegroups.com
Hmm, not sure. If you can, please file an issue with repro steps at:
https://issues.apache.org/jira/browse/CB

... so it can be tracked and evaluated by the devs, and you can be
notified. We will look at it for v2.2.0

Thanks!

PhoneGap Fans

unread,
Sep 6, 2012, 3:02:47 AM9/6/12
to phon...@googlegroups.com
Shazron Abdullah,  Thank you for your help, 
 
I find the bug in the Phonegap source code and fix it,  it work ok.
 
CDVSound.m  
 
the procedure "prepareToPlay" , the format of filepath is wrong
 
 
NSString* filePath = [NSString stringWithFormat:@"%@/%@.mp3", NSTemporaryDirectory(), uuidString];
 
change to
 
NSString* filePath = [NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), uuidString];
 
 
 
 
 
 

在 2012年9月6日星期四UTC+8上午11时59分45秒,PhoneGap Fans写道:

Shazron

unread,
Sep 6, 2012, 3:16:56 AM9/6/12
to phon...@googlegroups.com
Hmm, that doesn't make sense since a path separator ("/") is needed in
the format to create the temp file in the temp directory. Please file
a bug so this can be investigated.

Shazron

unread,
Sep 6, 2012, 3:23:43 AM9/6/12
to phon...@googlegroups.com
You're right. I just did a quick test and NSTemporaryDirectory()
returns a path with a trailing slash :/ Quite annoying...

Shazron

unread,
Sep 6, 2012, 3:36:11 AM9/6/12
to phon...@googlegroups.com
In my opinion, a better fix would be:

NSString* filePath = [NSString stringWithFormat:@"%@/%@.mp3",
[NSTemporaryDirectory() stringByStandardizingPath], uuidString];

This keeps the string format clear with its purpose, and by
standardizing the path of the temp directory we remove any ambiguity
whether it has a trailing slash or not (since it will always be
removed if it exists).

PhoneGap Fans

unread,
Sep 6, 2012, 4:53:06 AM9/6/12
to phon...@googlegroups.com
OK, thank you
 
I follow you to fix the code, and it work better
 

在 2012年9月6日星期四UTC+8上午11时59分45秒,PhoneGap Fans写道:
Message has been deleted

mankind-nil

unread,
Feb 3, 2013, 4:09:26 PM2/3/13
to phon...@googlegroups.com
In fact, I solved this of course, by simply replacing "mp3" with "m4a" in the above solution for CDVSound.m.

However, this seems less than ideal, I would think we should allow all playable audio formats here (sorry I don't know enough about the architecture to suggest something more specific...).

Thanks

Daniel

db746...@gmail.com

unread,
Jun 25, 2013, 3:57:51 PM6/25/13
to phon...@googlegroups.com
I had the same issue using an old version of PhoneGap (2.2) with an iOS application.  Turns out it's a bug in the older version of PhoneGap as other posters have said.  I removed the ".mp3" from the Sound.m file as per other posts and it works great with URL pointing to wav file.

Thanks everyone for your help!
Reply all
Reply to author
Forward
0 new messages