Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As I Understand the problem is about mp.seekTo(posiotion) in onResume() or mp.getCurrentPosition in onPause() method. That exception can because of not initializing the media player. According to the listener when the song finished you make your player stop and released and in onResume on line mp.seekTo(position) caused that exception. Remove mp.release() line in OnCompletion() method and in onResume and onpPause methods. There's another thing you need to do. use a boolean value in your code to understand whether your mediaplayer finished playing or not. Change your onCreat like below:</p> <pre><code>public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.audio); init(); imgVw.setImageResource(R.raw.teddy_two); prefs = PreferenceManager.getDefaultSharedPreferences(this); mp=MediaPlayer.create(Audio_Activity.this,R.raw.ennamo_yadho); Log.e("Song is playing","in Mediya Player "); Log.e("Current ","Position -&gt; " + length); mp.setLooping(false); mp.start(); prefsEdit.putInt("mediaplaying", true); prefsEdit.commit(); btnChapter.setEnabled(false); mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { // TODO Auto-generated method stub mp.stop(); prefsEdit.putInt("mediaplaying", false); prefsEdit.commit(); btnChapter.setEnabled(true); System.out.println("Music is over and Button is enable !!!!!!"); } }); @Override public void onPause() { super.onStop(); SharedPreferences. Editor prefsEdit = prefs.edit(); boolean isPlaying=prefs.getBoolean("mediaplaying",false); if(isPlaying){ int position = mp.getCurrentPosition(); prefsEdit.putInt("mediaPosition", position); prefsEdit.commit(); } } @Override protected void onResume() { super.onResume(); System.out.println("Activity is Resume !!!"); boolean isPlaying=prefs.getBoolean("mediaplaying",false); if(isPlaying){ int position = prefs.getInt("mediaPosition", 0); mp.seekTo(position); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload