2012-09-11 138 views
0

我創建了一個音頻播放器,並在我的項目中有一個類用於處理持續時間。如何確保totalDuration的計數方向相反?更改時間android音頻播放器

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; 
} 
} 

回答

0

很難找出你正在嘗試做的。也許你可以編輯你的問題來更好地解釋?你想讓currentDuration從totalDuration向下計數到0嗎?

我想你可能想要這個:

currentDuration = (int) totalDuration - ((((double)progress)/100) * totalDuration);