Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 468
  • Last Modified:

How to create a dynamic play list on the fly?

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
andreni78
Asked:
andreni78
  • 7
  • 4
  • 3
2 Solutions
 
hernst42Commented:
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
 
hernst42Commented:
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
 
merwetta1Commented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
andreni78Author Commented:
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
 
hernst42Commented:
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
 
hernst42Commented:
and the information come from a post-form
so also replace $_POST with $_GET to make the ?movie_choice=moview

work
0
 
merwetta1Commented:
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
 
andreni78Author Commented:
w/ the POST method.. how would I specify the movie I want to display? thanks for all your help btw...
0
 
merwetta1Commented:
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
 
andreni78Author Commented:
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
 
andreni78Author Commented:
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
 
andreni78Author Commented:
nevermind.. i don't need it in include anymore.. wonder how i would make include work though?
0
 
andreni78Author Commented:
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
 
andreni78Author Commented:
nevermind i got it solved.. thanks for your help!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 7
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now