mirror of
https://github.com/clangen/musikcube.git
synced 2025-01-01 17:58:29 +00:00
Added buffer progress to the seekbar.
This commit is contained in:
parent
0493f9cd13
commit
a0c37bca1f
@ -197,10 +197,13 @@ public class PlayerControl extends Activity implements OnTrackUpdateListener, On
|
||||
positionView.setText(positionText);
|
||||
|
||||
SeekBar seekBar = (SeekBar)findViewById(R.id.TrackProgress);
|
||||
if(this.duration==0){
|
||||
seekBar.setProgress(0);
|
||||
}else{
|
||||
seekBar.setProgress(msPosition/this.duration);
|
||||
synchronized (this.lock) {
|
||||
if(this.duration==0){
|
||||
seekBar.setProgress(0);
|
||||
}else{
|
||||
seekBar.setProgress(msPosition/this.duration);
|
||||
}
|
||||
seekBar.setSecondaryProgress(10*Player.GetInstance().GetTrackBuffer());
|
||||
}
|
||||
|
||||
// Next callback in 0.5 seconds
|
||||
|
@ -172,5 +172,15 @@ public class Player implements TrackPlayer.OnTrackStatusListener{
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int GetTrackBuffer(){
|
||||
synchronized(this.lock){
|
||||
TrackPlayer player = this.currentPlayer;
|
||||
if(player!=null){
|
||||
return player.GetBuffer();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,12 +2,13 @@ package org.musikcube.core;
|
||||
|
||||
import android.media.MediaPlayer;
|
||||
|
||||
public class TrackPlayer implements Runnable, MediaPlayer.OnCompletionListener, MediaPlayer.OnErrorListener {
|
||||
public class TrackPlayer implements Runnable, MediaPlayer.OnCompletionListener, MediaPlayer.OnErrorListener,MediaPlayer.OnBufferingUpdateListener {
|
||||
|
||||
private Thread thread;
|
||||
private String url;
|
||||
private java.lang.Object lock = new java.lang.Object();
|
||||
private MediaPlayer mediaPlayer;
|
||||
private int buffer = 0;
|
||||
|
||||
private int status = 1;
|
||||
|
||||
@ -24,6 +25,7 @@ public class TrackPlayer implements Runnable, MediaPlayer.OnCompletionListener,
|
||||
|
||||
this.mediaPlayer.setOnCompletionListener(this);
|
||||
this.mediaPlayer.setOnErrorListener(this);
|
||||
this.mediaPlayer.setOnBufferingUpdateListener(this);
|
||||
|
||||
this.mediaPlayer.setDataSource(this.url);
|
||||
this.mediaPlayer.prepare();
|
||||
@ -151,5 +153,17 @@ public class TrackPlayer implements Runnable, MediaPlayer.OnCompletionListener,
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void onBufferingUpdate(MediaPlayer mp, int percent) {
|
||||
synchronized(this.lock){
|
||||
this.buffer = percent;
|
||||
}
|
||||
}
|
||||
|
||||
public int GetBuffer(){
|
||||
synchronized(this.lock){
|
||||
return this.buffer;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user