android - MediaPlayer: Error (1,-2147483648) in Cordova 6.1.1 with Phaser 2.4.6 -


i trying play audio files on android game built cordova 6.1.1 , phaser.io 2.4.6. media not play on android versions less api 21 or so, , gives error

04-21 21:48:57.546 9659-9671/com.jtronlabs.birdu e/mediaplayer: error (1, -2147483648) 04-21 21:48:57.546 9659-9672/com.jtronlabs.birdu e/mediaplayer: error (1,-2147483648) 

i have read answers, , nothing has helped. load in audio using phaser's loader class:

this.load.audio('background-music', this.arrayofcompatiblemusicfilenames('the_plucked_bird') );  

...

//phaser has support load in multiple types of audio formats if first supplied in array not compatible browser. arrayofcompatiblemusicfilenames: function(key){   //old versions of android don't play music, require absolute pathname (instead of relative). generic solution   //https://stackoverflow.com/questions/4438822/playing-local-sound-in-phonegap?lq=1   var path = window.location.pathname;   path = path.substr( 0, path.lastindexof("/")+1 ); //need remove 'index.html' end of pathname   var aud = path+'assets/audio/';    //aud = '/android_res/raw/'   var wav = aud + 'wav/';   var ogg = aud + 'ogg/';   var mp3 = aud + 'mp3/';    console.log(mp3+key+".mp3");    return [mp3+key+".mp3",ogg+key+".ogg",wav+key+".wav"]; }, 

this works in browser, , on newer versions of android. on older versions have attempted add multiple formats, absolute path, external write permissions $project_root/platforms/android/androidmanifest.xml, , moving files /www $project_root/platforms/android/res/raw.

all naught. ideas on going wrong?

edit: when audio files in 'res' folder, reference them such:

arrayofcompatiblemusicfilenames: function(key){   return ['/android_res/raw/'+key+".ogg"]; } 

which works on api 21 not 19 or below (just first function).

i have gotten audio working using cordova-plugin-media.

var path = window.location.pathname; path = path.substr( 0, path.lastindexof("/")+1 ); //need remove 'index.html' end of pathname var aud = path+'assets/audio/';  var ogg = aud + 'ogg/' + key + ".ogg";  //works! var snd = new media(ogg); snd.play(); 

however, discovered 'normal' way of doing causes bad behaviour.

//does not work... phaser uses internally var snd = new audio(ogg); snd.play(); 

it seems have write code test if browser or cordova, , use 'media' or 'audio' respectively.

update: wrote code , makes things messy, works. nowadays use crosswalk, , webaudio works on devices. no need media plugin , case-checking in code.


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -