I use the following code to play the recorded audio file, it works fine. I have an arrow that shows the progress of the game. I have two static texts, beginning and ending. I need to show the duration of the playback (from 00.00 to the maximum duration) in the initial text and reduce the time from the maximum duration to 00.00. I need to show the progressing time, the remaining time ... Any suggestion ..
private void playAudio () {
// TODO Auto-generated method stub
start.setVisibility (View.VISIBLE);
end.setVisibility (View.VISIBLE);
Context context = getApplicationContext ();
CharSequence text1 = "Your audio will play";
int duration = Toast.LENGTH_SHORT;
Toast toast1 = Toast.makeText (context, text1, duration);
toast1.setGravity (Gravity.CENTER_VERTICAL, 0, 0);
toast1.show ();
String newFolderName = "/ComAudioRecorder";
String extstoredir = Environment.getExternalStorageDirectory()
.toString();
String filename = "/combinedrecaudio.wav";
String path1 = extstoredir + newFolderName + filename;
Log.d("path1", path1);
mPlayer = new MediaPlayer();
try {
mPlayer.setDataSource(path1);
mPlayer.prepare();
mPlayer.start();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
mSeekBar.setMax(mPlayer.getDuration());
new Thread(new Runnable() {
@Override
public void run() {
while (mPlayer != null
&& mPlayer.getCurrentPosition() < mPlayer.getDuration()) {
Log.d("Indide Run Method",Integer.toString(mPlayer.getCurrentPosition()));
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
mSeekBar.setProgress(mPlayer.getCurrentPosition());
start.setText(Long.toString(startTime));
}
}
}).start();
pos=mPlayer.getCurrentPosition();
mSeekBar.setProgress(mPlayer.getCurrentPosition());
pauseRecord.setVisibility(View.INVISIBLE);
resumeRec.setVisibility(View.VISIBLE);
}
source
share