gpt4 book ai didi

javascript - 如何正确地将 MPEG-DASH list 提供给 Shaka 播放器?

转载 作者:数据小太阳 更新时间:2023-10-29 03:18:27 26 4
gpt4 key购买 nike

我尝试执行 Shaka Player在我的 Go 项目中。这是项目结构:

.
├── client
│ ├── index.html
│ ├── shaka.js
│ └── shaka-player.compiled.js
└── server
├── assets
│ ├── test_dashinit.mp4
│ └── test_dash.mpd
├── Gopkg.lock
├── Gopkg.toml
├── main.go
└── vendor

index.html:

<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<title>Video</title>

<script src="shaka-player.compiled.js" defer></script>
<script src="shaka.js" defer></script>
</head>

<body>
<video id="video-clip" controls></video>
</body>

</html>

我的 main.go 文件,我在其中指定了 index.htmltest_dash.mpd 的路由:

func sendManifest(w http.ResponseWriter, r *http.Request) {
// Open the file.
manifest, err := os.Open("server/assets/test_dash.mpd")

if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)

return
}

defer manifest.Close()

// Get file size.
stat, err := manifest.Stat()

if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)

return
}

size := strconv.FormatInt(stat.Size(), 10)

// Set the headers.
w.Header().Set("Content-Disposition", "attachment; filename=manifest.mpd")
w.Header().Set("Content-Type", "application/dash+xml")
w.Header().Set("Content-Length", size)
// Send the file.
io.Copy(w, manifest)
}

func main() {
cwd, _ := os.Getwd()
fmt.Println(cwd)

fs := http.FileServer(http.Dir("client"))

http.Handle("/", fs)
http.HandleFunc("/manifest", sendManifest)

http.ListenAndServe(":5000", nil)
}

当我尝试使用 player.load() 访问 list 时,它只返回 404 Not found。但是,当我尝试通过同一链接 (127.0.0.1:5000/manifest) 在浏览器中访问它时,没问题,我可以下载该文件。指南中的链接效果很好。我应该如何从我的 Go 服务器提供视频 list ,以便 Shaka 播放器可以使用它而不会出现任何错误?

最佳答案

好的,指定方案就足够了:http://127.0.0.1:5000/ list 而不仅仅是127.0.0.1:5000/ list

关于javascript - 如何正确地将 MPEG-DASH list 提供给 Shaka 播放器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57538927/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com