Youtube videos
Does anyone have an example of the youtube api being used in titanium mobile? I am parsing the xml response using the kitchen sink "xml rss" example as a template and I keep getting flash only movie responses from youtube. How do I get a response with an iphone playable youtube link.
Below is the xhr url I am using
var xhr = Ti.Network.createHTTPClient();
xhr.open("Get","http://gdata.youtube.com/feeds/api/videos?q=test&format=6&orderby=published&start-index=11&max-results=10&v=2");
xhr.onload = function()
3 Answers
-
Accepted Answer
When you get the alphanumeric 'watch' id of a youtube videi, simply use that the create the standard flash(!) embed code in a webview.
even though it's flash code, the iphone already knows what to do with it and will show you a thumbnail with a play button over it - which when clicked will open the video on the builtin youtube player.
There are other youtube apis you can use if you want to obtain the mp4 url to a youtube video - if one exists.
-
Here is an example of adding the embed code to a webview from a parsed XML feed in case it might help someone out. You could then add the webview to a table or scroll view to create a video gallery of sorts.
var htmlheader = "<html><head></head><body style='margin:0'><embed id='yt' src='"; var htmlfooter = "' type='application/x-shockwave-flash' width='120' height='90'></embed></body></html>"; var htmlmash = htmlheader + videoUrl + htmlfooter; //The videoUrl is parsed from the media:content tag in the YouTube XML feed var webview = Ti.UI.createWebView({ html: htmlmash, height: 90, width: 120, top: 5, bottom: 5, left: 5 });
-
This may help somebody else:
you can download the following plugin for firefox and the get the mp4 url from there and use that for url in Titanium.Media.createVideoPlayerfirefox plugin:
https://addons.mozilla.org/en-US/firefox/addon/download-youtube/demo:
var youtubeURL= "http://o-o.preferred.dub06s01.v2.lscache5.c.youtube.com/videoplayback?sparams=id%2Cexpire%2Cip%2Cipbits%2Citag%2Csource%2Cratebypass%2Ccp&fexp=910601%2C900810&itag=18&ip=217.0.0.0&signature=9EE86B79F89D239F65C083433C8D24F1BA3C1EFC.74C3113E0543748A6CD6C393459206CD082B914E&sver=3&ratebypass=yes&source=youtube&expire=1318024800&key=yt1&ipbits=8&cp=U0hQTVBNUl9FSkNOMF9IR1ZJOjJxREw5TVZEMGVv&id=bc124b31292e50d2&title=New%20Irish%20Cadbury%20Dairy%20Milk%20advert"; var activeMovie = Titanium.Media.createVideoPlayer({ url: youtubeURL, autoplay:true });