From 78c5c70c733bf4273ebec530207edc3789625300 Mon Sep 17 00:00:00 2001 From: Alexey Khit Date: Tue, 8 Nov 2022 01:29:58 +0300 Subject: [PATCH] Add duration API for MP4 file --- cmd/mp4/mp4.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/cmd/mp4/mp4.go b/cmd/mp4/mp4.go index 55535a16..b4b4763a 100644 --- a/cmd/mp4/mp4.go +++ b/cmd/mp4/mp4.go @@ -9,6 +9,7 @@ import ( "net/http" "strconv" "strings" + "time" ) func Init() { @@ -108,9 +109,25 @@ func handlerMP4(w http.ResponseWriter, r *http.Request) { cons.Start() + var duration *time.Timer + if s := r.URL.Query().Get("duration"); s != "" { + if i, _ := strconv.Atoi(s); i > 0 { + duration = time.AfterFunc(time.Second*time.Duration(i), func() { + if exit != nil { + exit <- nil + exit = nil + } + }) + } + } + err = <-exit log.Trace().Err(err).Caller().Send() + + if duration != nil { + duration.Stop() + } } func isChromeFirst(w http.ResponseWriter, r *http.Request) bool {