[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 267
  • Last Modified:

Autoplay on Random mp3's from database?

Hello all,

I have a music room where I am trying to pull random mp3's out of the database and have them play automatically.  They will include the name of the cd, the song title, the artist, and all will be links to purchase the cd.  However, what I have now pulls the information out of the database, but I'm clueless on how I can get this to automatically play one after the other while showing the information.  I do know the file player I'm using probably won't work here, but I'm happy to not have any file player at all as long as it still plays somehow?  It's this one: http://www.macloo.com/examples/audio_player/options.html  Any ideas?

The code (please excuse my css and such, will be fixed later):
<?php
include ("dbinfo.php");
$result = mysql_query("SELECT * FROM cds ORDER BY RAND() LIMIT 10");  
while($row = mysql_fetch_array($result))
{
$cdnum=$row['cdnum'];
$cdnum=htmlspecialchars($cdnum);
$cdnum_sq=mysql_real_escape_string($cdnum);
$cdname=$row['cdname'];
$cdname=htmlspecialchars($cdname);
$cdname_sq=mysql_real_escape_string($cdname);
$cdname2=$row['cdname2'];
$cdname2=htmlspecialchars($cdname2);
$cdname2_sq=mysql_real_escape_string($cdname2);
$fileName=$row['fileName'];
$fileName=htmlspecialchars($fileName);
$fileName_sq=mysql_real_escape_string($fileName);
}

if ($cdname2!="")
{
$cd=$cdname." - ".$cdname2;
}
else
{
$cd=$cdname;
}

$result = mysql_query("SELECT * FROM `$cdnum_sq` WHERE songclip != '' ORDER BY RAND() LIMIT 10");  
while($row = mysql_fetch_array($result))
{
$artist=$row['artist'];
$artist=htmlspecialchars($artist);
$artist_sq=mysql_real_escape_string($artist);
$song=$row['song'];
$song=htmlspecialchars($song);
$song_sq=mysql_real_escape_string($song);
$year=$row['year'];
$year=htmlspecialchars($year);
$year_sq=mysql_real_escape_string($year);
$songclip=$row['songclip'];
$songclip=htmlspecialchars($songclip);
$songclip_sq=mysql_real_escape_string($songclip);
}

echo "<table>";
echo "<tbody>";
echo "<tr><td rowspan=\"3\">";
echo "<a href=\"http://www.mywebsite.com/item.php?ID=$cdnum_sq\">";
echo "<img src='$fileName' width=\"100\" height=\"100\">";
echo "</a>";
echo "</td></tr>";
echo "<tr><td valign=\"bottom\" style=\"padding:3px;\">";
echo "<a href=\"http://www.mywebsite.com/item.php?ID=$cdnum_sq\" \">";
echo "<b>";
echo "CD Name: ";
echo "</b>";
echo "</a>";
echo "</td><td valign=\"bottom\" style=\"padding:3px;\">";
echo "<a href=\"http://www.mywebsite.com/item.php?ID=$cdnum_sq\" \">";
echo "<b>";
echo "Song: ";
echo "</b>";
echo "</a>";
echo "</td><td valign=\"bottom\" style=\"padding:3px;\">";
echo "<a href=\"http://www.mywebsite.com/item.php?ID=$cdnum_sq\" \">";
echo "<b>";
echo "Artist: ";
echo "</b>";
echo "</a>";
echo "</td><td valign=\"bottom\" style=\"padding:3px;\">";
echo "<a href=\"http://www.mywebsite.com/item.php?ID=$cdnum_sq\" \">";
echo "<b>";
echo "Songclip: ";
echo "</b>";
echo "</a>";
echo "</td></tr>";
echo "<tr><td valign=\"top\" style=\"padding:3px;\">";
echo "<font color=\"black\">";
echo "<a href=\"http://www.mywebsite.com/item.php?ID=$cdnum_sq\">";
echo $cd;
echo "</a>";
echo "</font>";
echo "</td><td valign=\"top\" style=\"padding:3px;\">";
echo "<font color=\"black\">";
echo "<a href=\"http://www.mywebsite.com/item.php?ID=$cdnum_sq\">";
echo $song;
echo "</a>";
echo "</font>";
echo "</td><td valign=\"top\" style=\"padding:3px;\">";
echo "<font color=\"black\">";
echo "<a href=\"http://www.mywebsite.com/item.php?ID=$cdnum_sq\">";
echo $artist;
echo "</a>";
echo "</font>";
echo "</td><td valign=\"top\" style=\"padding:3px;\">";
echo "<object type=\"application/x-shockwave-flash\" data=

\"http://www.mywebsite.com/songs/player.swf\" id=\"audioplayer\" height=\"14\" width=
\"290\">";
echo "<param name=\"movie\" value=\"http://www.mywebsite.com/songs/player.swf\">";
echo "<param name=\"FlashVars\" value=

\"playerID=audioplayer&soundFile=http://www.mywebsite.com/$songclip\">";
echo "<param name=\"quality\" value=\"high\">";
echo "<param name=\"menu\" value=\"false\">";
echo "<param name=\"wmode\" value=\"transparent\">";
echo "</object>";
echo "</td></tr>";
echo "</tbody>";
echo "</table>";
?>

Open in new window

0
happysunny
Asked:
happysunny
  • 8
  • 5
4 Solutions
 
amiguraCommented:
reading the instruction on website i do not see auto play for next track only for first track

id on line 99 needs to be a unique id
id=\"audioplayer$cdnum_sq\"

Open in new window


0
 
happysunnyAuthor Commented:
I'm unsure why it has to be unique when it is just one player playing different songs one at a time?
0
 
amiguraCommented:
o sorry i did not relies, anyway i found the developer website with the newer one its possible

http://wpaudioplayer.com/standalone/
0
Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

 
happysunnyAuthor Commented:
Nothing shows up at all when I try that one.  This isn't for Wordpress, it's just the one I chose.  Another audio player is fine, if you can recommend one that's easier to implement.
0
 
amiguraCommented:
if that don't work here is a list of other players, can't recommend as i have not used any, sorry
http://www.instantshift.com/2010/02/10/21-free-music-players-for-your-website/



change paths on line 7,9,65

<html>  
    <head>  
        <title>Your website</title> 
         
   // change paths to player
   
        <script type="text/javascript" src="path/to/audio-player.js"></script>  
        <script type="text/javascript">  
            AudioPlayer.setup("http://yoursite.com/path/to/player.swf", {  
                width: 290  
            });  
        </script>  
  
    </head>  
    <body>  


<?php
include ("dbinfo.php");
$result = mysql_query("SELECT * FROM cds ORDER BY RAND() LIMIT 10");  
while($row = mysql_fetch_array($result))
{
$cdnum=$row['cdnum'];
$cdnum=htmlspecialchars($cdnum);
$cdnum_sq=mysql_real_escape_string($cdnum);
$cdname=$row['cdname'];
$cdname=htmlspecialchars($cdname);
$cdname_sq=mysql_real_escape_string($cdname);
$cdname2=$row['cdname2'];
$cdname2=htmlspecialchars($cdname2);
$cdname2_sq=mysql_real_escape_string($cdname2);
$fileName=$row['fileName'];
$fileName=htmlspecialchars($fileName);
$fileName_sq=mysql_real_escape_string($fileName);
}

if ($cdname2!="")
{
$cd=$cdname." - ".$cdname2;
}
else
{
$cd=$cdname;
}

$result = mysql_query("SELECT * FROM `$cdnum_sq` WHERE songclip != '' ORDER BY RAND() LIMIT 10");  
while($row = mysql_fetch_array($result))
{
$artist=$row['artist'];
$artist=htmlspecialchars($artist);
$artist_sq=mysql_real_escape_string($artist);
$song=$row['song'];
$song=htmlspecialchars($song);
$song_sq=mysql_real_escape_string($song);
$year=$row['year'];
$year=htmlspecialchars($year);
$year_sq=mysql_real_escape_string($year);
$songclip=$row['songclip'];
$songclip=htmlspecialchars($songclip);
$songclip_sq=mysql_real_escape_string($songclip);


$song_set.= "$song,";
$artist_set.= "$artist,";
$track_set.= "http://yoursite.com/path/to/$artist,"; // set correct path

}

?>


<script type="text/javascript">  
AudioPlayer.embed("audioplayer_1", {  
    soundFile: "<?php echo sub_str($track_set,0,-1); ?>",  
    titles: "<?php echo sub_str($song_set,0,-1); ?>",  
    artists: "<?php echo sub_str($artist_set,0,-1); ?>"  
});  
</script>  


 </body>  
</html>  

Open in new window

0
 
happysunnyAuthor Commented:
I'm trying to try your code above...what is line 65 for?  I'm confused...Is it supposed to be path to songclip?
0
 
happysunnyAuthor Commented:
Okay, I tried to use your code, but it comes up a blank page.  It's not working.  Is there any other way to do this?
0
 
happysunnyAuthor Commented:
Ahhh...I got it!!!!

I added this...
<META HTTP-EQUIV=Refresh CONTENT="30; URL=http://www.yoursite.com/yoururl.php">

Open in new window


and then added autostart=yes& to this:
echo "<object type=\"application/x-shockwave-flash\" data=\"http://www.mywebsite.com/songs/player.swf\" id=\"audioplayer\" height=\"14\" width=\"290\">";
echo "<param name=\"movie\" value=\"http://www.mywebsite.com/songs/player.swf\">";
echo "<param name=\"FlashVars\" value=\"playerID=audioplayer&autostart=yes&soundFile=http://www.mywebsite.com/$songclip\">";
echo "<param name=\"quality\" value=\"high\">";
echo "<param name=\"menu\" value=\"false\">";
echo "<param name=\"wmode\" value=\"transparent\">";
echo "</object>";

Open in new window


Works exactly like I wanted :)
0
 
amiguraCommented:
v good. yeah i have been trying to make it work but it doesn't seem to show up.

note:
if you are selling mp3, make sure you are playing previews from a preview directory rather than a direct link to full mp3 directory
0
 
happysunnyAuthor Commented:
Actually, it's just snippets of songs from cds that are being sold.  Should I be using a directory for that?  As you can probably tell from above, I'm putting the mp3s in a directory and the link to it in the database.  Is there a better way?
0
 
amiguraCommented:
how you are doing it is fine. just as long as the file you are selling is in another directory.
because you can view the source code in a browser then see where the directory is and download the songs directly without paying.

domain/preview/low_quality.mp3
domain/secretdir/high_quality.mp3

- low quality for preview also saves on bandwidth
- just state that its a low quality mp3 for preview only

0
 
happysunnyAuthor Commented:
I see.  Awesome, thank you :)
0
 
happysunnyAuthor Commented:
I accepted my comment as solution, because I got it figured out.  However, I gave points for you helping, which I really appreciate :)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 8
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now