Dynamic (Random) wmv playlist embedded in page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
paulrobere1
Forum Newbie
Posts: 2
Joined: Sun Oct 29, 2006 1:40 am

Dynamic (Random) wmv playlist embedded in page

Post by paulrobere1 »

Hello,

I need to have a wmv video playback in the center of a homepage. I will have a folder full of video clips, and would like to generate random playlists using PHP that would play in that central section. So, when the page loads, a random video will play and when it completes, another random video will play, etc.

Using similar PHP that generates random text/html on a page, I'm able to generate 1 random video or 1 pre-determined playlist. But I cannot think of a way to generate a random playlist each time the page refreshes. I could create a bunch of pre-determined playlists and randomly load them into the page, but I'm trying to avoid this hack.

Also, I'd prefer to not to use a MySQL database for this (text file, etc. would be okay)

Although this isn't quite what I'm looling for, the following link shows the syntax to embed a static playlist into a page: http://www.webdeveloper.com/forum/showt ... hp?t=68571 <-- this is on the right track, but not dynamic/random.

Any help is appreciated :D thanks
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

All you have to do is 'generate' such a file.. the same way you generate html with php.. Which part keeps you from doing it? The only problem i can think of is that you need to send the appropriate content-type header...

Here's an untested suggestion:

Code: Select all

<?php header('Content-type: video/x-ms-wvx'); ?>
<ASX version="3.0">
<?php

function get_random_url() {
 $files = array('1.wmv', '2.wmv', '3.wmv');
 $index = rand(0, count($files));
 $random_url = 'http://example.com/' . $files[$index];
 return $random_url;
}

for ($i = 0; $i < 10; ++$i) {
 $random_url = get_random_url();
 echo '<ENTRY><REF http="' . $random_url . '"/></ENTRY>' . "\r\n";
}
?>
</ASX>
paulrobere1
Forum Newbie
Posts: 2
Joined: Sun Oct 29, 2006 1:40 am

thanks

Post by paulrobere1 »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


had to make some changes, but used your general concept, thanks. Here's the debugged conclusion:

Code: Select all

<ASX version="3.0"> 

<?
function get_random_url() { 
 $files = array('1.wmv', '2.wmv', '3.wmv'); 
 $index = rand(0, count($files)-1); 
  $random_url = "movies/" . $files[$index]; 
 
 return $random_url; 
} 

for ($i = 0; $i < 10; ++$i) { 
 $random_url = get_random_url(); 

 echo '<ENTRY><REF HREF="' . $random_url . '"/></ENTRY>' . "\r\n"; 
} 
?> 
</ASX>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
chaser7016
Forum Commoner
Posts: 34
Joined: Sat Nov 04, 2006 3:22 pm

Post by chaser7016 »

Does this work and in order for it to work its need to be a php enabled server?

How would I change this to create a randomized playlist detailing my favorite online radio stations. Id like to just click a playlist that has five of my favorite online stations in it and have the playlist just randomly begin to play one of the streams.

Thanks,
Chaser
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

chaser7016 wrote:Does this work and in order for it to work its need to be a php enabled server?
Apparently it does work (i wouldn't have expected it not to work :p).
I don't think it would be very hard to rewrite it in asp, asp.net, java servlet, jsp, or jsf, ...
chaser7016 wrote: How would I change this to create a randomized playlist detailing my favorite online radio stations.
You would have to make an array that contains the urls for your online radio stations. Then you would have to shuffle the radio stations and output an <entry> line foreach url.
chaser7016 wrote: Id like to just click a playlist that has five of my favorite online stations in it and have the playlist just randomly begin to play one of the streams.
How your http-useragent handle a file with a given content-type, in this case video/x-ms-wvx, depends on how you configure it (read: this has to be handled at the client-side, not the server-side).
chaser7016
Forum Commoner
Posts: 34
Joined: Sat Nov 04, 2006 3:22 pm

Post by chaser7016 »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi Tim

I tried coding the following, but it didnt work.

Code: Select all

<ASX version="3.0">
<ASX verion="3.0">
<script language="javascript">
<ENTRY>
var list = new Array;
list[0] = "<REF HREF="http://65.54.48.101:8000" />";
list[1] = "<REF HREF="http://58.32.32.100:8000" />";
list[2] = "<REF HREF="rtsp://wm.3wk.com/3wk1wm" />";
list[3] = "<REF HREF="http://33.23.24.101:8000" />";
var choice = Math.floor(Math.random() * list.length); document.write("<embed src='http://x.com/storage/audio/"+list[choice]+"' autostart='yes'>");</script></ENTRY>
</ASX>
What is wrong with my code...thanks in advance for any help you or any1 can extend!

cheers, Chaser


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Post Reply