Hi I've read some post with same question but can't find the exact or I must say the answer I've been looking for. Well I just want to know how I can get the playback level of the audio file that is set on the mediaplayer. I already tried the int volume_level = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
but from what I see. I only get the current volume set on my device. Well what I want to achive is to add an animation that follows with level of my audio being played. Here's my code so far:
before the call of play audio method:
audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
the playback method:
public void playAudio(String record_path) throws IOException{
if(audioPlayer!=null && mpStatus == State.Paused){
/*play from paused state*/
audioPlayer.start();
mpStatus = State.Playing;
}
else
{
/*play from start of recording*/
setMediaPlayer(record_path);
audioPlayer.start();
mpStatus = State.Playing;
}
}
and the thread:
private class playBackRunnable extends Thread {
final long start_time = System.currentTimeMillis();
public void run() {
while(chk_play.isChecked()){
try {
Thread.sleep(100);
} catch (InterruptedException e) {
return;
} catch (Exception e) {
return;
}
final long elapsed = System.currentTimeMillis() - start_time;
final String elapsed_time = util.getAsTime((int) elapsed);
runOnUiThread(new Runnable() {
@Override
public void run() {
int volume_level = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
int amp = (int)(volume_level * 100.f)/100;
Log.v("Volume Level", String.valueOf(amp));
if(chk_play.isChecked()){
prog_volume.setProgress(amp);
//txt_rectime.setText(elapsed_time);
if(amp <= 40 ){
prog_volume.setProgressDrawable(getResources().getDrawable(R.drawable.progress_green));
}else if(amp <= 60){
prog_volume.setProgressDrawable(getResources().getDrawable(R.drawable.progress_yellow));
}else if(amp <= 80){
prog_volume.setProgressDrawable(getResources().getDrawable(R.drawable.progress_orange));
}else {
prog_volume.setProgressDrawable(getResources().getDrawable(R.drawable.progress_red));
}
}
}
});
}
}
}
Hope someone can help me with this. Thanks in advance.
EDIT:
Added audioPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
before audioPlayer.prepare() still not working.