Audio file source in repo on github pages
I am hosting a project on github pages and want to play an audio file that is in my repository via an html5 element <audio>
. when i get it in my dev environment the sound plays fine, but when i click on gh-pages i get a 404 console error it can't find.
<audio ref='themeSong' src="vendor/assets/music/Tetris.mp3" autoPlay loop></audio>
Mistake:
GET http://myName.github.io/vendor/assets/music/Tetris.mp3 404 (Not Found)
I tried to find this:
"vendor/assets/music/Tetris.mp3"
"/vendor/assets/music/Tetris.mp3"
"http://github.com/myName/myRepo/vendor/assets/music/Tetris.mp3"
"http://github.com/myName/myRepo/tree/master/vendor/assets/music/Tetris.mp3"
but nothing works.
source to share
You can try and give the raw url
https://raw.githubusercontent.com/myName/myRepo/master/vendor/assets/music/Tetris.mp3
Note: a service like rawgit.com mentions:
When you request a file from
raw.githubusercontent.com
orgist.githubusercontent.com
, GitHub usually serves it up (in the case of JavaScript, HTML, CSS, and some other file types) withContent-Type
oftext/plain
. As a result, most modern browsers don't actually interpret it as JavaScript, HTML, or CSS.They do this because serving raw files from a git repository is relatively inefficient, so they want to prevent people from using their GitHub repositories for static file hosting.
RawGit acts as a caching proxy, redirects requests to GitHub, caches responses either briefly (in the case of
rawgit.com
URLs) or permanently (in the case ofcdn.rawgit.com
URLs) and sends them to your browser with the correct headersContent-Type
.
source to share