Ads

Showing posts with label YouTube. Show all posts
Showing posts with label YouTube. Show all posts

Wednesday, August 7, 2013

Android YouTube Player

Android module that plays videos from YouTube.

This module create an Android activity that allows developers to play videos that are hosted on YouTube. This module is based on Android YouTube player library.

The original code was created by KeyesLabs (www.keyeslabs.com) as part of the Screebl project. The developers wanted the ability to play YouTube-hosted help videos, and wanted those videos to be able to play on any device, even those that didn't have the stock YouTube player app.

Android YouTube Player
NOTE: If module unable to get the RTSP url from YouTube server, then video cannot be played.

Features:
  • Higher Bandwidth Video
    This module plays higher bandwidth video from YouTube server as new Activity.
  • Auto Play
    Without user interaction, video will will play automatically in landscape mode once it is loaded from YouTube server.
  • Video Player Controls
    YouTube video player comes with default controls like play, pause, SeekForward, SeekBackward.
  • Play by Video Id and Playlist Id
    playVideo method takes video id as input parameter and plays video automatcally.
    playPlayListVideo
    method takes playlist id as input parameter then it will play the latest video added to a YouTube playlist.
Usage:
var win = Ti.UI.createWindow({
 backgroundColor : "#fff",
 layout : "vertical"
});

var youtubePlayer = require('titutorial.youtubeplayer');
Ti.API.info("module is => " + youtubePlayer);

/*
 * Play video by videoId
 */
var playVideo = Ti.UI.createButton({
 title : 'Play video',
 height : '40dp',
 width : Ti.UI.SIZE,
 top : '100dp'
});
win.add(playVideo);

playVideo.addEventListener('click', function() {
 youtubePlayer.playVideo("FjMs_imWkFM");
});

/*
 * Play video by playListId
 */
var playPlayListVideo = Ti.UI.createButton({
 title : 'Play playlist video',
 height : '40dp',
 width : Ti.UI.SIZE,
 top : '100dp'
});

playPlayListVideo.addEventListener('click', function() {
 youtubePlayer.playPlayListVideo("PLB03EA9545DD188C3");
});

win.add(playPlayListVideo);

win.open();
Download:
Module: https://marketplace.appcelerator.com/apps/6223?942520925
Source code: https://github.com/railskarthi/YoutubePlayer-Android

Screenshot:
Android YouTube Player
Android YouTube Player
 

Wednesday, August 1, 2012

YouTube Playlist in Titanium

In this post I am going to discuss about how to fetch YouTube playlist from a channel using Appcelerator Titanium.

YouTube offer API for category, search term, playlist, favorites, subscriptions... etc. Here you can found list of YouTube API
https://developers.google.com/youtube/getting_started

Below API will retrieve the user's playlists. This request does not require authentication
https://gdata.youtube.com/feeds/api/users/userId/playlists?v=2
* Here  userId represents YouTube username.

The above API response containing a playlists feed in XML format.
The response contains a series of <entry>  tags, with each entry describing a playlist.
Each entry contains the playlist's title, description, author and modification date as well as
a  <content> tag that specifies the URL for retrieving the list of videos in the playlist

Here I am  using Apple's YouTube username to fetch their YouTube playlist
var channelName = "apple";
var loader = Titanium.Network.createHTTPClient();
loader.open("GET", "http://gdata.youtube.com/feeds/api/users/"+channelName+"/playlists?v=2");

loader.onload = function() {
 var doc = this.responseXML.documentElement;
 var items = doc.getElementsByTagName("entry");
 for (var i = 0; i < items.length; i++) {
   var item = items.item(i);
   var playlist_title = item.getElementsByTagName("title").item(0).text;//playlist title
   var vid_count = item.getElementsByTagName("yt:countHint").item(0).text; //video count for this playlist
   var play_list_id = item.getElementsByTagName("yt:playlistId").item(0).text; //play_list_id
 }
};

loader.onerror = function(e) {
 alert("Error:"+e.error);
};

loader.timeout = 10000;
loader.send();

In below code I am going to retrieve all the videos in a particular playlist using playlist id.
http://gdata.youtube.com/feeds/api/playlists/playlist_id?v=2
var loader = Titanium.Network.createHTTPClient();
loader.open("GET", "http://gdata.youtube.com/feeds/api/playlists/" + playlist_id + "?v=2");

loader.onload = function() {
  var doc = this.responseXML.documentElement;
  var items = doc.getElementsByTagName("entry");
  for (var c = 0; c < items.length; c++) {
   var item = items.item(c);
   var thumbnails = item.getElementsByTagName("media:thumbnail");
   if (thumbnails && thumbnails.length > 0) {
     var media = thumbnails.item(0).getAttribute("url"); //thumbnail image
     var title = item.getElementsByTagName("title").item(0).text; //video title
     var videoId = item.getElementsByTagName("yt:videoid").item(0).text; //video id
   }
  }
};

loader.onerror = function(e) {
 alert("Error:" + e.error);
};

loader.timeout = 5000;
loader.send(); 

YouTube Playlist in Titanium
Playlist listing for Apple

YouTube Playlist in Titanium
Video List for Particular Playlist
Here you can download the complete working project from my Github Titanium YouTube Playlist

CodeStrong