Solved

How to create a dynamic play list on the fly?

Posted on 2004-10-10
14
460 Views
Last Modified: 2008-03-10
If you don't know what ASX file type is.. it's just a video playlist.. it's very simple.. here's what it looks like:
<ASX Version="3">

<ENTRY>
    <REF HREF="http://www.mysite.com/video/mymovie2-1.wmv"/>
</ENTRY>

      <ENTRY ClientSkip="no">
                <REF HREF="http://www.mysite.com/video/ads/ads_coke1.wmv"/>
      </ENTRY>

<ENTRY>
    <REF HREF="http://www.mysite.com/video/mymovie2-2.wmv"/>
</ENTRY>

      <ENTRY ClientSkip="no">
                <REF HREF="http://www.mysite.com/video/ads/ads_pepsi1.wmv"/>
      </ENTRY>

<ENTRY>
    <REF HREF="http://www.mysite.com/video/mymovie2-3.wmv"/>
</ENTRY>

      <ENTRY ClientSkip="no">
                <REF HREF="http://www.mysite.com/video/ads/ads_coke1.wmv"/>
      </ENTRY>

<ENTRY>
    <REF HREF="http://www.mysite.com/video/mymovie2-4.wmv"/>
</ENTRY>

      <ENTRY ClientSkip="no">
                <REF HREF="http://www.mysite.com/video/ads/ads_pepsi2.wmv"/>
      </ENTRY>

<ENTRY>
    <REF HREF="http://www.mysite.com/video/mymovie2-5.wmv"/>
</ENTRY>

</ASX>

The asx file can use the extension .php so that i can use php to make the asx play list dynamic...

so i was wondering.. as you can see i have ad videos.. and main content videos..

i want to have a file name playlist.php.. in it contains the ASX playlist like shown above..

i want the ASX playlist to created in this way:

how can i make the asx file put mymovie2-3.wmv first(because the user requested that specific file) and the list would automatically put mymovie2-1,mymovie2-2,mymovie2-4, mymovie2-5  in that order.. and the ads in between would be in random order?

so if the user requested mymovie2-4.. the playlist would put mymovie2-4 first.. then mymovie2-1 then mymovie2-2, mymovie2-3,mymovie2-5.. with random commercials in between?

if you need more clarification please ask! thanks for your help!
0
Comment
Question by:andreni78
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
  • 3
14 Comments
 
LVL 48

Expert Comment

by:hernst42
ID: 12274862
Store all files of the playlist in two array and the nshow them to the user: The following code (untested) should give you the directon how to do that:
playlist.php:
---------------------------------------------------------------------------------
<ASX Version="3">
<?php
function showEntry($url, $opts = '') {
    echo "\n<ENTRY $opts>\n\t<REF HREF="$url"/>\n</ENTRY>\n";
}

$movies = array (
  'mymovie2-1' => "http://www.mysite.com/video/mymovie2-1.wmv"),
  'mymovie2-2' => "http://www.mysite.com/video/mymovie2-2.wmv"),
  [...]
);

$comercial = array(
  "http://www.mysite.com/video/ads/ads_coke1.wmv",
  "http://www.mysite.com/video/ads/ads_pepsi1.wmv",
  [...]
);

//randomize commercials
shuffle($comercial);

if (isset($_GET['movie'])) {
    showEntry($movies[$_GET['movie']]);
    //remove entry from the playlist
    unset($movies[$_GET['movie']]);
    reset($movies);
}else {
     // show first entry of list
    reset($movies);
    showEntry(next($movies));
}

// show the ads and movies
while ($url = next($movies)) {
    $ad = next($comercial);
    if (!$ad) {
        // no more ads in the list, start from the beginning
        //randomize commercials
        shuffle($comercial);
        reset($comercial);
        $ad = next($comercial);
    }
    showEntry($ad, '  ClientSkip="no"');
    showEntry($url);
}

?>
</ASX>
0
 
LVL 48

Expert Comment

by:hernst42
ID: 12274870
to bring the movie mymovie2-2 as first title to play call the script with:
playlist.php?movie=mymovie2-2

also change the line
if (isset($_GET['movie'])) {
to
if (isset($_GET['movie']) && isset($movies[$_GET['movie']])) {

so only if such a movoe is found it will be place on the top, else it will show the standard list
0
 
LVL 6

Expert Comment

by:merwetta1
ID: 12274899
here's my take on it:

<?

echo '<ASX Version="3">'."\n";

## store movies and ads in arrays
$ad_array[] = 'ads_coke1.wmv';
$ad_array[] = 'ads_pepsi1.wmv';
$ad_array[] = 'ads_pepsi2.wmv';

$movie_array[] = 'mymovie2-1.wmv';
$movie_array[] = 'mymovie2-2.wmv';
$movie_array[] = 'mymovie2-3.wmv';
$movie_array[] = 'mymovie2-4.wmv';
$movie_array[] = 'mymovie2-5.wmv';

## move chosen movie to front of movie array
## in this example, chosen movie would be in POST var $movie_choice
if ($key = array_search($_POST[$movie_choice], $movie_array))
{
      $chosen_movie = $movie_array[$key];
      unset($movie_array[$key]);
      array_unshift($movie_array, $chosen_movie);
}

## display each movie entry with a random ad
foreach($movie_array as $movie)
{
?>
      <ENTRY>
          <REF HREF="http://www.mysite.com/video/<? echo $movie; ?>"/>
      </ENTRY>
<?
      $rand_key = array_rand($ad_array);
?>
      <ENTRY>
          <REF HREF="http://www.mysite.com/video/ads/<? echo $ad_array[$rand_key]; ?>"/>
      </ENTRY>
<?
}

echo '</ASX>';

?>
0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

Author Comment

by:andreni78
ID: 12274955
merwetta1... so with your method.. i can refer to your play list as..

playlist.php?movie_choice=mymovie2-2

and it should play mymovie2-2 first and the rest in sequential order after that right?
0
 
LVL 48

Assisted Solution

by:hernst42
hernst42 earned 150 total points
ID: 12274976
Yes if you fix that bug in the line
if ($key = array_search($_POST[$movie_choice], $movie_array))
to:
if ($key = array_search($_POST['movie_choice'], $movie_array))
0
 
LVL 48

Expert Comment

by:hernst42
ID: 12274982
and the information come from a post-form
so also replace $_POST with $_GET to make the ?movie_choice=moview

work
0
 
LVL 6

Expert Comment

by:merwetta1
ID: 12279593
andreni,

in my example, i had the selected movie coming in as a POST variable from a form. if you want to call the movie with a GET variable (playlist.php?movie_choice=mymovie2-2) you just have to change $_POST['movie_choice'] to $_GET['movie_choice'], as hernst mentioned (and the bug fix he mentions too).

but why use a GET variable? you would have to receive the results of your form, form the URL with the correct query string/GET variable, and then do a header redirect or something to load the page that plays the movie. if you use a POST var, you can have this script receive the results of your form and begin playing the movie immediately without a header redirect.
0
 

Author Comment

by:andreni78
ID: 12280783
w/ the POST method.. how would I specify the movie I want to display? thanks for all your help btw...
0
 
LVL 6

Accepted Solution

by:
merwetta1 earned 350 total points
ID: 12281185
I'm not sure how you use ASX lists with a web browser. Can you just output the ASX list directly to a browser to get it to play the list?

To elaborate on my suggestion, let's say this script is called "playmovie.php" and you wanted to offer a pulldown menu of movies to choose from. You would have an HTML form similar to this:

<form action="playmovie.php" method="post">
      Select a movie:
      <select name="movie_choice">
            <option value="mymovie2-1.wmv">mymovie2-1</option>
            <option value="mymovie2-2.wmv">mymovie2-2</option>
            <option value="mymovie2-3.wmv">mymovie2-3</option>
            <option value="mymovie2-4.wmv">mymovie2-4</option>
            <option value="mymovie2-5.wmv">mymovie2-5</option>
      </select>
      <input type="submit">
</form>

The script would then generate the ASX list for you. If you can output the ASX list directly to a browser, the script will work as written. If you need your ASX list in a file, instead of echoing the ASX entries, you would write them to a file and then use headers to transmit the file. Hope that helps!
0
 

Author Comment

by:andreni78
ID: 12281318
ah i c.. the way my site works is.. users click on a thumbnail picture of the clip they want to see.. and the rest of the main contents follow in sequential order with ad content in between randomly.. i guess that makes the GET method most useful for what i'm doing... i'll will start implementing the GET method and will post back my progress.. Thank you Merwetta1 and hernst42!!
0
 

Author Comment

by:andreni78
ID: 12284815
i tried adding the movie/ad array as an include file.. but it wouldn't work when i make it as an include file...
in the include file.. i have this:

$ad_array[] = 'ads_coke1.wmv';
$ad_array[] = 'ads_pepsi1.wmv';
$ad_array[] = 'ads_pepsi2.wmv';

$movie_array[] = 'mymovie2-1.wmv';
$movie_array[] = 'mymovie2-2.wmv';
$movie_array[] = 'mymovie2-3.wmv';
$movie_array[] = 'mymovie2-4.wmv';
$movie_array[] = 'mymovie2-5.wmv';


here's the playlist.php file:

<?

echo '<ASX Version="3">'."\n";

## store movies and ads in arrays
include('http://www.mysite.com/movie_list.inc');

## move chosen movie to front of movie array
## in this example, chosen movie would be in POST var $movie_choice
if ($key = array_search($_POST[$movie_choice], $movie_array))
{
     $chosen_movie = $movie_array[$key];
     unset($movie_array[$key]);
     array_unshift($movie_array, $chosen_movie);
}

## display each movie entry with a random ad
foreach($movie_array as $movie)
{
?>
     <ENTRY>
         <REF HREF="http://www.mysite.com/video/<? echo $movie; ?>"/>
     </ENTRY>
<?
     $rand_key = array_rand($ad_array);
?>
     <ENTRY>
         <REF HREF="http://www.mysite.com/video/ads/<? echo $ad_array[$rand_key]; ?>"/>
     </ENTRY>
<?
}

echo '</ASX>';

?>

how do i make the include file work? thanks!!
0
 

Author Comment

by:andreni78
ID: 12285546
nevermind.. i don't need it in include anymore.. wonder how i would make include work though?
0
 

Author Comment

by:andreni78
ID: 12296298
hi i'm having trouble with something... i want to $_GET a variable inside a php string.. how do i do it?

here's the code

<?php include('http://www.mysite.com/inc/watch_<?php echo $_GET['type']; ?>_1.inc'); ?>

as you can see.. i want the variable 'type' to be right in between the "watch_"  and  "_1.inc" file name..

how can i achieve this?

right now i'm getting this error:

Parse error: parse error, unexpected T_STRING in d:\web\mysite\watch\index.php on line 16

any help is appreciated... Thanks!
0
 

Author Comment

by:andreni78
ID: 12303631
nevermind i got it solved.. thanks for your help!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question