更改android音频播放器的持续时间
我创建了一个音频播放器,在我的项目中有一个类用于处理持续时间。如何确保totalDuration的计数方向相反更改android音频播放器的持续时间,android,audio,duration,Android,Audio,Duration,我创建了一个音频播放器,在我的项目中有一个类用于处理持续时间。如何确保totalDuration的计数方向相反 public class Utilities { public String milliSecondsToTimer(long milliseconds){ String finalTimerString = ""; String secondsString = ""; // Convert total duration into time int ho
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 > 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;
}
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;
}
}
公共类实用程序{
公共字符串毫秒计时器(长毫秒){
字符串finalTimerString=“”;
字符串secondssString=“”;
//将总持续时间转换为时间
整数小时=(整数)(毫秒/(1000*60*60));
整数分钟=(整数)(毫秒%(1000*60*60))/(1000*60);
整数秒=(整数)((毫秒%(1000*60*60))%(1000*60)/1000);
//如果有,请加上小时数
如果(小时数>0){
finalTimerString=hours+“:”;
}
//如果是一位数字,则在0到秒之前加上前缀
如果(秒<10){
secondsString=“0”+秒;
}否则{
secondsString=”“+秒;}
finalTimerString=finalTimerString+minutes+“:”+secondsString;
//返回计时器字符串
返回finalTimerString;
}
public int getProgressPercentage(长currentDuration、长totalDuration){
双倍百分比=(双倍)0;
长currentSeconds=(int)(currentDuration/1000);
长总秒数=(整数)(总持续时间/1000);
//计算百分比
百分比=((双倍)当前秒数)/总秒数)*100);
//回报率
返回百分比;
}
public int progressToTimer(int progress,int totalDuration){
int currentDuration=0;
总持续时间=(整数)(总持续时间/1000);
当前持续时间=(整数)((双)进度)/100)*总持续时间;
//返回当前持续时间(毫秒)
返回电流持续时间*1000;
}
}
很难弄清楚你想做什么。也许你可以修改你的问题以便更好地解释?是否希望currentDuration从totalDuration倒计时到0
我想你可能想要这个:
currentDuration = (int) totalDuration - ((((double)progress) / 100) * totalDuration);