2016-02-23 30 views
1

我做一個應用程序中使用的MediaPlayer到流從谷歌驅動MP3:上更新時間funtionMediaPlayer的時間返回0時流的MP3

:(https://drive.google.com/uc?export=download&id=0B50eyu1h_Rc1bENYOU1iSjFWaVk特異):

private Runnable mUpdateTimeTask = new Runnable() { 
    public void run() { 
     long totalDuration = mp.getDuration(); 
     long currentDuration = mp.getCurrentPosition(); 
     // Displaying time completed playing 
     songCurrentDurationLabel.setText(""+utils.milliSecondsToTimer(totalDuration - currentDuration)); 
     // Updating progress bar 
     int progress = (int)(utils.getProgressPercentage(currentDuration, totalDuration)); 
     //Log.d("Progress", ""+progress); 
     songProgressBar.setProgress(progress); 
     // Running this thread after 100 milliseconds 
     mHandler.postDelayed(this, 100); 
    } 
}; 

我看到長totalDuration = mp.getDuration()總是儘管媒體播放器已播放,但仍返回0。

如何獲得媒體的長度?

+0

getCurrentPosition()返回正確的值? –

+0

是的,它有價值 – phongvan

回答

1

我覺得你最好看這個視頻。這段視頻對媒體播放器有一定的瞭解。

這裏是link。請訪問它,我希望這會解決您的問題

+2

這不回答這個問題。該問題明確要求MediaPlayer.getDuration()返回0. –

+0

鏈接顯示如何執行此操作。你試過了嗎? –

+0

鏈接顯示如何準備和啓動MediaPlayback。我認爲OP已經做到了。儘管媒體播放成功,但他在調用getDuration()返回0時面臨問題。 –