Jump to content

Audio is not working on Phaser game wrapped by PhoneGap


anhma282
 Share

Recommended Posts

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

Hi JP91,

 

The project structure as below:

 

dxa8.png

 

 

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

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

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

Thank 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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...