Jump to content

Cannot specify relative or full path for HTML wepbage function()


jasonxweb
 Share

Recommended Posts

Hello Everyone,

I'm making a webpage that has a number of buttons that play different sound files when clicked on. To keep things organzed ( there are multiple html and mp3 files ), I want to keep the html and mp3 files in a separate folders.  Here is the folder structure that I have: 

566258065_FolderStructure2.jpg.b3a408d089f0ba7c415850498a287b84.jpg

But this does not work:

function function_animal_cow(){var audio=new Audio("../mp3_files/animal_sound_files/Cow_mooing_audio.mp3"); audio.play();} 

Please note that I am using all the html and mp3 files on a local Mac computer only ( not a server ).  

Why does using ../ to specify a relative path not work in a function?  Is there a different way to specify a relative path within a function?

As an alternative to specifying relatives paths, I also tried specify the full path, but this does not work either :

function function_animal_cow(){var audio=new Audio("/Users/Jason/Desktop/Sounds of the World Webpage/mp3_files/animal_sound_files/Cow_mooing_audio.mp3"); audio.play();} 

Is there a different way to specify a full path ( on a local Mac computer, not a server )?

Thank you,

Jason

Context for code below:

<!DOCTYPE html>
<html>
<head>
<meta charset='UTF-8'>
<title>Animal Sounds</title>
<style>	
...
</style>
<body>
<div class="button_plays_sound" onclick="function_animal_cow()"> Cow goes moo </div>
...
<script> 	
function function_animal_cow(){var audio=new Audio("../mp3_files/animal_sound_files/Cow_mooing_audio.mp3"); audio.play();} 
...
</script> 
</body>
</html>

 

Link to comment
Share on other sites

The path looks correct.

Does it work when you put the audio file in the same folder as the HTML file? Are there any Javascript errors shown in the error console?

Link to comment
Share on other sites

Ingolme, thank you, yes, the entire webpage works when I put the MP3 files in the same folder as the HTML files - so it's only specifying a path to a different folder that is the problem.

What is the error console?  Is that in the browser ( am using Safari ), or in the web design software ( am using Dreamweaver, everything is done by code )?

Edited by jasonxweb
To show who I am replying to.
Link to comment
Share on other sites

1 hour ago, Ingolme said:

The path looks correct.

Does it work when you put the audio file in the same folder as the HTML file? Are there any Javascript errors shown in the error console?

Okay, found in Safari > Develop > Show JavaScript Console.  No error messages are shown.

Link to comment
Share on other sites

I'm not sure how the Safari console works, but look for a "net" or "network" tab in the console and see if anything changes in it when you click on the button which activates the sound.

Link to comment
Share on other sites

On 9/8/2021 at 10:01 PM, Ingolme said:

I'm not sure how the Safari console works, but look for a "net" or "network" tab in the console and see if anything changes in it when you click on the button which activates the sound.

Sorry for the late reply!  It took some time to gather this information.  Here's a screenshot of the Network tab as requested:

1.thumb.jpg.41abae9e731d66c22760407253c436c0.jpg

The Network tab shows the mp3 files being listed, but no sound is played.

Here a screenshot of the Console tab:

2.thumb.jpg.ecb0df021b305f6ef084f4f456b78ccf.jpg

Each time I click on a button and there's no sound, this is what the Console tab displays ( not sure why last time no error messages were displayed ).  Do you know what these error messages mean?

Description of problem in its current state

  • The webpage works intermittently, about 50%.  I am unable to identify any circumstances correlating to success or failure.  Repeated initiations of the webpage in the same circumstances result in both success and failure to play sound when button clicked.
  • Made some minor folder and file naming changes since last time, and updated htmls accordingly.  Since the webpage works 50% of the time, I can rule out folder and file naming changes as a cause to the problem.
  • 3.jpg.49637b979938fc2020ebaaecffae6001.jpg
  • I am starting the webpage with an app written in Applescript.  The Applescript starts Safari and loads the webpage html.  Since the webpage works 50% of the time, I am assuming that the Applescript app is not contributing to the problem, but who knows how Safari might be affected by another app that is starting it?

Thank you.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...