Hi, I am trying to create a playlist using a multidimesional array. Where the user will select a song to hear from a radio button and when they do they will hear the song on the url that I have for that song. I am not sure if I am headed in the right direction. I believe the array is suppose to go as follows:

<?php
$songs = array(
  'Christina Aguilera'=>array(
    'Impossible',
    'Beautiful',
    'Dirrty'
  ),
  'Pink'=>array(
    'Just like a pill',
    'Family potrait',
    'Missundaztood'
  ),
  'Kelly Rowland'=>array(
    'Stole',
    'Obsession',
    'Past 12'
  )
);


?>

but I am trying to see how would I send them to the url to listen to the song after they have selected the song.

Member Avatar for diafol

You can certainly do this with DB, an array, or with XML or json data. The problem with an array, as is, is that you haven't included an id or an url. The id just gives a hook to link to the url to insert into an mp3 player.

I've used xspf player in the past: http://musicplayer.sourceforge.net/

It's flash-based and allows you to apply playlists. Data is stored in an xml-type file. Maybe worth a look. That was two years ago. I think you could reference mp3 files on other domains as well.

so I just add an url to to each song in the array...I have to do this in php and cannot use anything else but html

Member Avatar for diafol

well the app I mentioned uses php to create the xml playlist, or at least the solution I created did. Was a while ago. Twas a throw-away project, so unfortunately I don't have it anymore.

You can only use html? Are you using html5 audio? Most online mp3 players use flash. The odd one may use Java. How are you playing said songs?

I am suppose to reference each song to a url link such as you tube using href in mutli dimensional array holding the songs

such as if they select the song impossible by christina it should direct them to this link
http://www.youtube.com/watch?v=-vtRSTM1zMo

Member Avatar for diafol

Ok, is this a homework assignment?

is is an extra credit assignment or school

Member Avatar for diafol

OK, so far you've got radio buttons in your html? How about showing your complete code? We need to see how you've constructed the html from the php array.

This is my input form with the radio buttons that I have so far...but I am trying to figure out what to do on the output form ...such as when they select a song how do I have to play the song automatically. Do I used href and the url and put it in the array next to each song?

What Song would you like to hear:<br>

<html>
<body>

<form action='p6output.php' method='POST'>
<p><input type="radio" name="song[0]" value="mygirl">My Girl<br>
<input type="radio" name="song[1]" value="">Get Ready<br>
<input type="submit" name="submit" value="Submit"></p>
</form>
</body>
</html>
Member Avatar for diafol
$songs 	=>	array(
		"Pink Floyd"	=>	array(
						array("Comfortably Numb", "/tracks/pf/uio.mp3"),
						array("Wish You Were Here, "tracks/pf/wish.mp3")
    					),
   		"Meic Stevens"	=>	array(
						array("Nos Du, Nos Da","tracks/meic/ndnd.mp3")
					),
		"Black Sabbath"	=>	array(
						array("Never Say Die","old_tracks/sabbath/never_say_die.mp3"),
						array("Sweet Leaf", "audio/sweet.mp3")
					)
		);

The above structure will give a key for the artist and then values for various songs.

$song[0][0][0] will give "Comfortably Numb".
(1st artist/1st song/title)
$song[2][1][1] will give "audio/sweet.mp3".
(3rd artist/2nd song/url)


So, using a loop you can create your list of songsand output the url:

PSEUDOCODE

loop from the first artists to the last...
  loop from the first song to the last...
    if the artist has changed - make an artist title in the form (e.g. <h3>) 
      echo a radio input, with name attribute: e.g. name = "song[0][1]" (artist0, song1
   
  end loop   
end loop

/?EDIT - Just leaving work and looked at this - hmm, I don't think the php code I included will work - keys all wrong. SOrry, will tune in again later.

thanx alot I think I understand how to add a url to the array. I am going to try it and see

ok everything is good except the video is not showing. Is it possible to embed a youtube video in php? if so how?

Hello this is very nice thread. Thanks For sharing sch a nice information. Take care.

Member Avatar for diafol

YT in php - you can store the id and 'transplant it into a generic YT iframe container via ajax. OR you can store the entire iframe (see embed code in YT itself) in the array.

An example of the whole code:

<iframe title="YouTube video player" width="640" height="390" src="http://www.youtube.com/embed/jVje1Fiz-_c?rel=0" frameborder="0" allowfullscreen></iframe>

Or just the id: jVje1Fiz-_c

You can place this so:

<iframe title="YouTube video player" width="640" height="390" src="http://www.youtube.com/embed/<?php echo $video_id;?>?rel=0" frameborder="0" allowfullscreen></iframe>

I haven't tried using js to change the iframe video - but this would be better as you wouldn't have to refresh.

Member Avatar for diafol

Yes it works:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script>
function change(){
  document.getElementById("video").setAttribute("src", "http://www.youtube.com/embed/jVje1Fiz-_c");
}
</script>
</head>

<body>

<iframe id="video" title="YouTube video player" width="640" height="390" src="http://www.youtube.com/embed/hbIZy3EBpPE?rel=0" frameborder="0" allowfullscreen></iframe>
<button onclick="change();return false;">CHANGE</button>

</body>
</html>

I am trying to use an input form where they will select a song I am trying to see if it is possible to do something like this in php because it is not loading the video for me when I try. it seems like it is trying to but it never comes up


<?php
$a = 'http://www.youtube.com/embed/bZh7nRw6gl8'

?> <object width="425" height="350"><param name="movie" value="$a"></param><param name="wmode" value="transparent"></param><embed src="$a" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>

Member Avatar for diafol

Once you close the php tags. No php, unless you open a new set. So your code won't work.

<?php
$a = 'http://www.youtube.com/embed/bZh7nRw6gl8';

?> 

<object width="425" height="350"><param name="movie" value="<?php echo $a;?>"></param><param name="wmode" value="transparent"></param><embed src="<?php echo $a;?>" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>

Should work.

thanx for all your help but that wouldnt work either. I guess I may have to just try another way

Member Avatar for diafol

Further to my original post with the js. This works.
No reload.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript" >
 $(document).ready(function() {
    $('#vlist a').click(function() {
  		var code = $(this).attr("rel");
  		$("#video").attr("src","http://www.youtube.com/embed/" + code + "?rel=0");
	});
 });
</script>
</head>
 
<body>
 
<iframe id="video" title="YouTube video player" width="640" height="390" src="http://www.youtube.com/embed/hbIZy3EBpPE?rel=0" frameborder="0" allowfullscreen></iframe>
<ul id="vlist">
	<li><a href="#" rel="Z2wzpfPFBlw">Judas Priest: Nightcrawler</a></li>
	<li><a href="#" rel="4O_YMLDvvnw">Gary Moore: Still Got The Blues (Live)</a></li>
	<li><a href="#" rel="dGoYmRoBF4Q">Gary Moore: Parisienne Walkways< (Live)</a></li>
</ul>
 
</body>
</html>

You can also create your own playlist in YT if you have an account. This may be a better option?

Oh no! I just realised - no php involved! Oh well - you can always use php to parse the html in the playlist from an array.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.