Commit 8c4932e4 authored by ogg.k.ogg.k's avatar ogg.k.ogg.k
Browse files

export start time to the status bar code, so seeking works as expected

also expose start time as a parameter for when the stream is not seekable
parent 7f609db1
......@@ -134,7 +134,11 @@ parameters:
Defaults to auto
duration: int
Length of clip in seconds. Needed when seekable is true,
Length of clip in seconds. Needed when seekable is false,
to allow the seek bar to work.
startTime: int
Start time of clip in seconds. Needed when seekable is false,
to allow the seek bar to work.
keepAspect: boolean
......
......@@ -49,6 +49,7 @@ public class Cortado extends Applet implements Runnable, MouseMotionListener,
private int bufferHigh;
private int debug;
private double durationParam;
private double startTimeParam;
private boolean statusRunning;
private Thread statusThread;
public Status status;
......@@ -104,6 +105,8 @@ public class Cortado extends Applet implements Runnable, MouseMotionListener,
"Is this a live stream (disabled PAUSE) (auto|true|false) (default auto)"},
{"duration", "float",
"Total duration of the file in seconds (default unknown)"},
{"startTime", "float",
"Start time of the file in seconds (default unknown)"},
{"audio", "boolean", "Enable audio playback (default true)"},
{"video", "boolean", "Enable video playback (default true)"},
{"kateIndex", "boolean", "Enable playback of a particular Kate stream (default -1 (none))"},
......@@ -233,6 +236,7 @@ public class Cortado extends Applet implements Runnable, MouseMotionListener,
seekable = getEnumParam("seekable", autoBoolVals, "auto");
live = getEnumParam("live", autoBoolVals, "auto");
durationParam = getDoubleParam("duration", -1.0);
startTimeParam = getDoubleParam("startTime", -1.0);
audio = getBoolParam("audio", true);
video = getBoolParam("video", true);
kateIndex = getIntParam("kateIndex", -1);
......@@ -315,7 +319,7 @@ public class Cortado extends Applet implements Runnable, MouseMotionListener,
status.setSeekable(false);
}
if (durationParam < 0) {
if (durationParam < 0 || startTimeParam < 0) {
try {
String base = documentBase != null ? documentBase.toString().substring(0, documentBase.toString().lastIndexOf("/")) : "";
String docurlstring = (urlString.indexOf("://") >= 0) ? urlString : base + "/" + urlString;
......@@ -323,13 +327,19 @@ public class Cortado extends Applet implements Runnable, MouseMotionListener,
URL url = new URL(docurlstring);
DurationScanner dscanner = new DurationScanner();
DurationScanner.TimingInfo tinfo = dscanner.scanURL(url, userId, password);
duration = durationParam = tinfo.duration;
Debug.log(Debug.INFO, "Determined stream duration to be approx. " + durationParam+", starting at "+tinfo.startTime);
if (durationParam < 0) {
duration = durationParam = tinfo.duration;
}
if (startTimeParam < 0) {
startTimeParam = tinfo.startTime;
}
Debug.log(Debug.INFO, "Determined stream duration to be approx. " + durationParam+", starting at "+startTimeParam);
} catch (Exception ex) {
Debug.log(Debug.WARNING, "Couldn't determine duration for stream.");
}
}
status.setStartTime(startTimeParam);
status.setDuration(durationParam);
inStatus = false;
mayHide = (hideTimeout == 0);
......
......@@ -76,6 +76,7 @@ public class Status extends Component implements MouseListener,
private double position = 0;
private long time;
private double startTime = 0;
private double duration;
private long byteDuration;
private long bytePosition;
......@@ -402,13 +403,14 @@ public class Status extends Component implements MouseListener,
if (clicked == NONE) {
double newPosition;
if (seconds < duration || seekable)
if (seconds < duration || seekable) {
time = (long) seconds;
}
else
time = (long) duration;
if(duration > -1) {
newPosition = ((double) time) / duration;
newPosition = ((double) time - startTime) / duration;
if (newPosition != position) {
position = newPosition;
component.repaint();
......@@ -421,6 +423,11 @@ public class Status extends Component implements MouseListener,
}
}
public void setStartTime(double seconds) {
startTime = seconds;
component.repaint();
}
public void setDuration(double seconds) {
duration = seconds;
component.repaint();
......@@ -641,7 +648,7 @@ public class Status extends Component implements MouseListener,
if (newPosition != position) {
position = newPosition;
time = (long) (duration * position);
time = (long) (startTime + duration * position);
component.repaint();
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment