android - on Pause starts audio from starting not where i paused -


this code, using pause song , play has been left, playing song starting not has been paused, why ?

private mediaplayer mediaplayer;  mediaplayer = new mediaplayer();  public void play(){                try {                 mediaplayer.reset();                 mediaplayer.setdatasource(strnurl);             } catch (illegalargumentexception e) {             } catch (securityexception e) {             } catch (illegalstateexception e) {             } catch (ioexception e) {                 e.printstacktrace();             }             try {                 mediaplayer.prepare();             } catch (illegalstateexception e) {             } catch (ioexception e) {             }             mediaplayer.start();                ....................        }         public void pause(){            mediaplayer.pause();           btnpause.setenabled(false);           btnplay.setenabled(true);        } 

i have placed whole code, allowing user tap on of item in listview.

this problem due reseting mediaplayer on play method remove mediaplayer.reset();

for more

you can use methods getcurrentposition play last position

     public void pause(){       current_position=mediaplayer.getcurrentposition();           mediaplayer.pause();           btnpause.setenabled(false);           btnplay.setenabled(true);        }         public void play(){           mp.prepare();            mp.seekto(current_position);          mp.start();         } 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -