anhma282 Posted April 12, 2014 Share Posted April 12, 2014 Hello everyone, I am working on a small game using Phaser, the audio works fine on web browser. Then, I used PhoneGap to wrap the game and build it for Android. I used Samsung Galaxy S2 to deploy and test the game, the game work fine but I can't hear sound. I also search on Internet and our forum but I failed to find out the solution. My question is: "We should load audio files by PhoneGap API or load them using Phaser normally?" I also tried put the audio files on Internet instead of project internal but it's still not working. Could you please help me some advices or the sample code for this issues? Thank you for your time and sorry for my English. Link to comment Share on other sites More sharing options...
anhma282 Posted April 13, 2014 Author Share Posted April 13, 2014 Anyone, please help me Link to comment Share on other sites More sharing options...
JP91 Posted April 13, 2014 Share Posted April 13, 2014 what kind of format you are using? anhma282 1 Link to comment Share on other sites More sharing options...
anhma282 Posted April 13, 2014 Author Share Posted April 13, 2014 I tried to use .ogg, .wav but these files are still not working. Thank you for you time, JP91! Link to comment Share on other sites More sharing options...
JP91 Posted April 13, 2014 Share Posted April 13, 2014 is a problem using these wrappers. mmmm... perhaps where the source of sound are located within android-asset. anhma282 1 Link to comment Share on other sites More sharing options...
anhma282 Posted April 13, 2014 Author Share Posted April 13, 2014 Hi JP91, The project structure as below: Then, in the file loader.js within /js directory, I loaded audio files as below:Loader.prototype = { preload:function() { var assets = { ....... audio: { m1: ['m1.wav'], m2: ['m2.wav'], m3: ['m3.wav'] } }; Object.keys( assets ).forEach( function( type ) { Object.keys( assets[type] ).forEach( function( id ) { this.game.load[type].apply( this.game.load, [id].concat( assets[type][id] ) ); }); }); },Am I right, could you please give me the right way for this? Thank you! Link to comment Share on other sites More sharing options...
JP91 Posted April 13, 2014 Share Posted April 13, 2014 I do not think the error is in phaser. mmmm... you aren't using the Media APIs? ,used a little bit console, do not throw any error? anhma282 1 Link to comment Share on other sites More sharing options...
anhma282 Posted April 13, 2014 Author Share Posted April 13, 2014 Hi JP91, Yes, LogCat display error "Failed to open file 'android_asset/www/m1.ogg'. (No such file or directory)". I also tried to edit the path many times but still not success. I enabled plugin media as PhoneGap document<plugin name="Media" value="org.apache.cordova.AudioHandler" />I also search on Internet and still have not the right solution. Could you help me? Thank a lot! Link to comment Share on other sites More sharing options...
plicatibu Posted April 13, 2014 Share Posted April 13, 2014 Looking at the picture you posted I don't see any .ogg file. just .wave files.Haven't you forget to add them? anhma282 1 Link to comment Share on other sites More sharing options...
JP91 Posted April 13, 2014 Share Posted April 13, 2014 that error is another file type? ehh I guess you changed the file,this path change much /android_asset/www/sounds/ or /android_asset/www/audio/. mmmm.. the problem is very frequent attempts to load the audio directly without the api. anhma282 1 Link to comment Share on other sites More sharing options...
anhma282 Posted April 14, 2014 Author Share Posted April 14, 2014 Thank you for your comment. Could you please guide me how to load the audio files using PhoneGap APIs so that I can use them in Phaser code, JP91? I sincerely thank you! Link to comment Share on other sites More sharing options...
anhma282 Posted April 14, 2014 Author Share Posted April 14, 2014 Looking at the picture you posted I don't see any .ogg file. just .wave files.Haven't you forget to add them?I tried to add both wav and ogg files but it still doesn't work Link to comment Share on other sites More sharing options...
JP91 Posted April 14, 2014 Share Posted April 14, 2014 after you have enabled the plugin,you just have to do: var audio = new Media('/android_asset/www/m1.wav');---> audio.play();or this---->http://chrisgriffith.wordpress.com/2014/04/01/edge-animate-phonegap-build anhma282 1 Link to comment Share on other sites More sharing options...
anhma282 Posted April 14, 2014 Author Share Posted April 14, 2014 Anyone have experience on this issue please help me . I sincerely thank you! Link to comment Share on other sites More sharing options...
anhma282 Posted April 14, 2014 Author Share Posted April 14, 2014 after you have enabled the plugin,you just have to do: var audio = new Media('/android_asset/www/m1.wav');---> audio.play();or this---->http://chrisgriffith.wordpress.com/2014/04/01/edge-animate-phonegap-buildThank you JP91, so we cannot use Phaser.Sound class and its methods to control music in the game such as play, pause, resume, ... and must use the PhoneGap to do, am I right? Link to comment Share on other sites More sharing options...
JP91 Posted April 14, 2014 Share Posted April 14, 2014 so is or maybe modifying the loader, I'm thinking about using phonegap with the phaser so trying, what I can say is that this api is working well in android. anhma282 1 Link to comment Share on other sites More sharing options...
anhma282 Posted April 15, 2014 Author Share Posted April 15, 2014 Thank JP91 for your support. Now my game is working fine. The solution is using PhoneGap media APIs instead of Phaser audio methods. Once again, thank you very much! Link to comment Share on other sites More sharing options...
Recommended Posts