2017-12-10 38 views
0

그래서 seekbar가 작동합니다. 드래그하면 노래가 해당 위치에서 재생되기 시작하지만 내가 원하는 것은 seekbar를 끌 때입니다. 내가 현재 드래그 한 노래 위치를 표시하는 내 textview를 볼 수 있으므로 사용자는 시작할 특정 시간을 선택할 수 있습니다.노래에서 현재 시간 위치를 표시하는 텍스트 뷰를 업데이트하는 방법

바로 지금 내가 seekbar를 드래그하면 textview가 변경되지 않고 드래그하기 시작할 때 마지막 위치 만 보여줍니다.

여기

private Runnable mUpdateTime = new Runnable() { 
    @Override 
    public void run() { 
     long songCurrentTime = mediaPlayer.getCurrentPosition(); 
     long songTotalTime = mediaPlayer.getDuration(); 

     tvSongCurrentTime.setText(""+utilities.msToTimer(songCurrentTime)); 
     tvSongTotalTime.setText(""+utilities.msToTimer(songTotalTime)); 

     int progress = (int)(utilities.getProgressPercentage(songCurrentTime, songTotalTime)); 
     seekBar.setProgress(progress); 

     mHandler.postDelayed(this, 100); 
    } 
}; 

public void updateProgressBar(){ 
    mHandler.postDelayed(mUpdateTime, 100); 
} 

@Override 
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { 

} 

@Override 
public void onStartTrackingTouch(SeekBar seekBar) { 
     mHandler.removeCallbacks(mUpdateTime); 
} 

@Override 
public void onStopTrackingTouch(SeekBar seekBar) { 
     mHandler.removeCallbacks(mUpdateTime); 
     int songTotalTime = mediaPlayer.getDuration() ; 
     int currentPosition = utilities.progressToTimer(seekBar.getProgress(), songTotalTime); 

     mediaPlayer.seekTo(currentPosition); 
     updateProgressBar(); 
} 

당신이 첫 번째 GIF 내가 지금 가지고있는 것입니다

https://imgur.com/a/zEpWI

달성하기 위해 노력하고 무엇 메신저보고, 두 번째 수 있습니다 내 코드입니다 내가 원하는 걸

EDIT;

나는 이것을하는 방법을 찾지 못했지만, 누군가 그것을하는 법을 알고 있습니까? 나는 코드를 onProgressChanged 안에 넣어야한다고 생각하는데, 현재 시간과 전체 지속 시간을 추가하려고 시도했지만, 게시물에 추가 된 gif와 같이 seekbar를 스크롤 할 때 어떻게 텍스트 뷰를 업데이트 할 수 있습니까? SeekBar를 위치가 변경 될 때 onProgressChanged 가정 https://imgur.com/a/zEpWI

+0

의 내가 – Vince

+0

하나의 작은 점을 원하는 좀 모호, 업데이트 할 필요가 없습니다 경우 미안 해요 노래의 지속 시간마다 1/10 초. 'tvSongTotalTime'이 일정하다고 가정 할 수 있습니다. – Sam

+0

'onStopTrackingTouch()'의'updateProgressBar();를'tvSongCurrentTime.setText ("+ utilities.msToTimer (mediaPlayer.getCurrentPosition()));로 대체하면 어떻게됩니까? – Sam

답변

0

은 다음과 같습니다

@Override 
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { 
    if(fromUser) { 
     long songCurrentTime = mediaPlayer.getCurrentPosition(); 
     long songTotalTime = mediaPlayer.getDuration(); 

     tvSongCurrentTime.setText(""+utilities.msToTimer(songCurrentTime)); 
     tvSongTotalTime.setText(""+utilities.msToTimer(songTotalTime)); 
    } 
} 
+0

코드를 시도했지만 작동하지 않습니다. – Vince

+0

GIF 업로드가 잘못되었습니다. 의미가 무엇인지 명확히 할 수 있습니다. – Vince

+0

https://imgur.com/a/zEpWI, 여기에 제가 의미하는 바가 명확히 나와 있습니다. – Vince