android - Cordova Media stop working -
i tried find solution, have not found solved problem. so, problem pretty basic, there many places found him , many places resolved it. anyway problem that, cordova media plugin after 50-100 played sound has stop working on android 4.2.2
adamos42@a42book:~$ cordova -v 3.5.0-0.2.6 adamos42@a42book:~/place/of/project$ cordova plugins com.badrit.macaddress 0.1.0 "macaddress" com.megster.cordova.bluetoothserial 0.3.0 "bluetooth serial" com.randdusing.bluetoothle 1.0.2 "bluetooth le" org.apache.cordova.battery-status 0.2.10 "battery" org.apache.cordova.device 0.2.11-dev "device" org.apache.cordova.file 1.2.0 "file" org.apache.cordova.file-transfer 0.4.5-dev "file transfer" org.apache.cordova.geolocation 0.3.8 "geolocation" org.apache.cordova.media 0.2.12-dev "media" org.apache.cordova.media-capture 0.3.2-dev "capture" org.apache.cordova.network-information 0.2.11-dev "network information" org.apache.cordova.vibration 0.3.10-dev "vibration"
my code:
var sound = true; var mymedia = null; var mediasrc = ''; var lastsnd = ''; function sound(snd) { if(sound) { lastsnd = snd; mediasrc = "/android_asset/www/sound/"+snd+".mp3"; console.log("media::load('"+mediasrc+"');"); mymedia = new media(mediasrc, media_success, media_error); mymedia.play(); return true; } return false; } function media_success() { console.debug('media::success(\''+lastsnd+'\');'); mymedia.stop(); mymedia.release(); mediasrc = ""; } function media_error(error) { console.error('media::error(): '+json_encode(error)); if(mediasrc != "" && error.message != undefined) alert(error.message); }
so every success media.play() trigger media_success function release media output on android device, program use sound function sereveal times, of times cordova break playback , play lattest sound , every sound trigger media_error error is: {code:0}
i need little have managed use it, problem code? 1 more thing: in logcat output has weird thing:
d/mediaplayer(xxxxx): don't notify duration com.adamos42.application!
now try use way , seems working:
var sound = true; var mymedia = null; var mediasrc = ''; var lastsnd = ''; function sound(snd) { if(sound) { lastsnd = snd; mediasrc = "/android_asset/www/sound/"+snd+".mp3"; console.log("media::load('"+mediasrc+"');"); if(mymedia != null) mymedia.release(); mymedia = new media(mediasrc, media_success, media_error); mymedia.play(); return true; } return false; } function media_success() { console.debug('media::success(\''+lastsnd+'\');'); //mymedia.stop(); //mymedia.release(); mediasrc = ""; } function media_error(error) { console.error('media::error(): '+json_encode(error)); if(mediasrc != "" && error.message != undefined) alert(error.message); }
Comments
Post a Comment