Solved

Can I use relative paths for EMBED src?

Posted on 2006-11-22
14
378 Views
Last Modified: 2008-01-09
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
Comment
Question by:etd_onlineguys
  • 7
  • 3
  • 2
  • +1
14 Comments
 
LVL 11

Expert Comment

by:ch2
ID: 17996248
try this src="./audio/sound.mp3"
0
 
LVL 11

Expert Comment

by:ch2
ID: 17996293
if the above dosen't work try like this

this src="./../audio/sound.mp3"
0
 
LVL 7

Expert Comment

by:rangasuman
ID: 17998221
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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 2

Author Comment

by:etd_onlineguys
ID: 17998707
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
 
LVL 11

Expert Comment

by:ch2
ID: 18009343
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
 
LVL 11

Expert Comment

by:ch2
ID: 18009352
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
 
LVL 11

Expert Comment

by:ch2
ID: 18171966
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
 
LVL 2

Author Comment

by:etd_onlineguys
ID: 18179735
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
 
LVL 11

Expert Comment

by:ch2
ID: 18180069
< 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
 
LVL 11

Expert Comment

by:ch2
ID: 18180095
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
 
LVL 16

Accepted Solution

by:
LeeKowalkowski earned 500 total points
ID: 18234834
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
 
LVL 2

Author Comment

by:etd_onlineguys
ID: 18237271
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
 
LVL 16

Expert Comment

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

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question