简体   繁体   中英

Phaser not making any sound on Android

I have this code for making sounds in my game built using Phaser which runs inside a browser on iOS and Android applications (wrappers).

While working fine on iOS, on Android I'm getting error messages and no sound at all when running the app in a webview.

My code:

preload:function() {
    game.load.audio('blast', 'assets/audio/blast.mp3');
    game.load.audio('collect_coin', 'assets/audio/Coin.mp3');

...

create:function() {         
    game.physics.startSystem(Phaser.Physics.ARCADE);
    blast=game.add.audio('blast');
    collect_coin=game.add.audio('collect_coin');

...

blast.play();

The error message from the console:

E/MediaPlayer﹕ error (1, -2147483648)

When loading the files form a URL ( http://.. .) there is a sound although its not working well... (and I want the files to load locally anyway.)

Some browsers don't support MP3, usually the best option to support most browsers is to have both an OGG & an MP3 version of the sound, and provide them both in a game.add.audio('my', ['my.mp3', 'my.ogg']) call.

As the docs say , Phaser is clever enough to only actually load the first compatible file it finds, so don't worry about load time issues.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM