cordova - MediaPlayer isPlaying: called in state MEDIA_PLAYER_STATE_ERROR -


i working on app using cordova. in app have 30 pages , should play sound on every swipe. works fine until 20 pages , start getting error

media_player_state_error

based on search on forum believe it's coz of media not being released examples have seen java based. having hard time figuring out call release media.

would appreciate help.thank you.

below current code

function playaudio(src) {         // create media object src     try{       my_media = new media(src,onsuccess,onerror,status_change);                  // play audio                 my_media.play();                  // update my_media position every second                 if (mediatimer == null) {                     mediatimer = setinterval(function() {                         // my_media position                         my_media.getcurrentposition(                             // success callback                             function(position) {                                 if (position > -1) {                                     setaudioposition((position) + " sec");                                 }                             },                             // error callback                             function(e) {                                 console.log("error getting pos=" + e);                                 setaudioposition("error: " + e);                             }                         );                     }, 1000);                 }      } catch (e){     console.log("in catch");          releasemedia();     }    }       function pauseaudio() {         if (my_media) {             my_media.pause();         }     }      // stop audio     //     function stopaudio() {         if (my_media) {             my_media.stop();         }         clearinterval(mediatimer);         mediatimer = null;     }     // onsuccess callback     //     function onsuccess() {         console.log("playaudio():audio success");     }      // onerror callback     //     function onerror(error) {         console.log('code: '    + error.code    + '\n' +               'message: ' + error.message + '\n');               releasemedia();     }     function releasemedia(){          if (my_media) {                     my_media.release();          }          clearinterval(mediatimer);          mediatimer = null;     }  function status_change(code) {     switch (code) {     case media.media_stopped :  console.log("stopped"); break;     case media.media_starting : console.log("starting"); break;     case media.media_running : console.log("running"); break;     case media.media_error: console.log("error");break;     }  } 

error log in logcat

    "starting",   e/mediaplayer? error (-19, 0)  v/mediaplayer? callback application v/mediaplayer? received seek complete v/mediaplayer? seeks complete - return regularly scheduled program  v/mediaplayer? callback  v/mediaplayer? getduration_l 07-13 13:19:35.080  17446-17458/com.aa.apps v/mediaplayer? callback application 07-13 13:19:35.080  17446-17458/com.aa.apps v/mediaplayer? callback  e/mediaplayer? attempt call getduration without valid mediaplayer  v/mediaplayer? message received msg=100, ext1=-38, ext2=0 e/mediaplayer? error (-38, 0) v/mediaplayer? callback application v/mediaplayer? callback v/mediaplayer-jni? getduration: 0 (msec) e/mediaplayer? error (-19,0) d/audioplayer? on completion calling stopped e/mediaplayer? error (-38,0) d/audioplayer? on completion calling stopped v/mediaplayer-jni? getcurrentposition: 0 (msec) e/mediaplayer? isplaying: called in state media_player_state_error v/mediaplayer-jni? isplaying: 0  i/chromium? [info:console(98)] "running",  

adding below code before creating media in playaudio(src) fixed issue.

if(my_media != null){          releasemedia();  } 

Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -