Page 1 of 1

Embedded flash player

Posted: Thu Mar 11, 2010 3:42 pm
by captain_scarlet87
Hi,

I got this piece of code that displays all the .flv files in a certain folder as links to download them. I also have code which displays an embedded video player however a static link to the video is used.

Can someone please help me link these two codes together so that when the link of a video in the first piece of code is clicked it will take it to the embedded video player page and play the appropriate video. I would imagine this involves passing the .flv file location into the href but I am a total noob so don't know how to! :(

Please help if you can. Thanks.

Displays all .flv files currently in the folder:

Code: Select all

<?php
  $current_dir = "includes/videos/";    // Location to read files from.
  $dir = opendir($current_dir);        // Opens the directory.
 
  echo ("<p><h1>Video Tutorials:</h1></p><hr><br />");
  while ($file = readdir($dir))            // while loop
    {
    $parts = explode(".", $file);                    // pull apart the name and dissect by period
    if (is_array($parts) && count($parts) > 1) {    // does the dissected array have more than one part
        $extension = end($parts);        // set to we can see last file extension
        if ($extension == "flv"){    // Set allowable file extensions.
             echo "<a href=\"$current_dir/$file\" target=\"_blank\"> $file </a><br />";    // Link to location of video.
        }
       }
    }
  echo "<hr><br />";
  closedir($dir);        // Close the directory.
?>
</body>
</html>
 
Embedded video player:

Code: Select all

<html>
<head>
    <title>Videos</title>
    <script src="flowplayer/example/flowplayer-3.1.4.min.js"></script>
</head>
<body>
 
<a
    href="includes/videos/testflash.flv"
    style="display:block;width:425px;height:300px;"
    id="player">
</a>
 
<script language="JavaScript">
    flowplayer("player", "flowplayer/flowplayer-3.1.5.swf");
</script>
</body>
</html>

Re: Embedded flash player

Posted: Fri Mar 12, 2010 7:10 am
by cpetercarter
In your code, the links from the list of flv videos are to the videos themselves. Instead, you could link to the page which runs the flashplayer and pass a reference to the video you want to play in the URL query string (eg "videoplayer.php?video=myvideo").
In the videoplayer script, the name of the video to play will then be in $_GET['video'], and you can presumably then use this value to tell the flashplayer which video to play.

Re: Embedded flash player

Posted: Fri Mar 12, 2010 9:44 am
by captain_scarlet87
Hey, that is exactly what I want to do, however my skills with php are not great :? so if possible can anyone guide me exactly what code I need and where?

Thank you.