增加点播读取flv文件功能

This commit is contained in:
李宇翔
2021-06-24 15:44:43 +08:00
parent e02dc36bdd
commit ead7f0ac39
2 changed files with 21 additions and 0 deletions

View File

@@ -40,6 +40,7 @@ func init() {
func run() { func run() {
go AddHook(HOOK_PUBLISH, onPublish) go AddHook(HOOK_PUBLISH, onPublish)
os.MkdirAll(config.Path, 0755) os.MkdirAll(config.Path, 0755)
http.HandleFunc("/vod/", VodHandler)
http.HandleFunc("/api/record/flv/list", func(w http.ResponseWriter, r *http.Request) { http.HandleFunc("/api/record/flv/list", func(w http.ResponseWriter, r *http.Request) {
CORS(w, r) CORS(w, r)
if files, err := tree(config.Path, 0); err == nil { if files, err := tree(config.Path, 0); err == nil {

20
vod.go Normal file
View File

@@ -0,0 +1,20 @@
package record
import (
"io"
"net/http"
"os"
"path/filepath"
)
func VodHandler(w http.ResponseWriter, r *http.Request) {
streamPath := r.RequestURI[5:]
filePath := filepath.Join(config.Path, streamPath)
if file, err := os.Open(filePath); err == nil {
w.Header().Set("Transfer-Encoding", "chunked")
w.Header().Set("Content-Type", "video/x-flv")
io.Copy(w, file)
} else {
w.WriteHeader(404)
}
}