Note that there are some explanatory texts on larger screens.

plurals
  1. POchange duration android audio player
    text
    copied!<p>I created an audio player, and I have a class in my project for working with duration. How can one make sure that totalDuration has counted in the opposite direction? </p> <pre><code>public class Utilities { 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 &gt; 0){ finalTimerString = hours + ":"; } // Prepending 0 to seconds if it is one digit if(seconds &lt; 10){ secondsString = "0" + seconds; }else{ secondsString = "" + seconds;} finalTimerString = finalTimerString + minutes + ":" + secondsString; // return timer string return finalTimerString; } public int getProgressPercentage(long currentDuration, long totalDuration){ Double percentage = (double) 0; long currentSeconds = (int) (currentDuration / 1000); long totalSeconds = (int) (totalDuration / 1000); // calculating percentage percentage =((((double)currentSeconds)/totalSeconds)*100); // return percentage return percentage.intValue(); } public int progressToTimer(int progress, int totalDuration) { int currentDuration = 0; totalDuration = (int) (totalDuration / 1000); currentDuration = (int) ((((double)progress) / 100) * totalDuration); // return current duration in milliseconds return currentDuration * 1000; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload