Attempt to call getDuration without a valid mediaplayer  in media player on android
<p>i am playing song from sdcard with seek bar. while getting duration of song i get <strong>Attempt to call getDuration without a valid mediaplayer and illegal state exception</strong>. the filename and path  is valid one.i tried long time i could not get solution. and how to move seek bar while playing song.please help me.
my code:</p>

<pre><code>Button play,pause,stop;
SeekBar seek;
MediaPlayer mediaPlayer;
SurfaceView sv;
boolean isPlaying = false;

    play.setOnClickListener(new View.OnClickListener() 
    {   
        public void onClick(View v) 
        {
            playsong(filename); 
        }
    });


private void playsong(String filename2) {
    try{
        Log.e("filename2",filename2);
        mediaPlayer = new  MediaPlayer();
        mediaPlayer.setDataSource(filename2);
        seek.setMax(mediaPlayer.getDuration());
        mediaPlayer.prepare();
        mediaPlayer.start();
        myHandler.post(runn);
        isPlaying = true;
        mediaPlayer.setOnCompletionListener(this);          
    }
    catch(Exception ex){
        Log.e("sdcard-err2:",""+ex);
    }

}

private Handler myHandler = new Handler();
    final Runnable runn = new Runnable()
    {
        public void run() 
        {
            if (mediaPlayer != null) 
            {
                if (isPlaying ) 
                {
                    try 
                    {
                       int currentPosition = mediaPlayer.getCurrentPosition();

                       seek.setProgress(currentPosition);

                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                    sv.postDelayed(runn, 150);
                }
            }
        }

    };  
</code></pre>

<p>my log cat errors:</p>

<pre><code>05-17 09:46:43.578: ERROR/filename2(1670): /sdcard/The Dance Theme.mp3
05-17 09:46:43.594: ERROR/MediaPlayer(1670): Attempt to call getDuration without a valid mediaplayer
05-17 09:46:43.594: ERROR/MediaPlayer(1670): error (-38, 0)
05-17 09:46:43.594: ERROR/MediaPlayer(1670): prepareAsync called in state 0
05-17 09:46:43.594: ERROR/sdcard-err2:(1670): java.lang.IllegalStateException
05-17 09:46:43.594: ERROR/MediaPlayer(1670): Error (-38,0)
</code></pre>
