SecondLife Vodpod Player

From Second Life Wiki
Revision as of 13:13, 23 January 2009 by Devin Linden (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Introduction

The Second Life Showcase Vodpod Player is a video tutorial application that uses the jQuery JavaScript Library to retrieve and process XML feeds from the Vodpod API service. The original codebase was written by Devin Linden and Makai Linden in July 2008.

Why did we write it?

  • We had a need to aggregate videos hosted on various platforms from around the web.
  • Our preferred javascript framework is jQuery. At the time there were no vodpod players written using jQuery.
  • We needed the ability to customize the look and feel, output, and user experience for the Second Life community.
  • We wanted a "Video CMS" that provided us the ability to manage our videos via tags, categories, and searches.

Why did we use Vodpod?

Vodpod is an advanced video aggregator, bringing together videos from around the web into a unified place. We could easily pull in thumbnails, tag our videos using tags, and build search tools to streamline our video display capabilities. In addition, the people at vodpod are very responsive, agile, and open to working with their customers to improve the offering and experience overall.

In addition, the Vodpod API provided us with out-of-the box functionality that would have been time-consuming to build ourselves, such as:

  • Tagging facilities
  • Multi-site video consolidation
  • Streamlined web-based administration panels

Workflow

The Showcase Vodpod API performs the following tasks:

  1. Loads a list of videos by building an ajax query using default parameters (currently all videos, date-descending, 50 video links/pg) and loads the most recent video into the player.
  2. Accept from the user a term from either a search query input, a selection from a list of predefined terms, or tag link related to the active video.
  3. Dynamically create an ajax query to the Vodpod service, including the Second Life API key and a set of parameters (query term(s), number of listings per page, sort behavior, etc.).
  4. Parse the returned XML, creating an array object and storing returned items in the array for manipulation.
  5. Create the list of links to videos returned by the query.
  6. Clicking on any video link/thumbnail will load that video into the video player.

Technical Specifications

Languages and Frameworks

The Second Life Vodpod Player was written in JavaScript using the jQuery framework. It leverages Ajax calls to the Vodpod API and digests JSON responses.

Query Construction

The Showcase tutorials utilize two of the basic Vodpod services:

/pod/videos - Used for querying the videos and associated metadata.  
/pod/search - Used for querying specific videos based on search parameters.

As you can see on the Vodpod API Service List, there are many others to choose from.

The Second Life Showcase first builds up the service call and then processes an Ajax request using the jQuery Ajax Utilities:

//Create your url string, containing the parameters you need for a successful request
var url = http://api.vodpod.com/api/pod/videos.js?api_key=yourkey&pod_id=yourpid&page=1&per_page=25&sort=date-desc&query=term;

// Send the Ajax query to vodpod. 
// callback=? lets jQuery handle the cross-domain JSON response.
$.ajax({
url: url + "&callback=?",
	type: 'GET',
	dataType: 'json',
	timeout: 10000,     // 10 seconds
	error: function (XMLHttpRequest, textStatus, errorThrown) {
	// create an error message
// ex: $('#errormsg’).html('<span class="error">0 matching results</span>');
	return false;
		},
	success: function(xml) {
		// function to parse the returned xml object
		$.fn.vodpodGallery.createVideos(xml);
		}
});