首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何正确地向Shaka播放器提供MPEG-DASH清单?

如何正确地向Shaka播放器提供MPEG-DASH清单?
EN

Stack Overflow用户
提问于 2019-08-18 02:31:41
回答 1查看 562关注 0票数 1

我试图在我的Go项目中实现Shaka Player。项目结构如下:

代码语言:javascript
复制
.
├── 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

代码语言:javascript
复制
<!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的路由

代码语言:javascript
复制
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玩家可以毫无错误地使用它?

EN

回答 1

Stack Overflow用户

发布于 2019-08-20 00:56:13

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57538927

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档