jQuery YouTube player with playlist

Version: 1.0
License: CodeCanyon regular license
Price: $5
Compatible with: IE10, Firefox, Safari, Opera, Chrome

jQuery plugin that allows quick embedding of YouTube videos in any page. It is touch enabled and supports YouTube’s HTML5 player. Has fallback capability from Flash player to HTML5 player in case the first isn’t available. Compatible with all modern browsers and iPhone/iPad.

Features

  • Touch enabled;
  • Can create playlist from single YouTube video, user playlist, YouTube playlist or search queries;
  • Autoplay and loop videos;
  • Multiple players into the same page;
  • Displays player status (playing, paused, etc.);
  • Fallback to HTML5 player in case Flash isn’t available;
  • Compatible with iPhone/iPad;
  • All CSS is external;
  • Autoplay – can play all videos in playlist without user interaction.

Requirements

The plugin is fully compatible with WordPress, can be implemented using JavaScript files (jQuery, jQuery UI Slider and Touch Punch) provided by WordPress.

Usage

Place the script files and stylesheet into the head section of your page:

<!DOCTYPE html>
<html lang="en-US">
<head>
<script language="javascript" type="text/javascript" src="jquery.js"></script>
<script language="javascript" type="text/javascript" src="jquery-ui-1.10.1.slider.min.js"></script>
<script language="javascript" type="text/javascript" src="jquery.ui.touch-punch.js"></script>
<script language="javascript" type="text/javascript" src="swfobject.js"></script>
<script language="javascript" type="text/javascript" src="YTV-1.0.jquery.js"></script>
</head>
<!-- rest of page goes below -->

Next thing to do is start the script:

;(function($){
	$(document).ready(function(){
		var playerSettings = {
			videoContainer: '.YTV_playback',
			playlist: {
				selector : '.YTV_playlist',
				scrollbar : '.playlist_container .scrollbar'
			},	
			playerConfig: {
				showRelated: 0,
				showSearch: 0,
				showInfo: 1
			},		
			items			: '.YTV_playlist li a',
			clickStart		: true,
			volume			: 80,
			infoPanel		: '.movie_state',
			togglePlaylist		: '.show_playlist',
			toggleRepeat		: '.playlist_repeat',
			repeatPlaylist		: true,
			playOnLoad 		: false
		};
		// start the video player
		$('.YTV_movies').YTV( playerSettings );			
	})
})(jQuery);	

Plugin Parameters

PropertyDefaultValuesDescription
itemsnull-Playlist items selector (single videos or playlists).
playerConfigObject-Object that has 3 keys: showRelated, showSearch and showInfo. By default, all are set to false. These 3 settings control related videos display, search form and video info when player finishes playling the current video.
videoContainernull-CSS selector of video player container. YouTube’s player will be injected inside this element and will have the size it has.
playlistObject-Object having 2 keys: selector and scrollbar. Key selector contains the CSS selector for the playlist and scrollbar key contains the CSS selector where the playlist scrollbar will be injected.
infoPanelnull-CSS selector for element that will display the player status (ie: playing, paused and so on).
togglePlaylistnull-CSS selector for link that toggles the playlist in/out of view.
toggleRepeatnull,-CSS selector for link that toggles playlist repeat on/off.
clickStarttruetrue/falseWhen video is clicked in playlist it can automatically play or load paused. This option controls this behavior.
volume30-For videos that don’t have volume parameter set individually, the volume will have the value set in this parameter.
repeatPlaylistfalsetrue/falseWill automatically play the next video when current one ends. In case current video has repeat set ON in individual settings this setting will be overrun and current video will play again.
playOnLoadfalsetrue/falseWhen set to true, on page load the video set as selected will start playing automatically.
rewindVideofalsetrue/falseWhen current video ends it will rewind to beginning.
forceHTML5Playerfalsetrue/falseBy default the plugin will try to first load Flash player and if unavailable, it will load HTML5 player. This can be overrun by setting this parameter true; this will load by default the HTML5 player without testing if Flash is available or not.

Playlist items parameters

Each item in playlist has a set of parameters that are set as a JSON string on anchor rel attribute. There are 4 types of elements: single videos, YouTube playlists, YouTube user playlists and search queries. Below are examples for each type:

1. Individual videos

<a href="#" title="" rel="{'vidId' : 'youtubeVideoId'}">My video</a>
PropertyTypeDescription
vidIdstringYouTube video ID.
selectedintVideo will be loaded on page load ( 1 ).
repeatintAfter video ends, it will start again ( 1 ) or stop ( 0 ).
volumeintVideo volume ( 0-100 ).
pausedintVideo will be loaded paused ( 1 ) or will play automatically ( 0 ).

2. YouTube user playlist

<a href="#" title="" rel="{'userId' : 'youtubeUserId'}">My user playlist</a>
PropertyTypeDescription
userIdstringYouTube user ID to pull videos from.
resultsintNumber of videos to be retrieved ( no more than 50 – YouTube limitation ).
loadIfNextintWhen repeatPlaylist is on, if the next item in list is playlist and loadIfNext equals to 1, the playlist will be loaded and videos in it played.
autoloadintOn page load query for the playlist and populate with the results ( 1 ).

3. YouTube playlist

<a href="#" title="" rel="{'playlistId' : 'youtubePlaylistId'}">My playlist</a>
PropertyTypeDescription
playlistIdstringYouTube playlist ID to pull videos from.
resultsintNumber of videos to be retrieved ( no more than 50 – YouTube limitation ).
loadIfNextintWhen repeatPlaylist is on, if the next item in list is playlist and loadIfNext equals to 1, the playlist will be loaded and videos in it played.
autoloadintOn page load query for the playlist and populate with the results ( 1 ).

4. YouTube query

<a href="#" title="" rel="{'query' : 'some query'}">My query</a>
PropertyTypeDescription
querystringQuery to pull YouTube videos for.
resultsintNumber of videos to be retrieved ( no more than 50 – YouTube limitation ).
loadIfNextintWhen repeatPlaylist is on, if the next item in list is playlist and loadIfNext equals to 1, the playlist will be loaded and videos in it played.
autoloadintOn page load query for the playlist and populate with the results ( 1 ).

Changelog

  • 1.0

    - Initial release