I tried to implement Shaka Player in my Go project. This is the project structure:
.
├── 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>
My main.go
file in which I specify routes for index.html
and 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)
}
When I try to access the manifest with player.load()
, it just returns 404 Not found
. But when I try to access it in the browser by the same link (127.0.0.1:5000/manifest
), it's ok and I can download the file. The link from the guide works well. How should I serve the video manifest from my Go server so Shaka player could consume it without any errors?
</div>
Ok, it was enough to specify the scheme: http://127.0.0.1:5000/manifest
instead of just 127.0.0.1:5000/manifest
.