Hi,
I am working on a media player for android.
I know that a thread should constantly run in order to take the current position of the audio.
String file = audioFile.getAbsolutePath();
mp.reset();
mp.setDataSource(file);
mp.prepare();
if (last_pos > 0) {
mp.seekTo(last_pos);
}
// the media could be just prepared.
if (media.isAutoPlay()) {
mp.start();
}
mp.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(final MediaPlayer mp) {
mHandler.post(new Runnable() {
@Override
public void run() {
int position;
int duration = mp.getDuration();
do {
try {
info.setText(app.getInfo());
position = mp.getCurrentPosition();
Thread.sleep(1000);
} catch (Exception ex) {
break;
}
} while (mp.isPlaying() && position <= duration);
}
});
}
});
Open in new window
any ideas?