"android MediaPlayer get progress" Code Answer's
You're definitely familiar with the best coding language Whatever that developers use to develop their projects and they get all their queries like "android MediaPlayer get progress" answered properly. Developers are finding an appropriate answer about android MediaPlayer get progress related to the Whatever coding language. By visiting this online portal developers get answers concerning Whatever codes question like android MediaPlayer get progress. Enter your desired code related query in the search bar and get every piece of information about Whatever code related question on android MediaPlayer get progress.
android MediaPlayer get progress
try{
mediaPlayer.start();
seekbar.setProgress(0);
seekbar.setMax(mediaPlayer.getDuration());
// Updating progress bar
seekHandler.postDelayed(updateSeekBar, 15);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
}
/**
* Background Runnable thread
* */
private Runnable updateSeekBar = new Runnable() {
public void run() {
long totalDuration = mediaPlayer.getDuration();
long currentDuration = mediaPlayer.getCurrentPosition();
// Displaying Total Duration time
remaining.setText(""+ milliSecondsToTimer(totalDuration-currentDuration));
// Displaying time completed playing
elapsed.setText(""+ milliSecondsToTimer(currentDuration));
// Updating progress bar
seekbar.setProgress((int)currentDuration);
// Call this thread again after 15 milliseconds => ~ 1000/60fps
seekHandler.postDelayed(this, 15);
}
};
/**
* Function to convert milliseconds time to
* Timer Format
* Hours:Minutes:Seconds
* */
public String milliSecondsToTimer(long milliseconds){
String finalTimerString = "";
String secondsString = "";
// Convert total duration into time
int hours = (int)( milliseconds / (1000*60*60));
int minutes = (int)(milliseconds % (1000*60*60)) / (1000*60);
int seconds = (int) ((milliseconds % (1000*60*60)) % (1000*60) / 1000);
// Add hours if there
if(hours > 0){
finalTimerString = hours + ":";
}
// Prepending 0 to seconds if it is one digit
if(seconds < 10) {
secondsString = "0" + seconds;
}else {
secondsString = "" + seconds;
}
finalTimerString = finalTimerString + minutes + ":" + secondsString;
// return timer string
return finalTimerString;
}
Source: stackoverflow.com
All those coders who are working on the Whatever based application and are stuck on android MediaPlayer get progress can get a collection of related answers to their query. Programmers need to enter their query on android MediaPlayer get progress related to Whatever code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about android MediaPlayer get progress for the programmers working on Whatever code while coding their module. Coders are also allowed to rectify already present answers of android MediaPlayer get progress while working on the Whatever language code. Developers can add up suggestions if they deem fit any other answer relating to "android MediaPlayer get progress". Visit this developer's friendly online web community, CodeProZone, and get your queries like android MediaPlayer get progress resolved professionally and stay updated to the latest Whatever updates.