feat(stream): report duration and position in watch progress
EstimatedProgress now returns video duration in seconds (from ffprobe). WatchReporter sends Position and Duration fields when available, giving the server precise playback time instead of just a percentage.
This commit is contained in:
parent
2dfe144df1
commit
c612ebb2e4
1 changed files with 6 additions and 1 deletions
|
|
@ -47,7 +47,7 @@ func (wr *WatchReporter) Run(ctx context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wr *WatchReporter) sendReport(ctx context.Context) {
|
func (wr *WatchReporter) sendReport(ctx context.Context) {
|
||||||
pct, _ := wr.server.EstimatedProgress()
|
pct, durSec := wr.server.EstimatedProgress()
|
||||||
if pct == 0 || pct == wr.lastSentPct {
|
if pct == 0 || pct == wr.lastSentPct {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -58,6 +58,11 @@ func (wr *WatchReporter) sendReport(ctx context.Context) {
|
||||||
Source: "range",
|
Source: "range",
|
||||||
Progress: &pct,
|
Progress: &pct,
|
||||||
}
|
}
|
||||||
|
if durSec > 0 {
|
||||||
|
update.Duration = &durSec
|
||||||
|
pos := int(float64(pct) / 100 * float64(durSec))
|
||||||
|
update.Position = &pos
|
||||||
|
}
|
||||||
|
|
||||||
reportCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
|
reportCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue