javascript - 如何正确向 Shaka 播放器提供 MPEG-DASH 清单?
问题描述
我试图在我的 Go 项目中实现Shaka Player 。这是项目结构:
.
├── 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>
我在其中为andmain.go
指定路由的文件:index.html
test_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()
,它只是返回404 Not found
。但是当我尝试通过相同的链接 ( 127.0.0.1:5000/manifest
) 在浏览器中访问它时,没关系,我可以下载文件。指南中的链接效果很好。我应该如何从我的 Go 服务器提供视频清单,以便 Shaka 播放器可以毫无错误地使用它?
解决方案
好的,指定方案就足够了:
http://127.0.0.1:5000/manifest
而不仅仅是
127.0.0.1:5000/manifest
.
推荐阅读
- oracle-apex - 将日期选择器的值设置为 sysdate 检索另一个日期
- c - realloc 调用失败并抛出 SIGABORT 信号
- python - Pandas 数据框中的经过时间
- swift - SWift 错误域=AVFoundationErrorDomain 代码=-11819 "无法完成操作 "NSLocalizedRecoverySuggestion=稍后再试。,
- google-admin-sdk - 是否可以使用 GoogleAppsScript 获取 google admin 的管理地址列表?
- php - 使用 Codeigniter 打印日志文件中的所有数据库查询(ajax 请求)
- javascript - 如何根据时隙将对象时间序列数组拆分为多个时间序列?
- python - 检测图像中的最大像素距离
- sql-server-2014 - 基于同一张表添加和/或更新
- selenium - 在 Firefox 扩展中压缩 HAR (json) 文件