Solved

Can I use relative paths for EMBED src?

Posted on 2006-11-22
14
368 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
 
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Uploading files to the web server has become common part of almost any kind of web application. People use different technologies to solve this, but regardless of the technology used, it is always useful to have some kind of progress indicator shown…
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…
The viewer will learn how to dynamically set the form action using jQuery.

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now