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

时间:2019-08-17 18:31:40

标签: javascript go mpeg-dash shaka

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

"Sort": {
    "separator_before": false,
    "separator_after": true,
    "label": "Sort",
    "action": false,
    "submenu": {
        "Ascending": {
            "seperator_before": false,
            "seperator_after": false,
            "label": "Ascending",
            action: function (obj) {
                setSortFunction('asc');
                var selector = '#treeview';
                var root = $(selector).jstree(true).get_node("1");//get_node("root");
                $(selector).jstree(true).sort(root, true);
                $(selector).jstree(true).redraw_node(root, true);
            }
        },
        "Descending": {
            "seperator_before": false,
            "seperator_after": false,
            "label": "Descending",
            action: function (obj) {
                setSortFunction('desc');
                var selector = '#treeview';
                var root = $(selector).jstree(true).get_node("1");//get_node("root");
                $(selector).jstree(true).sort(root, true);
                $(selector).jstree(true).redraw_node(root, true);
            }
        }
    }

. ├── 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.goindex.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)在浏览器中访问它时,就可以了,我可以下载文件了。指南中的链接效果很好。我应该如何从Go服务器提供视频清单,以便Shaka播放器可以正常使用它?

1 个答案:

答案 0 :(得分:0)

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