Re: PhoneGap 2.0.0 Local Audio Failed to Play

394 views
Skip to first unread message

Caleb Qian

unread,
Jul 24, 2012, 10:46:04 AM7/24/12
to phon...@googlegroups.com
Follow-ups:

I confirmed many times that this problem occurs on PhoneGap 2.0.0. I am building my Android app using API level 16, minimum API level 8. It was tested on a simulator at API level 10. 
The source file is placed beneath '/android_asset/www/', which is a playable mp3 audio file.

Behavior:
  • No sound has been played
  • when I manually stop the music by triggering the click event of a "stop" button, the error function is invoked and "Audio Error" alert message is shown.
Notice: when I was degrading the PhoneGap to 1.9.0 and deploy the application immediately, the simulator neither play music nor throw error message. This is due to simulator issue. The simulator has to be restarted without launching from snapshot.

Best regards,
Caleb

On Tuesday, July 24, 2012 1:10:56 AM UTC-5, Caleb Qian wrote:
Hi, recently I am working on playing an local audio on Android PhoneGap. It was working on the version 1.9.0 using the path prefixed with 'android_assets/www/'. Today I just feel it might be better for future work, I upgraded the PhoneGap version to 2.0.0, and the local audio play does not work any longer.

I am pretty sure it was working last time on 1.9.0. I double-checked the logCat and there was no JS loading or syntax errors. The behavior is that no sound is going to be played, and the error handler will be invoked after I trigger the stop function.  In addition, the audio given by a HTTP URL is fine. Apparently there is something messed up with the path. 

Here is my essential segment of code:

function error_error(e) {
alert('Audio Play Error.');
alert(e.message);
}

function playAudio(src) {
if (device.platform == 'Android') {
src = '/android_asset/www/' + src;
}

my_media = new Media(src, success, error_error);

$("#status_title").text('Sensing');
$("#status_text")
.text(
'System is sensing the sensor... Press stop button when you want to stop this process.');
$("#inner_start").hide();
$("#inner_stop").show();

my_media.play();
}

// play audio main function, callback function and exception handler

$('#inner_start').live('vclick', function(e) {

// alert('inner start tapped.');

playAudio('Nokia_Tune_Dubstep_Edition.mp3');

return false;
});

duke

unread,
Jul 24, 2012, 4:58:24 PM7/24/12
to phon...@googlegroups.com
I'm having the same issue.  The audio was working fine in Cordova 1.8.

Kerri Shotts

unread,
Jul 24, 2012, 5:49:10 PM7/24/12
to phon...@googlegroups.com, phon...@googlegroups.com
Logs? That might show something useful.

______________________________
Kerri Shotts
photoKandy Studios LLC

📱 Phone: +1 (312) 380-1035
🌐 Web: http://photokandy.com 

Twitter: @photokandy

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

Simon MacDonald

unread,
Jul 25, 2012, 4:02:06 PM7/25/12
to phon...@googlegroups.com
I tried to reproduce this today using 2.0.0 and the following sources:

/android_asset/www/test.mp3

../../data/data/com.ibm.filcontact/test.mp3

/data/data/com.ibm.filcontact/test.mp3

http://audio.ibeat.org/content/p1rj1s/p1rj1s_-_rockGuitar.mp3

and I could not reproduce.

Caleb Qian

unread,
Jul 26, 2012, 8:34:28 PM7/26/12
to phon...@googlegroups.com
Hi Simon, 

I still have no clue why this stop working here. To find the reason of this problem, I upgraded to 2.0.0 again to pull the log out. I gave a shorter name for the mp3 file I am trying to play, which is temp.mp3. 

07-27 00:29:47.982: D/CordovaLog(918): Manifested src string: /android_asset/www/temp.mp3
07-27 00:29:47.982: D/CordovaLog(918): file:///android_asset/www/index_tool.js: Line 145 : Manifested src string: /android_asset/www/temp.mp3
07-27 00:29:47.982: I/Web Console(918): Manifested src string: /android_asset/www/temp.mp3 at file:///android_asset/www/index_tool.js:145
07-27 00:29:47.991: D/CordovaLog(918): before: null
07-27 00:29:47.991: D/CordovaLog(918): file:///android_asset/www/index_tool.js: Line 150 : before: null
07-27 00:29:47.991: I/Web Console(918): before: null at file:///android_asset/www/index_tool.js:150
07-27 00:29:48.021: D/CordovaLog(918): [object Object]
07-27 00:29:48.021: D/CordovaLog(918): file:///android_asset/www/index_tool.js: Line 154 : [object Object]
07-27 00:29:48.021: I/Web Console(918): [object Object] at file:///android_asset/www/index_tool.js:154
07-27 00:29:48.091: I/Deprecation Notice(918): Replace ctx.getActivity() with cordova.getActivity()
07-27 00:29:48.121: D/AudioPlayer(918): Send a onStatus update for the new seek

It looks like the app found the file, but there is just no sound being played. I also checked the emulator, audio playback/recording are both turned on. In addition, I checked /res/xml/config.xml, the audio handler is there. Permissions also include all necessary configurations such as WRITE_TO_EXTERNAL_STORAGE.

I cannot find a difference from the log recorded at a normal playing. I can play online music through the HTTP URL, but not local audio files.

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
 
 

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

Simon MacDonald

unread,
Jul 26, 2012, 10:43:44 PM7/26/12
to phon...@googlegroups.com
Yeah, something odd is going on in Media. Can you raise an issue in JIRA with your reproduction scenario and as many details as you can. Another PG dev will take a look at it as I'm currently on vacation.
 

Caleb Qian

unread,
Aug 5, 2012, 1:08:59 PM8/5/12
to phon...@googlegroups.com
An update to this issue:

I submit an issue in the Apache project and it cannot be successfully reproduced with the latest build. 
I downloaded the latest build on Github updated 16 days ago. The sound can be successfully played on a device, but still I cannot play it on an emulator. playback and recording support are turned on.

In addition, on the new device HTC 4.0.3 I got, the success function was never called after the completion of the sound play. Here is another new post I talked about this problem: 

Thank you very much for your help, Simon!

Caleb Qian

unread,
Aug 5, 2012, 1:12:10 PM8/5/12
to phon...@googlegroups.com
Correction:

The sound can be played on a 4.0.3 emulator, but not a 2.3 one. It works on a 4.0(HTC One X) and a 2.2 device(MOTO XT 800), so I assume this method can work for most of the devices including a 2.3 one. 
Reply all
Reply to author
Forward
0 new messages