2015-07-11 6 views
3

Я размещаю проект на страницах github и хотел бы воспроизвести аудиофайл, который находится в моем репозитории, через элемент html5 <audio>. когда я получаю его в своей среде dev, звук воспроизводится нормально, но когда я нажимаю на gh-pages, я получаю ошибку консоли 404, которую он не может найти.источник аудиофайла в репо на страницах github

<audio ref='themeSong' src="vendor/assets/music/Tetris.mp3" autoPlay loop></audio> 

Ошибка:

GET http://myName.github.io/vendor/assets/music/Tetris.mp3 404 (Not Found) 

Я попытался его поиске это:

"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" 

но ничего не похоже на работу.

ответ

2

Вы можете попробовать и ссылаться на Необработанные URL-адрес

https://raw.githubusercontent.com/myName/myRepo/master/vendor/assets/music/Tetris.mp3 

Примечание: услуга как rawgit.com упоминает:

When you request a file from raw.githubusercontent.com or gist.githubusercontent.com , GitHub usually serves it (in the case of JavaScript, HTML, CSS, and some other file types) with a Content-Type of text/plain . As a result, most modern browsers won't actually interpret it as JavaScript, HTML, or CSS.

They do this because serving raw files from a git repo is relatively inefficient, so they want to discourage people from using their GitHub repos for static file hosting.

RawGit acts as a caching proxy, forwarding requests to GitHub, caching the responses either for a short time (in the case of rawgit.com URLs) or permanently (in the case of cdn.rawgit.com URLs), and relaying them to your browser with the correct Content-Type headers.

+0

работал отлично. на стороне записки, когда я пошел в файл в своем репо, там была небольшая ссылка, в которой говорилось «посмотреть сырое». использовал эту ссылку в 'src' и играл на обеих dev и gh-страницах. cheers – PhilVarg

+0

Это все еще работает? Теперь исходные файлы теперь не воспроизводятся из GitHub, кнопка воспроизведения выделена серым цветом. То же самое происходит и с rawgit. –

+1

@JuanFerrer Он должен, но не с rawgit: https://github.com/rgrove/rawgit/issues/149#issuecomment-300056571. И проверьте свой рекламный блок, на всякий случай: https://github.com/rgrove/rawgit/issues/153#issuecomment-310252191 – VonC

Смежные вопросы