add(new Label(" Speed:"));
timeScaleText = new TextField(5);
timeScaleText.setText("1.0");
- timeScaleText.setEnabled(false);
- timeScaleText.setEditable(false);
add(timeScaleText);
timeScaleText.addActionListener(this);
}
player.setPaused(playButton.getLabel().equals("Pause"));
} else if (evt.getSource() == posText) {
player.setPos(Integer.parseInt(posText.getText()));
+ } else if (evt.getSource() == timeScaleText) {
+ player.setSpeed(Double.parseDouble(timeScaleText.getText()));
}
}
}
protected long timeOffset;
protected long seekOffset;
protected boolean paused;
+ protected double playbackSpeed;
protected byte[] buffer;
protected int bufferSize;
timeOffset = 0;
seekOffset = -1;
paused = false;
+ playbackSpeed = 1.0;
byte[] b = new byte[12];
readFully(b);
timeOffset = 0;
seekOffset = -1;
paused = false;
+ playbackSpeed = 1.0;
buffer = null;
bufferSize = 0;
// Methods providing additional functionality.
//
- public long getTimeOffset()
+ public synchronized long getTimeOffset()
{
- return timeOffset;
+ return (long)(timeOffset * playbackSpeed);
}
public synchronized void setTimeOffset(long pos)
{
// FIXME: Seeking works only in paused mode.
paused = true;
- seekOffset = pos;
+ seekOffset = (long)(pos / playbackSpeed);
notify();
}
+ public synchronized void setSpeed(double newSpeed)
+ {
+ timeOffset = (long)(timeOffset * playbackSpeed / newSpeed);
+ startTime = System.currentTimeMillis() - timeOffset;
+ if (isSeeking()) {
+ seekOffset = (long)(seekOffset * playbackSpeed / newSpeed);
+ }
+ playbackSpeed = newSpeed;
+ }
+
public boolean isSeeking()
{
return (seekOffset >= 0);
// Methods for internal use.
//
- private boolean fillBuffer() throws IOException
+ private synchronized boolean fillBuffer() throws IOException
{
waitWhilePaused();
buffer = new byte[realSize];
readFully(buffer);
bufferPos = 0;
-
- timeOffset = readUnsigned32();
+ timeOffset = (long)(readUnsigned32() / playbackSpeed);
}
if (bufferSize < 0 || timeOffset < 0) {
if (timeDiff <= 0) {
break;
}
- synchronized(this) {
- try {
- wait(timeDiff);
- } catch (InterruptedException e) {
- }
+ try {
+ wait(timeDiff);
+ } catch (InterruptedException e) {
}
waitWhilePaused();
}
}
}
+ public void setSpeed(double speed) {
+ fbsStream.setSpeed(speed);
+ }
+
public void setPos(int pos) {
fbsStream.setTimeOffset(pos * 1000);
}
+
public void updatePos() {
if (showControls)
buttonPanel.setPos((int)(fbsStream.getTimeOffset() / 1000));