android - MediaPlayer onCompletionListener called while paused -


my media player reason completes while paused. have seen post said being async , 300ms difference , understand. main problem have 20 seconds left on video , while paused finishes after 20 seconds run out. here relevant code might have messed on:

    private void initplayer() {     try {         if(videofile != null)         {              afd = getassets().openfd(videofile);              instructionvideoplayer = new mediaplayer();              instructionvideoplayer.setdatasource(afd.getfiledescriptor(), afd.getstartoffset(), afd.getdeclaredlength());              instructionvideoplayer.setdisplay(holder);              instructionvideoplayer.prepare();             log.i("instruction video", "videoprepared");             instructionvideoplayer.setoncompletionlistener(instructionvideocomplete);             instructionvideoplayer.setonpreparedlistener(this);         }      } catch (illegalargumentexception e) {         e.printstacktrace();     } catch (illegalstateexception e) {         e.printstacktrace();     } catch (ioexception e) {         log.i(this.tostring(), "ioexception");         e.printstacktrace();         //initplayer();     } catch (exception e)     {         log.i("initplayer", e.getclass().tostring());         e.printstacktrace();     }      restoreoverlaystate(); } 

the listeners:

    mediaplayer.oncompletionlistener instructionvideocomplete = new mediaplayer.oncompletionlistener() {      public void oncompletion(mediaplayer arg0) {         log.i("oncompletion", "called");         if(!videofile.contentequals(langselect.instruction_05))         {             intent returnintent = new intent();             returnintent.putextra(langselect.action, langselect.go_video_next);             setresult(result_ok, returnintent);             continueplaying = true;             tofinish();          }         else             tofinish();     } };  public void onprepared(mediaplayer mediaplayer)  {     playvideo(); } 

the play , pause functions

    private void playvideo() {     instructionvideoplayer.seekto(pausedat);     instructionvideoplayer.start();     restoreoverlaystate(); } private void pausevideo() {     pausedat = instructionvideoplayer.getcurrentposition();     instructionvideoplayer.pause(); }  private void restoreoverlaystate() {     prefs = getsharedpreferences(save_prefs, context.mode_private);      if(prefs.getboolean(is_paused, false))     {         pauseoverlay.setvisibility(view.visible);         pausevideo();     }     else     {         pauseoverlay.setvisibility(view.gone);     } } 

edit: happens on nexus s (2.3.3) 1 of phones testing on. other galaxy s(froyo) not have error.

i figured out doing wrong. oncompletionlistener being called. problem was running 2 media players , setting same oncompletionlistener them accidentally calling initplayer twice. once in surfacecreated , again @ end of onresume(). either galaxy s messed or has weird error checking becasue problem didnt show there.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -