Jump to content

Sound doesn't play on Android web browser


monteBorja
 Share

Recommended Posts

Hi everybody,

   I'm developing a game using Phaser 2.4.4. In my desktop web browsers (Chrome & Mozilla) the sound works fine but when I test it on Android web browser (Chrome), it doesn't work.

//MainActivity.java
protected void onCreate(Bundle savedInstanceState)
{
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_main);

   WebView myWebView = (WebView) this.findViewById(R.id.webView);

   // Enable JavaScript
   WebSettings webSettings = myWebView.getSettings();
   webSettings.setJavaScriptEnabled(true);
   webSettings.setAllowFileAccess(true);
   webSettings.setAllowFileAccessFromFileURLs(true);
   webSettings.setAllowUniversalAccessFromFileURLs(true);
   webSettings.setAllowContentAccess(true);
   webSettings.setLoadsImagesAutomatically(true);

   // Load HTML page
   myWebView.loadUrl("file:///android_asset/index.html");
}
//PreloadGame.js
preload: function()
{
   this.load.audio("TapSound", ["Common/sounds/TapButton.mp3","Common/sounds/TapButton.ogg"]);
}, // preload

update: function()
{
   if (this.cache.isSoundDecoded("TapSound") && !this.m_ready)
   {
      this.m_ready = true;
      this.state.start("Menu");
   }
}, // update

//Menu.js
create: function()
{
   this._tapSound = this.add.sound("TapSound");
}, // create

onClickButton: function()
{
   this._tapSound.play();
},

   I have used .mp3 and .ogg with these bitrates: 64, 128, 192, 320

   I've got the next error in the logcat.

04-19 10:41:06.366 24333-24333   I/chromium: [INFO:CONSOLE(11)] "%c %c %c Phaser v2.4.4 | Pixi.js v2.2.9 | Canvas | HTML Audio  %c %c %c http://phaser.io %c?%c?%c?", source: file:///android_asset/phaser.min.js (11)
04-19 10:41:08.408 24333-24333   I/chromium: [INFO:async_pixel_transfer_manager_android.cc(60)] Async pixel transfers not supported
04-19 10:55:33.712 24333-24333   V/MediaPlayer-JNI: native_setup
04-19 10:55:33.712 24333-24333   V/MediaPlayer: constructor
04-19 10:55:33.722 24333-24333   V/MediaPlayer: setListener
04-19 10:55:33.722 24333-24345   V/MediaPlayer: message received msg=8, ext1=0, ext2=0
04-19 10:55:33.722 24333-24333   V/MediaPlayer: setVideoSurfaceTexture
04-19 10:55:33.732 24333-24333   V/MediaPlayer: prepareAsync
04-19 10:55:33.732 24333-24345   V/MediaPlayer: unrecognized message: (8, 0, 0)
04-19 10:55:33.732 24333-24345   V/MediaPlayer: callback application
04-19 10:55:33.732 24333-24345   V/MediaPlayer: back from callback
04-19 10:55:33.732 24333-24345   V/MediaPlayer: message received msg=100, ext1=1, ext2=-2147483648
04-19 10:55:33.732 24333-24345   E/MediaPlayer: error (1, -2147483648)
04-19 10:55:33.732 24333-24345   V/MediaPlayer: callback application
04-19 10:55:33.732 24333-24345   V/MediaPlayer: back from callback
04-19 10:55:33.732 24333-24333   E/MediaPlayer: Error (1,-2147483648)

   How can I solve this error?

Thanks

Link to comment
Share on other sites

hi,

your need a httpServer to load sound file, 

Through the HTTP protocol,Rather than file agreement

The problem here:

   myWebView.loadUrl("file:///android_asset/index.html");

If you still don't understand where is the problem, can be your game index.html The into chrome,

also using the file read agreement, (address is' file / / ').Then look at the console, throws a similar to

Phaser. Js: 71935 XMLHttpRequest always load file:///xxx/xxx/xx/sound/great.mp3. Cross origin requests are only supported for protocol schemes: HTTP, data, chrome, chrome - the extension, HTTPS, chrome - the extension - the resource.The error

 

Link to comment
Share on other sites

 

   Hi lixin2628,

      Thanks for the response. So, I have to put the http address inside the function like myWebView.loadUrl("http://example.com/game/index.html"); Is this the only way?

      The game haven't got an http address because the game is hosted in no server. The game will be in a WebView inside another android app.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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