Retrieve the duration from the onPrepared callback...this will ensure the music(audio) is properly loaded before you attempt to get it's duration.
song.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer song) {
int duration = song.getDuration();
song.start();
controller.show();
}
});
StopSong():
private void StopSong() {
if (song != null) {
song.stop();
song.release();
}
}
for the duration text field, i will used global variable to access from all functions.
@Override
protected void onCreate(Bundle savedInstanceState) {
int totalDuration 0;
.
.
.
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
mHandler.removeCallbacks(mUpdateTimeTask);
totalDuration = song.getDuration(); // here
.
.
.
private void StopSong() {
if (song!=null) {
song.stop();
song.release();
totalDuration = 0; // here
}
i hope this helps!