Android : android mediaplayer song play skip and jumping

on Thursday, July 31, 2014


I have build an android application, in a particular module i have used media player class to play songs. Sometimes the songs get skipping and jumping a bit when we play the songs via application. Can anyone please assist us with this, thanks. seekbar.setOnSeekBarChangeListener(new seekchange()); public class seekchange implements SeekBar.OnSeekBarChangeListener { public void onStopTrackingTouch(SeekBar arg0) { // TODO Auto-generated method stub }



public void onStartTrackingTouch(SeekBar arg0)
{
// TODO Auto-generated method stub

}
public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser)
{
// TODO Auto-generated method stub
if (fromUser)
{
mp.seekTo(progress);
seekBar.setProgress(progress);
}
}
}
//seekbar song listenet
public class setp implements MediaPlayer.OnPreparedListener
{
public void onPrepared(MediaPlayer mps)
{
// TODO Auto-generated method stub
seekbar.setMax(mp.getDuration());
System.out.println("Total Duration Mp3" + mp.getCurrentPosition());

new Thread(new Runnable()
{
public void run()
{
try
{
while(mp!=null && mp.getCurrentPosition()<mp.getDuration())
{
seekbar.setProgress(mp.getCurrentPosition());
Message msg=new Message();
int millis = mp.getCurrentPosition();

msg.obj=millis/1000;

try
{
Thread.sleep(100);
}
catch (InterruptedException ie)
{
System.out.println("InterruptedException SeekBar" + ie);
}
catch (IllegalMonitorStateException imse)
{
System.out.println("IllegalMonitorStateException SeekBar" + imse);
}
catch (IllegalStateException ise)
{
System.out.println("IllegalStateException SeekBar" + ise);
}
catch (Exception e)
{
System.out.println(" Exception SeekBar" + e);
}

}
} catch (IllegalStateException e)
{

System.out.println("seekbar out IllegalStateException" + e);
}
catch (IllegalMonitorStateException e)
{
System.out.println("seekbar out IllegalMonitorStateException" + e);
}
catch (Exception e) {
System.out.println("Exception seekbar" + e);
}
}
}).start();

}
}


`


0 comments:

Post a Comment