Jump to content

How to play sound file on web page


geroid

Recommended Posts

Hi

I want to play an audio file on my webpage but have no idea how to. The user should be able to click on a link and listen to the sound. Can anyone help here. The location of the audio files on my system are:

 

C:\xampp\htdocs\Irishlang\FiveDayIrish\Day01.wma

 

Also, is wma the ideal format for this. I just simply want a link that starts the sound file and some way for the user to stop it perhaps

 

Thanks

Link to comment
Share on other sites

the format of the music doesn't matter too much, although mp3 is probably the way to go for quality sound.

true/false

something very primitative you can do is this...

<?php
echo "<embed src=\"/Irishlang/FiveDayIrish/".$_GET['song']."\" autostart="true" loop=\"".$_GET['loop']."\"
volume=\"".$_GET['vol']."\" />";
?>

 

then to choose the song and settings do this...

<form action="music.php" method="get'>
Song Name:
<input type="text" name="song" />
Volume(out of 100):
<input type="text" name="vol" />
Repeat song?:
<input type="checkbox" name="loop" value="false"  />
<input type="submit" value="Play Music!" />
</form>

Link to comment
Share on other sites

Hi MasterACE14

Thanks for the reply. As I'm relatively new to this I wonder could you help me a little more. The PHP code you supplied does not seem to have the sound file (Day01.wma) in the code. Could you write the code exactly as it should be written. The page where the link will be on is called fiveday.php. I've spent all morning trying to get various codes to work from the Internet with no luck. I'm afraid right now I need baby instructions and then once I see it working I can understand how it works. So let's say I click a link which takes me to the fiveday.php page which has a link on it like "Play this song". Clicking that link will make the song play.

 

Hope you can help

Link to comment
Share on other sites

put this in a file called music.php

<?php
if(isset($_GET['newsong'])) {
echo "<embed src=\"/Irishlang/FiveDayIrish/".$_GET['song']."\" autostart="true" loop=\"".$_GET['loop']."\"
volume=\"".$_GET['vol']."\" />";
} else {
?>
<form action="music.php" method="get'>
Song Name:
<input type="text" name="song" />
Volume(out of 100):
<input type="text" name="vol" />
Repeat song?:
<input type="checkbox" name="loop" value="false"  />
<input type="submit" value="Play Music!" name="newsong" />
</form>
<?php
}
?>

 

and that file will go in the htdocs folder.

 

in the text field where it says Song Name: you type in the song file.

Day01.wma
Link to comment
Share on other sites

Hi again

I've put the following code in a doc called music.php but I'm getting an error message like this:

 

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in C:\xampp\htdocs\Irishlang\music.php on line 53. Line 53 being the 'ecgo' line.

 

<?php

if(isset($_GET['newsong'])) {

echo "<embed src=\"/Irishlang/FiveDayIrish/".$_GET['Day01.wma']."\" autostart="true" loop=\"".$_GET['loop']."\"

volume=\"".$_GET['vol']."\" />";

} else {

?>

<form action="music.php" method="get'>

Song Name:

<input type="text" name="song" />

Volume(out of 100):

<input type="text" name="vol" />

Repeat song?:

<input type="checkbox" name="loop" value="false"  />

<input type="submit" value="Play Music!" name="newsong" />

</form>

<?php

}

?>

Link to comment
Share on other sites

Yes sorry, I made a mistake there but changed it and still getting the same error message.

 

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in C:\xampp\htdocs\Irishlang\music.php on line 53 (echo line)

 

<?php

if(isset($_GET['newsong'])) {

echo "<embed src=\"/Irishlang/FiveDayIrish/".$_GET['song']."\" autostart="true" loop=\"".$_GET['loop']."\"

volume=\"".$_GET['vol']."\" />";

} else {

?>

<form action="music.php" method="get'>

Song Name:

<input type="text" name="song" />

Volume(out of 100):

<input type="text" name="vol" />

Repeat song?:

<input type="checkbox" name="loop" value="false"  />

<input type="submit" value="Play Music!" name="newsong" />

</form>

<?php

}

?>

Link to comment
Share on other sites

change this line...

<?php
echo "<embed src=\"/Irishlang/FiveDayIrish/".$_GET['song']."\" autostart="true" loop=\"".$_GET['loop']."\"

to...

<?php
echo "<embed src=\"/Irishlang/FiveDayIrish/".$_GET['song']."\" autostart="true" loop=\"".$_GET['loop']."\"; // note the added ;

Link to comment
Share on other sites

Ok this is what I have now but I'm still getting the same error message. I'll post the entire page this time. Your script starts on line 51

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>

<title>Blueberry</title>

<link rel="shortcut icon" href="favicon.ico" type="image/x-icon"/>

<link rel="stylesheet" type="text/css" href="gorotron1.css"/>

</head>

<body>

<div id="container">

 

<div id="banner">

<div id="bannerLeft"></div>

<div id="bannerRight">

<h1>Glor Cheatharlach</h1>

<h2></h2>

</div>

</div>

 

<div id="content">

 

<div id="leftColumn">

<ul id="nav">

<li><a href="index.html">» Home</a></li>

<li><a href="history.html">» Irish Language History</a></li>

<li><a href="newletter.htm">» Newsletter</a></li>

<li><a href="course.html">» Our courses</a></li>

<li><a href="phpBB3/index.php">» Forum</a></li>

<li><a href="events.html">» Events</a></li>

<li><a href="http://www.focal.ie" target="_blank">» Dictionary</a></li>

<li><a href="http://www.gaelchultur.com" target="_blank">» Gaelchultur</a></li>

<li><a href="http://www.carlow.ie" target="_blank">» Carlow Council</a></li>

<li><a href="radio.html">» Radio</a></li>

<li><a href="events.html">» Events</a></li>

<li><a href="fiveday.html">» Five day Irish</a></li>

<li><a href="index.html">» About Us</a></li>

<li><a href="contact.html">» Contact us</a></li>

</ul>

<div id="leftColumnBottom">

<p>The image above the navigation bar should be sized 100h x 150w.</p>

<p></p>

 

</div>

</div>

 

<div id="rightColumn">

<h3>Five day Irish audio course <span class="date"> 12.28.06 // Comments (3)</span></h3>

 

<p>

</p>

<?php

if(isset($_GET['newsong'])) {

echo "<embed src=\"/Irishlang/FiveDayIrish/".$_GET['song']."\" autostart="true" loop=\"".$_GET['loop']."\";

volume=\"".$_GET['vol']."\" />";

} else {

?>

<form action="music.php" method="get'>

Song Name:

<input type="text" name="song" />

Volume(out of 100):

<input type="text" name="vol" />

Repeat song?:

<input type="checkbox" name="loop" value="false"  />

<input type="submit" value="Play Music!" name="newsong" />

</form>

<?php

}

?>

 

</div>

 

<div id="clear">

</div>

 

</div>

 

</div>

<div id="copyright"> © 2007 Glor Cheatharlach. Site design by <a href="http://www.gorotron.com">gorotron</a>.</div>

</body>

</html>

Link to comment
Share on other sites

Its the only php on the page that begins with:

 

echo "<embed src=\"/Irishlang/FiveDayIrish/".$_GET['song']."\" autostart="true" loop=\"".$_GET['loop']."\";

 

and th error is:

 

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in C:\xampp\htdocs\Irishlang\music.php on line 53

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.