Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

Random Youtube Video Player

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 09-17-2010, 01:13 PM
 
minfinger minfinger is offline
 

X-Adept
  
Join Date: Apr 2009
Posts: 678
 

Default Random Youtube Video Player

My client has several Youtube Videos that we'd like to display in the left menu bar and have to randomly chosen on each refresh or load of any page.

I tried the AJAX Banner Script, but that just displays one every so many seconds. It's switching before the videos stop.

Is this possible?
__________________
X-Cart 4.3
Joomla
Among other things
Reply With Quote
  #2  
Old 09-17-2010, 03:17 PM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,201
 

Default Re: Random Youtube Video Player

Can't advise on that but I would suggest not to start the video on page load. Have the plugin there but let the customer to decide if they want to play it or not. If I get to a site which automatically plays video or music or some sort of animation that moves over the screen it makes me leave that site immediately and not come back.
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote
  #3  
Old 09-17-2010, 03:20 PM
 
minfinger minfinger is offline
 

X-Adept
  
Join Date: Apr 2009
Posts: 678
 

Default Re: Random Youtube Video Player

Steve,

Thanks for the comment. I had no intention of starting the video on load.

www.littlepuppiesonline.com

The videos show on the right hand side. Like I said using the AJAX just swaps out the Embedded code from YouTube. It's not randomizing the videos.

I did read a small tutorial about making an SQL Database to accomplish the randomization of the videos, but I think there should be an easier way.
__________________
X-Cart 4.3
Joomla
Among other things
Reply With Quote
  #4  
Old 09-17-2010, 03:23 PM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,201
 

Default Re: Random Youtube Video Player

Quote:
Originally Posted by minfinger
Steve,

Thanks for the comment. I had no intention of starting the video on load.
I see it. Yes, like this is acceptable
Sorry can't help you with the random load
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote
  #5  
Old 09-18-2010, 05:11 PM
 
Regs Regs is offline
 

Senior Member
  
Join Date: Apr 2003
Location: Vancouver BC
Posts: 134
 

Default Re: Random Youtube Video Player

Not sure how to use smarty plugins but perhaps with some further googling, you'll be able to find out and use the following:\

http://roblogic.net/tech/articles/4

Cheers,

Regs.
__________________
x-cart 4.2.3 & 4.6.0
Reply With Quote
  #6  
Old 09-21-2010, 12:17 PM
 
minfinger minfinger is offline
 

X-Adept
  
Join Date: Apr 2009
Posts: 678
 

Default Re: Random Youtube Video Player

I did find this, but it appears to be ASP based using an SQL DB. Any thoughts?

http://www.codeproject.com/KB/aspnet/PlayYouTubeVideo.aspx
__________________
X-Cart 4.3
Joomla
Among other things
Reply With Quote
  #7  
Old 09-21-2010, 12:18 PM
 
minfinger minfinger is offline
 

X-Adept
  
Join Date: Apr 2009
Posts: 678
 

Default Re: Random Youtube Video Player

Quote:
Originally Posted by Regs
Not sure how to use smarty plugins but perhaps with some further googling, you'll be able to find out and use the following:\

http://roblogic.net/tech/articles/4

Cheers,

Regs.

Regs I had a php one before, I'm not so sure it works. Does PHP run inside x-cart as a TPL?
__________________
X-Cart 4.3
Joomla
Among other things
Reply With Quote
  #8  
Old 09-22-2010, 06:53 AM
 
minfinger minfinger is offline
 

X-Adept
  
Join Date: Apr 2009
Posts: 678
 

Default Re: Random Youtube Video Player

Regs, I found this one as well.

http://www.jakeludington.com/youtube/20070615_how_to_randomize_youtube_videos_with_php. html

I got the flash portion to show on the site, but the PHP isn't pulling in the tag on the Video to make it display.
__________________
X-Cart 4.3
Joomla
Among other things
Reply With Quote
  #9  
Old 09-22-2010, 07:37 AM
 
Regs Regs is offline
 

Senior Member
  
Join Date: Apr 2003
Location: Vancouver BC
Posts: 134
 

Default Re: Random Youtube Video Player

Can you post the relevant portion of the template you are putting the php code in?

As long as your path to the text file is correct and you wrap the php code in {php}{/php} tags in your template, it should work (as my limited understanding allows me to say )

Once you get that working though, looking into using native smarty language code would be ideal - there should be code to set an array and to pull a random line from it.

Cheers,

Regs.
__________________
x-cart 4.2.3 & 4.6.0
Reply With Quote
  #10  
Old 09-22-2010, 11:48 AM
 
minfinger minfinger is offline
 

X-Adept
  
Join Date: Apr 2009
Posts: 678
 

Default Re: Random Youtube Video Player

Regs,

This guy in another thread talking about PHP in X-Cart figured it out along the lines of what you were saying.

Quote:
Originally Posted by geckoday
Two ways. The easiest is to just do this in the template like this:
Code:
{assign var=video_array value='/home/minfinge/public_html/littlepuppiesonline.com/skin1/customer/main/YourVideoList.txt'|file} {assign var=video_rand value=$video_array|@array_rand} <object width="200" height="137"><param name="movie" value="http://www.youtube.com/v/{$video_array.$video_rand|trim}"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/{$video_array.$video_rand|trim}" type="application/x-shockwave-flash" wmode="transparent" width="200" height="137"></embed></object>

That still puts code into the template and you'd end up duplicating it everywhere if you use it in multiple places. I prefer to use Smarty plugins for this kind of stuff like this:

PHP Code:
<?php
if (!defined('XCART_START')) { header("Location: ../../../"); die("Access denied"); }
## -----------------------------------------------------------------------------
## Smarty plugin "random_video"
## Purpose: Retrieve random vidoe name for display
##
##
## -----------------------------------------------------------------------------
##
## Changelog:
##
## 2010-09-22 Created
##
##
## -----------------------------------------------------------------------------
##
## Preparations
## ------------
## Uses the following file:
##   skin1/customer/main/YourVideoList.txt - list of videos, one per line
## 
##
## Sample usage
## ------------
## {random_video result="video_rand"}
## <object width="200" height="137"><param name="movie"  value="http://www.youtube.com/v/{$video_rand}"></param><param  name="wmode" value="transparent"></param><embed  src="http://www.youtube.com/v/{$video_rand}"  type="application/x-shockwave-flash" wmode="transparent" width="200"  height="137"></embed></object>
## 
##
## Parameters
## ----------
##
## result [string] (required)
##      Smarty variable to return result string in.  Result is a random line form the video file
##      trimmed and ready for substitution into HTML.
## 
## 
## -----------------------------------------------------------------------------

function smarty_function_random_video($params, &$smarty) {

  
$required_params = array('result');

  foreach(
$required_params as $_key => $reqd_param) {
    if (!isset(
$params[$reqd_param]))
      
$smarty->trigger_error("random_video: required attribute '$reqd_param' not passed"E_USER_ERROR);
  }

  
$result    '';
  foreach(
$params as $_key => $_val) {
    switch(
$_key) {
      case 
'result':
          if (!
is_array($_val)) {
              if (
$_val <> '')
                $
$_key $_val;
              else
                
$smarty->trigger_error("random_video: '$_key' cannot be an empty string"E_USER_ERROR);
          } else
              
$smarty->trigger_error("random_video: '$_key' cannot be an array"E_USER_ERROR);
          break;

      default:
          
$smarty->trigger_error("random_video: attribute '$_key' not recognized"E_USER_NOTICE);
          break;
    }
  }

  
$video_file $smarty->template_dir.DIRECTORY_SEPARATOR."customer/main/YourVideoList.txt";
  
  if (!
is_file($video_file))
      
$smarty->trigger_error("random_video: video list file '$video_file' is missing"E_USER_NOTICE);
      
  
$video_array file($video_file);
  if (
count($video_array) < 1)
      
$smarty->trigger_error("random_video: video list file '$video_file' is empty"E_USER_NOTICE);
      
  
$smarty->assign($resulttrim($video_array[array_rand($video_array)]));

}
Save this in include/templater/plugins/function.random_video.php and use it like the code comments show. I would probably add a parameter to select the video file to it so it can be used in multiple places for different lists of videos but I'll leave that as an exercise for the reader.
__________________
X-Cart 4.3
Joomla
Among other things
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 10:39 AM.

   

 
X-Cart forums © 2001-2020