Forum Moderators: coopster

Message Too Old, No Replies

Media Player Issue

         

haywars

10:55 pm on May 31, 2010 (gmt 0)

10+ Year Member



Hello Everyone,

I have a test site here:
snipped


What I am trying to do is that when a user clicks on the speaker button a hidden media player (Javascript) will become visible and will load that mp3 file.

Currently when I click the speaker it just loads the actual audio file from the tables path.

Current Code:

<html>
<head>
<title></title>

</head>
<body>

<br />
<table border="1" width="75%" cellpadding="2" cellspacing="2">
<tr>
<td align="center">Cue Code</td>
<td align="center">Cue Title</td>
<td align="center">Cue Description</td>
<td align="center">Time</td>
<td align="center"></td>
</tr>
<?php
mysql_connect("******", "***", "****") or die(mysql_error());
echo "Connected to MySQL<br /><hr />";
mysql_select_db("music") or die(mysql_error());
echo "Connected to Database<br /><hr />";
$query = "SELECT * FROM tracks";
$result = mysql_query($query) or die(mysql_error());
while($line = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td align='center'>".$line[cue_code]."</td>";
echo "<td align='center'>".$line[cue_title]."</td>";
echo "<td align='center'>".$line[cue_description]."</td>";
echo "<td align='center'>".$line[time]."</td>";
echo "<td align='center'><a href='$line[audiolocation]'><img src='http://opus1.o1engine.com/img/speaker_dark.gif' border=0></a>";
echo "</tr>";
}
?>
</table>
</body>
</html>


Any help would be greatly appreciated.

[edited by: coopster at 11:29 am (utc) on Jun 2, 2010]
[edit reason] no personal urls please [/edit]

Matthew1980

12:42 am on Jun 1, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there haywars,

I'm not sure whether you can do a mysql_connect call like you are without assigning it to a var first, as this then acts as the connection handle for subsequent mysql_ function connection references. For example:-

<?php
$conn = mysql_connect("******", "***", "****") or die(mysql_error());
mysql_select_db("music", $conn) or die(mysql_error());

$query = "SELECT * FROM tracks";
$result = mysql_query($query, $conn) or die(mysql_error());

This should now work as a valid connection, I would be amazed it it worked before ;)

Also for your while statement, as you are in the loop, you needn't have everything in an echo, you could just break in and out of php, this will be less over head for your parser/cpu in the long run and makes the HTML editing easier ;)

But ;) as you are, you need to correct this (and similar):-

echo "<td align='center'>".$line[cue_code]."</td>";

to this:-

echo "<td align='center'>".$line['cue_code']."</td>";

because there will more than likely be a notice error flagged up about 'undefined index - presumed constant' if you have error reporting turned on :)

Lastly, as you are echoing the HTML you need to do the toothpick thing to the link, like this:-

echo "<td align=\"center\"><a href=\".$line['audiolocation'].\"><img src=\"http://opus1.o1engine.com/img/speaker_dark.gif\" border=0></a>";

You get the idea there, I think that you may have to play around with that though as using the toothpick (escaping the quotes) gets confusing - this is why I suggested doing it like this:-

while($line = mysql_fetch_array($result)) {
?>
<tr>
<td align="center"><?php echo $line['cue_code'];?></td>
<td align="center"><?php echo $line['cue_title'];?></td>
<td align="center"><?php echo $line['cue_description'];?></td>
<td align="center"><a href="<?php echo $line['audiolocation'];?>"><img src="http://opus1.o1engine.com/img/speaker_dark.gif" border=0></a></td>
</tr>
<?php
}

Oh, and your missing your last closing </td> from your table cell before you close it ;)

Don't mean to witter on, just thought it was worth pointing out some rudimentary things there ;)

And just for future post's try to exemplify your address' use example.com as the mods will more than likely change it..

As for the mp3, you are telling it to download, you need to embed it using a plugin, just google it, there are lost of places to help with that.

This is the type of code you need:-

<embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" name="mediaplayer1" ShowStatusBar="true" EnableContextMenu="false" autostart="false" width="320" height="240" loop="false" src="mymp3.mp3" />

you just need to change the type to whatever mp3 is, hope that helps,

Happy coding,

Cheers,
MRb

haywars

2:43 am on Jun 1, 2010 (gmt 0)

10+ Year Member



Thanks for the reply and your suggestions helped alot as I am working on it locally to speed up time. But I think the embed area would be alot more complicated then a embed tag as the part of the site im trying to duplicate is from this site: snipped url.

Im trying to make a hidden media player above my table I have my media player script but I cant seem to figure out how to make it work with a database. (MySQL is still new to me)

[edited by: coopster at 11:30 am (utc) on Jun 2, 2010]
[edit reason] no urls please [/edit]