?
Solved

Can I use relative paths for EMBED src?

Posted on 2006-11-22
14
Medium Priority
?
405 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Simplify Your Workload with One Tool

How do you combat today’s intelligent hacker while managing multiple domains and platforms? By simplifying your workload with one tool. With Lunarpages hosting through Plesk Onyx, you can:

Automate SSL generation and installation with two clicks
Experience total server control

Question has a verified solution.

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

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

649 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