• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 418
  • Last Modified:

Can I use relative paths for EMBED src?

I want to use EMBED to play a sound file that's in a folder at the same directory level as this HTML file.  I've got sound.mp3 in both locations (though I don't want to have it in the same folder as the HTML file.)  Why won't mySound2 play?

<html>
<body>
<EMBED id="mySound" name="mySound" src="sound.mp3" autostart="false" loop=false hidden="false">
<EMBED id="mySound2" name="mySound2" src="../audio/sound.mp3" autostart="false" loop=false hidden="false">
<br /><br />
<button onclick="document.getElementById('mySound').play();">Play 1</button>
<br /><br />
<button onclick="document.getElementById('mySound2').play();">Play 2</button>
</body>
</html>
0
etd_onlineguys
Asked:
etd_onlineguys
  • 7
  • 3
  • 2
  • +1
1 Solution
 
ch2Commented:
try this src="./audio/sound.mp3"
0
 
ch2Commented:
if the above dosen't work try like this

this src="./../audio/sound.mp3"
0
 
rangasumanCommented:
The webserver has a root folder known as wwwroot, htdocs etc. If you place a file above that directory, the webserver can not return the file. This is to protect your server from unauthorised access. I believe you placed the audio directory above the webserver root. Place it inside the webserver root to be able to access it.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
etd_onlineguysAuthor Commented:
Thanks for your comments.  I tried the solutions ch2 suggested.  The page works as written when I launch it through the http:// path on a webserver.  It does not work, however, when I launch it from the mapped directory.  I need it to work without a webserver.  It only needs to work in IE6.  It looks like the EMBED object is behaving differently in this case than an IMG would, for example.  Does anyone have an explanation or a workaround?    
0
 
ch2Commented:
Try this:


<html>
<body>
<EMBED id="mySound" name="mySound" src="audio/sound.mp3" autostart="false" loop=false hidden="false">
<EMBED id="mySound2" name="mySound2" src="audio/sound.mp3" autostart="false" loop=false hidden="false">
<br /><br />
<button onclick="document.getElementById('mySound').play();">Play 1</button>
<br /><br />
<button onclick="document.getElementById('mySound2').play();">Play 2</button>
</body>
</html>
0
 
ch2Commented:
A litle explain:

audio/sound.mp3 = absolute path
./audio/sound.mp3 = relative path

A full path or absolute path is a path that points to the same location on one file system regardless of the working directory or combined paths. It is usually written in reference to a root directory.

A relative path is a path relative to the current working directory, so the full absolute path may not need to be given.
0
 
ch2Commented:
Well, my example works perfectly.

You just have to try both examples and they work, i tryed them in a server enviorement and also as standalone.

They way to play it locally is like this "audio/sound.mp3".


0
 
etd_onlineguysAuthor Commented:
ch2,
Your example does work.  I didn't accept it as a solution because it did not solve my objective, which was to open a sound file in a parallel directory to the .htm file.  
0
 
ch2Commented:
< I want to use EMBED to play a sound file that's in a folder at the same directory level as this HTML file.

< I didn't accept it as a solution because it did not solve my objective, which was to open a sound file in a parallel directory to the .htm file.

The example below does that here, using path like this Audio/sound.mp3

My steps:

Created these folders:

C:\MyProject\
C:\Myproject\Audio\

Created these files:

C:\MyProject\mysound.html
C:\Myproject\sound.mp3
C:\Myproject\Audio\sound.mp3

// mysound.html Code:

<html>
<body>
<EMBED id="mySound" name="mySound" src="sound.mp3" autostart="false" loop=false hidden="false">
<EMBED id="mySound2" name="mySound2" src="Audio/sound.mp3" autostart="false" loop=false hidden="false">
<br /><br />
<button onclick="document.getElementById('mySound').play();">Play 1</button>
<br /><br />
<button onclick="document.getElementById('mySound2').play();">Play 2</button>
</body>
</html>

The above works here.
0
 
ch2Commented:
But hey, perhaps your computer is especial and don't want to work.

Bt as i don't really care about this site, this Q can be deleted, as i justa wanted to help you, and you just didn't reply.

As i say this site sucks.
0
 
LeeKowalkowskiCommented:
Hello sorry I'm late, relative paths should work fine exactly how you have them in your original post.  As your embedded sounds are not hidden, you should be able to right-click on the embedded windows media player control and select "Error Details" from the menu for information about any errors.

Note: the errors may not be entirely helpful I deliberately misspelt the filename and the error said "unsupported file type".
0
 
etd_onlineguysAuthor Commented:
Right-clicking the player and looking at the error code told me why it isn't possible to do what I was trying to do.  Relative paths are okay, but not parent paths.  Below is a copy of the error description frojm the Windows Media Player Error Control Center:

C00D132B: Cannot play the file
Windows Media Player cannot play the file. You might encounter this error message for the following reason:

The file that you are trying to play is stored in a location that the Player cannot access. Typically, this occurs when the path for a link on a Web page was created in a manner that is not supported by the embedded Player.
The file is either located in a folder above the location of a Web page containing the Windows Media Player ActiveX control or the file is in a folder above the location of a playlist (a Windows Media file with an .asx extension) that is referencing it. The Player does not support using relative paths to access folders above the current one.

To fix the problem, the Web page creator should modify the path to the file so that the file is located in a folder that the Player can access. For example, the path should not include the format "..\".

0
 
LeeKowalkowskiCommented:
Very interesting, must be intoduced in a later version of WMP that I'm using (mine is rather old).
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 7
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now