Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 30th, 2012, 1:27 PM   #1
BenRobertson
Newbie
 
Join Date: Nov 2012
Posts: 8
Rep Power: 0 BenRobertson is on a distinguished road
Exclamation Random audio file to play

Here is my current code:

<html>
<title>tunesmash</title>

<style type+text/css>
body {
color : black;}

#body {
left:15%;
position:absolute;
top:50%;
width:85%;
}

#audio1 {
left:30%;
position:absolute;
top:35%;
width:10%;
}

#audio2 {
left:55%;
position:absolute;
top:35%;
width:10%;
}


#title {
left:22%;
position:absolute;
top:25%;
width:60%;
}

.bg {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
z-index: -5000;
}

</style>

<img src="bgindex.jpg" class="bg">
<div id=title><b><font face=verdana size=5 color=black>

Tunesmash.com is designed to take the ridicule of bad music to the web.

</font></b></div>

<div id=audio1>

<audio controls="controls">
<source src="RIEY.m4a" type="audio/mpeg"> <!--Instead of "RIEY" playing I need a random file to play.-->
</audio>

</div>

<div id=audio2>

<audio controls="controls">
<source src="CBFG.m4a" type="audio/mpeg"> <!--Instead of "CBFG" playing I need a random file to play-->
</audio>

</div>

<div id=body><font face=verdana size=5 color=black>


</font></div>



<a href=index.html><IMG STYLE="position:absolute; TOP:11.3%; LEFT:41.55%; WIDTH:86px; HEIGHT:40px" SRC="buttonhome.JPG"></a>
<a href=about.html><IMG STYLE="position:absolute; TOP:11.5%; LEFT:47.8%; WIDTH:86px; HEIGHT:38px" SRC="buttonabout.JPG"></a>
<a href=why.html><IMG STYLE="position:absolute; TOP:11.5%; LEFT:54.1%; WIDTH:63px; HEIGHT:39px" SRC="buttonwhy.JPG"></a>
<a href=upload.html><IMG STYLE="position:absolute; TOP:11.2%; LEFT:59.1%; WIDTH:103px; HEIGHT:41px" SRC="buttonupload.JPG"></a>

<a href=index.html><IMG STYLE="position:absolute; TOP:40%; LEFT:38%; WIDTH:29px; HEIGHT:37px" SRC="thumbsup.JPG"></a>
<a href=index.html><IMG STYLE="position:absolute; TOP:40%; LEFT:63%; WIDTH:29px; HEIGHT:37px" SRC="thumbsup.JPG"></a>;

</body>
</html>

And some extra details:

The idea of the website is that the user can choose what song they like out of two side by side songs. I have all of the music in a local directory on my PC: C:\Users\Movie\Desktop\TuneSmash\Audio. I need some help so that the website picks a random song out of that folder and the user then has the ability to play it via the two side by side audio players that you can see in the code above.

Would you mind implementing your code into the code that is at the top of the post?
BenRobertson is offline   Reply With Quote
Old Dec 3rd, 2012, 5:23 AM   #2
pritaeas
mod_pritaeas
 
Join Date: May 2009
Location: The Netherlands
Posts: 251
Rep Power: 8 pritaeas is on a distinguished road
Re: Random audio file to play

Is your website running locally, or on a webserver? Even if it is running locally, Javascript has no access to your folders.
pritaeas is offline   Reply With Quote
Old Dec 3rd, 2012, 8:41 PM   #3
BenRobertson
Newbie
 
Join Date: Nov 2012
Posts: 8
Rep Power: 0 BenRobertson is on a distinguished road
Re: Random audio file to play

Hey there,

Thanks for the reply. The website is currently only running locally as I want to be sure that it works before I put it on a server.

Thanks.
BenRobertson is offline   Reply With Quote
Old Dec 3rd, 2012, 9:10 PM   #4
BenRobertson
Newbie
 
Join Date: Nov 2012
Posts: 8
Rep Power: 0 BenRobertson is on a distinguished road
Re: Random audio file to play

Quote:
Originally Posted by pritaeas View Post
Is your website running locally, or on a webserver? Even if it is running locally, Javascript has no access to your folders.
Hey there,

Thanks for the reply. The website is currently only running locally as I want to be sure that it works before I put it on a server.

Thanks.
BenRobertson is offline   Reply With Quote
Old Dec 10th, 2012, 2:19 PM   #5
FiRaS
Web Developer
 
FiRaS's Avatar
 
Join Date: Nov 2011
Location: Syria
Posts: 42
Rep Power: 0 FiRaS is on a distinguished road
Re: Random audio file to play

here is the solution.. but first u must save it as PHP.. Second u must put the music files in a folder named "music".. the folder must be in the same folder of the index...third to test this file.. u must test it by a local server..or on the main server :

<html>
<title>tunesmash</title>

<style type+text/css>
body {
color : black;}

#body {
left:15%;
position:absolute;
top:50%;
width:85%;
}

#audio1 {
left:30%;
position:absolute;
top:35%;
width:10%;
}

#audio2 {
left:55%;
position:absolute;
top:35%;
width:10%;
}


#title {
left:22%;
position:absolute;
top:25%;
width:60%;
}

.bg {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
z-index: -5000;
}

</style>

<img src="bgindex.jpg" class="bg">
<div id=title><b><font face=verdana size=5 color=black>

Tunesmash.com is designed to take the ridicule of bad music to the web.

</font></b></div>

<div id=audio1>

<audio controls="controls">
<?php
		$dir = dir("music");
		$files=0;

		//Count number of files in music directory
		while (($file = $dir->read()) !== false)
		{
			$files++;
		}

		$dir->close();
		$rand1=(rand(3,$files));
		$rand2=(rand(3,$files));
		while($rand1==$rand2)
		$rand2=(rand(3,$files));
		$i=0;
		$dir = dir("music");
		while (($file = $dir->read()) !== false)
		{
			$i++;
			if($i==$rand1)
				$file1=$file;
			if($i==$rand2)
				$file2=$file;
		}
		
		
		echo'
		<source src="music/'.$file1.'" type="audio/mpeg"> 
		</audio>

		</div>

		<div id=audio2>

		<audio controls="controls">
		<source src="music/'.$file2.'" type="audio/mpeg"> ';
?>
</audio>

</div>

<div id=body><font face=verdana size=5 color=black>


</font></div>



<a href=index.html><IMG STYLE="position:absolute; TOP:11.3%; LEFT:41.55%; WIDTH:86px; HEIGHT:40px" SRC="buttonhome.JPG"></a>
<a href=about.html><IMG STYLE="position:absolute; TOP:11.5%; LEFT:47.8%; WIDTH:86px; HEIGHT:38px" SRC="buttonabout.JPG"></a>
<a href=why.html><IMG STYLE="position:absolute; TOP:11.5%; LEFT:54.1%; WIDTH:63px; HEIGHT:39px" SRC="buttonwhy.JPG"></a>
<a href=upload.html><IMG STYLE="position:absolute; TOP:11.2%; LEFT:59.1%; WIDTH:103px; HEIGHT:41px" SRC="buttonupload.JPG"></a>

<a href=index.html><IMG STYLE="position:absolute; TOP:40%; LEFT:38%; WIDTH:29px; HEIGHT:37px" SRC="thumbsup.JPG"></a>
<a href=index.html><IMG STYLE="position:absolute; TOP:40%; LEFT:63%; WIDTH:29px; HEIGHT:37px" SRC="thumbsup.JPG"></a>;

</body>
</html>


But u are using a very bad technique of playing audio..coz the
<audio></audio> doesnt work with all music files & doesnt work on old browsers..
& to test ur page u must view it on Google Chrome Browser..
FiRaS is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading data from a text file into a C struct someone2088 C 1 Dec 7th, 2011 8:22 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:11 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC