Solved

How to create a dynamic play list on the fly?

Posted on 2004-10-10
14
449 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
  • 7
  • 4
  • 3
14 Comments
 
LVL 48

Expert Comment

by:hernst42
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:andreni78
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:andreni78
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
nevermind.. i don't need it in include anymore.. wonder how i would make include work though?
0
 

Author Comment

by:andreni78
Comment Utility
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
Comment Utility
nevermind i got it solved.. thanks for your help!
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now