0

I am doing a project for my computer science class in which I am adding audio into my website. I am doing this in cloud 9. And I have a folder of different songs on a different folder. I need to be able to access the song from the higher folder. People have been saying to use this code:

    <source src="../folder/filename.mp3" type=mpeg">

But the code was given to me fro images, I have not been able to do it with a song. When I use this code I get the normal looking play button on my website, but it is grayed out. I have been able to get it to work, but only if I take the song out of the folder and put it at the same level as the file. I have also tested different audio files to see if that is the problem.

Serkan Senyuz
  • 67
  • 1
  • 9

1 Answers1

2

Use absolute site URI routing whereby your sound file address starts with a / and so indicates the path from the root of the URL.

For instance:
Your current output file is, say, www.site.com/output/file.html, and you want to load a sound from, say, www.site.com/sounds/laugh.mp3 then you simply use the /sounds/laugh.mp3 part of the address as your reference. Becauseit starts with a / this indicates it's an absolute site URL and indicates the root HTML directory, rather than a page specific url.

 <source src="/sounds/filename.mp3" type=mpeg">

If you used a relative path such as ../sounds/filename.mp3 this would break if you used it in the base folder (www.site.com/index.html) or in a deeper directory tree such as www.site.com/sounds/silly/horses.html. But the absolute path would always work (as long as the destinaton file exists and is accessible).


Tip: Make sure you've also uploaded your sound file!

Martin
  • 22,212
  • 11
  • 70
  • 132
  • Sorry 'bout that hit enter by accident. My file directory is, The folder project, from inside is the folder music in as well as the file Music.html(my website). I tried your code like this (sorry I don't know how to make it show up like code). I still get the blank – Serkan Senyuz Oct 15 '16 at 16:08
  • your link is case sensitive, and so it would be `www.site.com/Music/Concerto.mp3` ? (code view in comments is using backticks (next to number 1 on keyboard, usually)). Does that link exist? – Martin Oct 17 '16 at 16:12