SimplePortal

Development => Feature Requests => Topic started by: Old Fossil on April 07, 2010, 11:51:53 AM

Title: Random Youtube Video ( Crazy Idea?)
Post by: Old Fossil on April 07, 2010, 11:51:53 AM
OK so we have the random photos in the gallery blocks.

What about random video clips?

Not so much a request as a brainwave.

Probably me being ambitious.
Title: Re: Random Youtube Video ( Crazy Idea?)
Post by: Nathaniel on April 07, 2010, 06:39:51 PM
Doesn't sound too hard.

Here is a youtube video clip example:
Code: [Select]
$videos = array(
    'id1',
    'id2',
    'id3',
    'id4',
// Add more ids there list this:   
//  'id',
);


$video = $videos[rand(0, count($videos) - 1)];

echo '<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/', $video, '&hl=en_US&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/', $video, '&hl=en_US&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object>';

You will need to extract the youtube id yourself, usually its something like 'h5isi4kjf' which is within the url.

When watching a video at youtube the format of the url is: "http://www.youtube.com/watch?v={id}" (Hopefully that should help).
Title: Re: Random Youtube Video ( Crazy Idea?)
Post by: Old Fossil on April 07, 2010, 06:41:58 PM
Thanks bud.

Thought I was being too ambitious then.

Surprised no one else has thought of it.
Title: Re: Random Youtube Video ( Crazy Idea?)
Post by: Nathaniel on April 07, 2010, 06:45:15 PM
Well, its easy because youtube provide their own embed code, if it was a matter of trying to show videos from a whole bunch of sources it would be more annoying. ;)
Title: Re: Random Youtube Video ( Crazy Idea?)
Post by: Old Fossil on April 07, 2010, 06:46:45 PM
Would i get away with having two embeds in one block as they come?
Title: Re: Random Youtube Video ( Crazy Idea?)
Post by: Nathaniel on April 07, 2010, 06:52:32 PM
Something like this?
Code: [Select]
$videos = array(
    'id1',
    'id2',
    'id3',
    'id4',
// Add more ids there list this:   
//  'id',
);

$video = $videos[rand(0, count($videos) - 1)];

echo '
<div style="float: left;">
<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/', $video, '&hl=en_US&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/', $video, '&hl=en_US&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object>
</div>';

$video2 = $video;
while ($video2 == $video)
$video2 = $videos[rand(0, count($videos) - 1)];

echo '
<div style="float: left;">
<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/', $video2, '&hl=en_US&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/', $video2, '&hl=en_US&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object>
</div>';

That code will show two unique videos horizontally next to each other, if you want them to be shown vertically that will be easy to change.
Title: Re: Random Youtube Video ( Crazy Idea?)
Post by: Old Fossil on April 07, 2010, 07:07:05 PM
Oops sorry bud.

I meant one then a different one after a page refresh.

Title: Re: Random Youtube Video ( Crazy Idea?)
Post by: Nathaniel on April 07, 2010, 07:09:46 PM
That should happen if you have enough video ids. Although sometimes the php rand function will return the same value for your two page views, its just unlucky if you happen to load the same video twice in a row, stopping it from happening would take more effort. ;)
Title: Re: Random Youtube Video ( Crazy Idea?)
Post by: Old Fossil on April 07, 2010, 07:12:38 PM
Will give it a go.

The new forum is going to be given a makeover soon.

www.mkaware.co.uk if ya wanna have a nosy peek.

Title: Re: Random Youtube Video ( Crazy Idea?)
Post by: Old Fossil on April 08, 2010, 08:15:54 AM
Sorry bud but I tried it on the test forum with no luck.
Title: Re: Random Youtube Video ( Crazy Idea?)
Post by: AngelinaBelle on April 09, 2010, 09:16:10 PM
Since you are using Aeva Media, why not use the Aeva Media SSI?
 
Here's a block I use for random images from a single album.
I have not tested it for videos.
 
You may want to change the div CSS class for videos.
 
Suppose you've put the vids in album 19
 
Code: [Select]
global $sourcedir;
include_once($sourcedir . '/Subs-RHSC.php');
rhsc_album(19,,1);
Code: (subs-RHSC) [Select]
<?php
if (!defined('SMF'))
 die(
'Hacking Attempt...');

function 
rhsc_album ($album=0$order='random'$start=0$count=5)
{
 global 
$sourcedir;
 
loadLanguage('Aeva');
 @include_once(
$sourcedir '/Aeva-Subs.php');
 if ( 
is_int($album) && !($album==0) ) 
 {
  
$aeva_albums = array($album);
  
$aeva_all_albums true;
 }
 else
 {
  
$aeva_all_albums=TRUE;
  
$aeva_albums = array();
 }

 
 if ( 
$order === 'random' )
  
$aeva_order 'RAND()';
 else
  
$aeva_order 'DESC';
 echo 
preg_replace('~<div class="highslide-maincontent">.*?</div>.*?</div>~'''
         
aeva_listItems(aeva_getMediaItems($start$count$aeva_order$aeva_all_albums$aeva_albums ), false''5)
 )
 ;
 return 
false;
}
?>


 
Title: Re: Random Youtube Video ( Crazy Idea?)
Post by: Old Fossil on April 09, 2010, 09:20:43 PM
Hiya

Would ya mind if I have a nosy at the one on ya forum?

Have a look at www.mkaware.co.uk

The forum will be having a major refit soon.

We have strted a major poster campaign asking local libraries and shops if they are willing to display one.
Title: Re: Random Youtube Video ( Crazy Idea?)
Post by: AngelinaBelle on April 09, 2010, 09:24:34 PM
You are welcome to view
http://rockhallsailingclub.org (http://rockhallsailingclub.org)
 
You can see pretty much everything as a guest.
 
 
 
Title: Re: Random Youtube Video ( Crazy Idea?)
Post by: Old Fossil on April 09, 2010, 09:41:52 PM
Didn't realise ordinary documents could be added to the media.

I have only recently started adding video clips.

 :-[
Title: Re: Random Youtube Video ( Crazy Idea?)
Post by: AngelinaBelle on April 11, 2010, 12:49:39 AM
It's a sort-of CMS-like way to organize documents.
Much better than losing them in attachments.
 
Did the random-video-album-item thing work out?
 
Title: Re: Random Youtube Video ( Crazy Idea?)
Post by: masterpaulocoolo on January 04, 2011, 08:29:47 AM
Yah it works great, but maybe you didn't want youtube videos to be displayed randomly how about online games?
Title: Re: Random Youtube Video ( Crazy Idea?)
Post by: AngelinaBelle on January 04, 2011, 10:11:03 AM
Then you would start with a block for online games.
Figure out how games are displayed in a block.
 
Figure out how to create an array that is a list of the games, then (here's the easy part) choose one randomly from the array.
 
Then, display the chosen game as usual.
 
You could start a new topic for this in customizations.
SimplePortal 2.3.8 © 2008-2024, SimplePortal