Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Playing random videos from a folder?
Old 05-01-2010, 04:21 PM Playing random videos from a folder?
Skilled Talker

Posts: 53
Trades: 0
Hey guys, I just finished installing flowplayer (video player for my website) on my server but I would like flowplayer to play random videos from a folder on my server everytime the page is refreshed. I have no idea how I could go about doing this. But I'm fairly certain it would involve some PHP, hence why I post my question here. If anybody can point me in the right direction it would be greatly appreciated.
worldy is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-04-2010, 08:18 AM Re: Playing random videos from a folder?
Extreme Talker

Posts: 181
Name: David Jackson
Trades: 0
how much PHP do you know
__________________

Please login or register to view this content. Registration is FREE
davidj is offline
Reply With Quote
View Public Profile
 
Old 05-06-2010, 11:21 AM Re: Playing random videos from a folder?
Skilled Talker

Posts: 53
Trades: 0
My PHP knowledge is very limited, so not that much. But I can manipulate existing PHP code.
worldy is offline
Reply With Quote
View Public Profile
 
Old 05-06-2010, 12:23 PM Re: Playing random videos from a folder?
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
This code should accomplish what you're looking for. Make sure to set $path to the path where your videos are stored. Just make sure that directory contains only playable videos, the function I wrote just picks a random file from the given path (or you can use a regular expression to only pick files with a certain extension).

PHP Code:
<?php
function getRandomFile($path)
{
    
$files = array();
    
    foreach( new 
DirectoryIterator($path) as $file )
    {
        if(
$file->isFile())
        {
            
$files[] = $path $file->getFilename();
        }
    }
    
    
$i array_rand($files);
    return 
$files[$i];
}

$path './';

$file getRandomFile($path);

/*
the following code is from the documentation: 
http://flowplayer.org/documentation/installation/index.html
*/
?>
<a 
    href="<?php echo $file?>
    style="display:block;width:425px;height:300px;" 
    id="player">
</a>
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 05-06-2010 at 12:31 PM..
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 05-07-2010, 02:30 PM Re: Playing random videos from a folder?
Skilled Talker

Posts: 53
Trades: 0
Thanks for your help. I tried implementing your code as follows but I get a fatal error. Any ideas? The videos are stored in a folder on my server called "vids"


PHP Code:
<?php
function getRandomFile($path)
{
    
$files = array();
    
    foreach( new 
DirectoryIterator($path) as $file )
    {
        if(
$file->isFile())
        {
            
$files[] = $path $file->getFilename();
        }
    }
    
    
$i array_rand($files);
    return 
$files[$i];
}

$path 'http://www.mysite.com/vids';
/*
I also tried just     $path = '/vids'
*/

$file getRandomFile($path);
?>


/*
the following code is from the documentation:
http://flowplayer.org/documentation/...ion/index.html
*/
HTML Code:
<a 
    href="<?php echo $file; ?>" 
    style="display:block;width:425px;height:300px;" 
    id="player">
</a>
<script language="JavaScript">
    flowplayer("player", "/flowplayer-3.1.5.swf");
</script>
<br clear="all" />

Last edited by chrishirst; 05-07-2010 at 05:50 PM..
worldy is offline
Reply With Quote
View Public Profile
 
Old 05-07-2010, 03:27 PM Re: Playing random videos from a folder?
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
My mistake, try:
PHP Code:
function getRandomFile($path)
{
    
$files = array();

    foreach( new 
DirectoryIterator($path) as $file )
    {
        if(
$file->isFile())
        {
            
$files[] = $path $file->getFilename();
        }
    }

    
$i array_rand($files);
    return 
$files[$i];
}

$path './vids';
$url 'http://mysite.com/';
$file getRandomFile($path);

echo 
str_replace('./'$url$file); 
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 05-08-2010, 11:44 AM Re: Playing random videos from a folder?
Skilled Talker

Posts: 53
Trades: 0
Now it works. Thanks for your help NullPointer, much appreciate it.
worldy is offline
Reply With Quote
View Public Profile
 
Old 06-20-2011, 12:02 AM Re: Playing random videos from a folder?
Junior Talker

Posts: 2
Trades: 0
Hey I know this is an old thread, But Im doing the same thing. I use this php code, and it doesnt work. All I get is a page full of code
snyperthugs is offline
Reply With Quote
View Public Profile
 
Old 06-20-2011, 11:11 AM Re: Playing random videos from a folder?
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
Have you enclosed it in <?php ?> tag? Is file named something.php?
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is offline
Reply With Quote
View Public Profile
 
Old 06-20-2011, 01:48 PM Re: Playing random videos from a folder?
Junior Talker

Posts: 2
Trades: 0
yes I tried all of that but just wouldnt work. But I did get it to do what I wanted it to do. I used an Image Rotator script and just modified it to use with flv files
snyperthugs is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Playing random videos from a folder?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.31732 seconds with 12 queries