mirror of
https://github.com/langhuihui/monibuca.git
synced 2025-09-27 05:35:57 +08:00
fix: hls play record ts
This commit is contained in:
@@ -236,12 +236,11 @@ func (config *HLSPlugin) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
var plBuffer util.Buffer
|
var plBuffer util.Buffer
|
||||||
playlist.Writer = &plBuffer
|
playlist.Writer = &plBuffer
|
||||||
playlist.Init()
|
playlist.Init()
|
||||||
|
|
||||||
for _, record := range records {
|
for _, record := range records {
|
||||||
duration := record.EndTime.Sub(record.StartTime).Seconds()
|
duration := record.EndTime.Sub(record.StartTime).Seconds()
|
||||||
playlist.WriteInf(hls.PlaylistInf{
|
playlist.WriteInf(hls.PlaylistInf{
|
||||||
Duration: duration,
|
Duration: duration,
|
||||||
URL: path.Base(record.FilePath),
|
URL: record.FilePath,
|
||||||
FilePath: record.FilePath,
|
FilePath: record.FilePath,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -271,9 +270,14 @@ func (config *HLSPlugin) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
} else if strings.HasSuffix(r.URL.Path, ".ts") {
|
} else if strings.HasSuffix(r.URL.Path, ".ts") {
|
||||||
w.Header().Add("Content-Type", "video/mp2t") //video/mp2t
|
w.Header().Add("Content-Type", "video/mp2t") //video/mp2t
|
||||||
|
data, err := os.ReadFile(fileName)
|
||||||
|
if err == nil {
|
||||||
|
w.Write(data)
|
||||||
|
return
|
||||||
|
}
|
||||||
parts := strings.Split(fileName, "/")
|
parts := strings.Split(fileName, "/")
|
||||||
filePath := strings.Join(parts[1:], "/")
|
filePath := strings.Join(parts[1:], "/")
|
||||||
data, err := os.ReadFile(filePath)
|
data, err = os.ReadFile(filePath)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
w.Write(data)
|
w.Write(data)
|
||||||
return
|
return
|
||||||
|
Reference in New Issue
Block a user