Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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.onload = function()
— asked March 30th 2010 by Christian Sullivan
  • api
  • iphone
  • mobile
  • youtube

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.

    — answered March 30th 2010 by Kosso
  • 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
    — answered November 2nd 2011 by Peter Wiley
    • Hi Peter, thanks for your snippet! I were struggling with this for a couple of weeks, trying many different html snippets in a webview – none working… Until now.
      Others: please note, that implementing it this way will lead to an empty webview in the iPhone Simulator! If you run it on your device, it will show the youtube embed nicely…

      — commented November 8th 2011 by Christoffer T. Timm
    • I forgot to add: it's important here to really use type=&#39;application&#x2F;x-shockwave-flash&#39;! Using type=&#39;video&#x2F;mp4&#39; will bring up the striked-through play button YouTube uses to indicate that the video is not available in this format.

      — commented November 8th 2011 by Christoffer T. Timm
    • Awesome, I was trying to do that for ages!

      — commented November 17th 2011 by Dhaya Benmessaoud
    • @Christoffer T. Timm: it shows the video on iOS simulator but on iPhone a blank page :'(, on galaxy s4 also :'(

      — commented October 1st 2015 by Abdessamed MANSOURI
  • 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.createVideoPlayer

    firefox plugin:


    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=";
    var activeMovie = Titanium.Media.createVideoPlayer({
        url: youtubeURL, 
    — answered October 7th 2011 by Andres Arguello Pitt
    1 Comment
    • doesn't work for me … :( shows a blank screen

      — commented June 25th 2012 by George Georgiou
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.