Titanium Community Questions & Answer Archive

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

Playing YouTube using Titanium.Media.VideoPlayer

Is it possible to play a YouTube video using Titanium.Media.VideoPlayer? Currently I am using Titanium.UI.WebView to play the video.

The reason why I want to use Titanium.Media.VideoPlayer is because:

1) I don't want user to have to click on the play to start the video. I want the video to start automatically when the window gets focus.

2) Once the video is complete or the user clicks the "Done" button, I want the view and window to be closed without user having to click the back button.

— asked October 15th 2010 by Mansoor Charaniya
  • media
  • player
  • video
  • youtube
2 Comments
  • hey Mansoor,

    Did you ever find the answer to your problem? I am trying to achieve the same - play youtube video on Titanium.Media.VideoPlayer, knowing the youtube ID.

    Can you please tell me how you made it work? You can message me at skolluri at gmail.

    Thanks,
    Sri

    — commented October 25th 2011 by Sridevi Kolluri
  • you can't do this anymore

    — commented August 7th 2015 by Andrew Gallasch

12 Answers

  • I finally did it!
    Everything you need is here
    and it gives this

    function h264videosWithYoutubeURL(_youtubeId, _callbackOk, _callbackError)
    {
            var youtubeInfoUrl = 'http://www.youtube.com/get_video_info?video_id=' + _youtubeId;
            var request = Titanium.Network.createHTTPClient({ timeout : 10000  /* in milliseconds */});
            request.open("GET", youtubeInfoUrl);
            request.onerror = function(_event){
                if (_callbackError)
                    _callbackError({status: this.status, error:_event.error});
            };  
            request.onload = function(_event){
                var qualities = {};
                var response = this.responseText;
                var args = getURLArgs(response);
                if (!args.hasOwnProperty('url_encoded_fmt_stream_map'))
                {
                    if (_callbackError)
                        _callbackError();
                }
                else
                {
                    var fmtstring = args['url_encoded_fmt_stream_map'];
                    var fmtarray = fmtstring.split(',');
                    for(var i=0,j=fmtarray.length; i<j; i++){
                        var args2 = getURLArgs(fmtarray[i]);
                        var type = decodeURIComponent(args2['type']);
                        if (type.indexOf('mp4') >= 0)
                        {
                            var url = decodeURIComponent(args2['url']);
                            var quality = decodeURIComponent(args2['quality']);
                            qualities[quality] = url;
    
                        }
    
                    }
                    if (_callbackOk)
                        _callbackOk(qualities);
                    }
            }
            request.send();
    
    
    }
    
    — answered July 22nd 2012 by Martin Guillon
    permalink
    10 Comments
    • Hi, great job, i'd like to use this code. Can you post all support functions (getURLArgs, etc) which you use in this sample? thanks

      — commented July 23rd 2012 by M. M.
    • oups! sorry i thought i posted everything

      function getURLArgs(_string) {
          var args = {};
          var pairs = _string.split("&");
          for(var i = 0; i < pairs.length; i++) {
              var pos = pairs[i].indexOf('=');
              if (pos == -1) continue;
              var argname = pairs[i].substring(0,pos);
              var value = pairs[i].substring(pos+1);
              args[argname] = unescape(value);
          }
          return args;
      }
      

      — commented July 23rd 2012 by Martin Guillon
    • This solution worked perfectly for me. Thank you very much.

      You just need to define a _callbackOk function that works with the URL you want.

      The array seems to have qualities["small"] and qualities["medium"] available for most of the YouTube videos I tried.

      You just pass this element of the array into the URL parameter when initializing`Titanium.Media.VideoPlayer

      — commented July 27th 2012 by John Hawkins
    • that s it John.
      By the way qualities are 'small', 'medium', '720p' and '1080p'

      — commented July 27th 2012 by Martin Guillon
    • It´s returning a error for me.
      {error:Forbidden, status:403}
      Does anyone know what it is?

      — commented September 24th 2012 by Douglas Alves
    • @John and @ Martin : Hey, Can you give me post all required function which use in this function..
      Thanks

      — commented November 27th 2012 by Jigar Maheshwari
    • Sadly my method doesnt seem to work anymore.
      You should try the version of Kenan
      https://gist.github.com/3151702

      — commented November 27th 2012 by Martin Guillon
    • Thanks Martin..
      Jigar

      — commented November 27th 2012 by Jigar Maheshwari
    • Thanks that works. But how to know if the video player is compatible with hd video or not. Since i am getting the 'medium' quality url of some of best quality videos (for eq: https://www.youtube.com/watch?v=xKdClsVM2TU)in youtube. But it is not playing at the same time hd720 url is working

      — commented August 14th 2014 by Praveen KP
    • doesn't work on iOS

      — commented August 6th 2015 by Andrew Gallasch
  • See https://gist.github.com/3151702 for my quite short workaround. Native player by extracting the mp4.

    — answered September 28th 2012 by Kenan Sulayman
    permalink
    13 Comments
    • This right here is what you need. Works perfectly! Thanks Kenan.

      — commented December 26th 2012 by Ross Waycaster
    • wow, it works again! thanks again for that.
      Here is my update code (i simplified your code a bit)

      function h264videosWithYoutubeURL(_youtubeId, _callbackOk, _callbackError) //http://www.youtube.com/watch?v=8To-6VIJZRE
      {
          var request = Titanium.Network.createHTTPClient({
              timeout : 10000 /* in milliseconds */
          });
          request.setRequestHeader("Referer", "http://www.youtube.com/watch?v=" + _youtubeId);
          request.open("GET", "http://m.youtube.com/watch?ajax=1&feature=related&layout=mobile&tsp=1&&v=" + _youtubeId);
          request.onerror = function(_event) {
              processRequestError(_event, "Can't get youtube video", _callbackError);
          };
          request.onload = function(_event) {
              var qualities = {};
              try {
                  var fmtarray = JSON.parse(decodeURIComponent(this.responseText.substring(4, this.responseText.length))).content.video['fmt_stream_map'];
                  ;
                  for (var i = 0, j = fmtarray.length; i < j; i++) {
                      var data = fmtarray[i];
                      var type = decodeURIComponent(data['type']);
                      if (type.indexOf('mp4') >= 0) {
                          var url = decodeURIComponent(data['url']);
                          var quality = decodeURIComponent(data['quality']);
                          qualities[quality] = url;
                      }
                  }
                  if (_callbackOk)
                      _callbackOk(qualities);
              } catch(e) {
                  if (_callbackError)
                      _callbackError();
              }
          }
          request.send(); 
      }
      

      — commented December 26th 2012 by Martin Guillon
    • there are three links in the qualities vaiables finally small , medium and hd720 but none of these links is working Titanum.Media.Videoplayer im trying that in android need help

      — commented December 31st 2012 by Mubashir khan
    • personnaly i didnt get the hd720 yet :s I was afraid i couldnt get it.
      Now for the playing part, it works really well here using

      Titanium.Media.createVideoPlayer({
              url:_args.url,
              autoplay : true,
              backgroundColor: '#000',
              fullscreen:true,
              scalingMode: Titanium.Media.VIDEO_SCALING_ASPECT_FIT,
              mediaControlMode: Titanium.Media.VIDEO_CONTROL_NONE
          });
      

      — commented December 31st 2012 by Martin Guillon
    • Will this code work as is for retrieving and playing videos from a youtube channel e.g. http://www.youtube.com/rss/user/DejAyEnterprise/videos.rss? If so, is this url now same as the youtubeID and what defines the other two params in the funciton call (callback ). If not, how can I adapt the code to do just that? Thx

      — commented January 17th 2013 by adebisi oladipupo
    • @adebisi: did you try? We are not here to implement things for you!

      — commented January 18th 2013 by Martin Guillon
    • @Martin Thanks ! Very helpful, quickly implemented it in a app ! I've got to look into caching the video file now. Thanks again!

      — commented January 22nd 2013 by Florent Lamoureux
    • Hi Kenan Sulayman, your code is fantastic and It works on iOS but when tried to run on android it just dont work… video player does not opens up.. any clue?

      — commented April 18th 2013 by Ajeet pratap Maurya
    • Doesn't work on Android, please see my solution.

      — commented May 21st 2013 by Justin Toth
    • Why not? All I see in your code is a reincarnation of my code. He asked for 3GPP, he got it. I don't work with Android, though.

      — commented May 21st 2013 by Kenan Sulayman
    • (sorry, misunderstanding; all good) :o)

      — commented May 21st 2013 by Kenan Sulayman
    • THANKS!

      — commented May 28th 2013 by Joseph Sachs
    • Thanks that works.
      But how to know if the video player is compatible with hd video or not. Since i am getting the 'medium' quality url of some of best quality videos (for eq: https://www.youtube.com/watch?v=xKdClsVM2TU)in youtube. But it is not playing at the same time hd720 url is working

      — commented August 14th 2014 by Praveen KP
  • @Jonathan: My Gist still works; we experienced the same outage, but my workaround wraps around the interface, the mobile Youtube App uses. https://gist.github.com/3151702 — we're already deploying this code as workaround in our apps. (successfully). Youtube implemented several security enhancements on it's servers; so for now, I think, this workaround is the only way to get it working. Have a nice day!

    — answered October 12th 2012 by Kenan Sulayman
    permalink
    6 Comments
    • I agree that s the best way to go. I liked my solution because i could get different qualities but it doesnt seem to work anymore! Thanks for sharing your solution

      — commented October 12th 2012 by Martin Guillon
    • hmmm. whether it is stable: (?

      — commented October 13th 2012 by Jonathan Schneider
    • okay. thanks. it works. but the quali ist realy bad :( resolution?
      i need min. 720p

      — commented October 13th 2012 by Jonathan Schneider
    • The problem is Youtubes' new security system; I'll get a bit deeper into the Youtube thing and will get my findings to you. Currently it seems this workaround is a bit unstable: Youtube rarely - but it happens - seems to send different "layouts" of what we're trying to extract, making the automated way unusable. Wouldn't it be so rarely happening, it'd be easy to build a good algorithm, but that's the reason it's happening anyway, I think ;)

      — commented October 13th 2012 by Kenan Sulayman
    • I tried the one that Kenan has provided. Some how I dont get to see the fmt_stream_map under content.video. I have seen the stream_url which is having a 3gp video url but even that is not playing in android.

      Is there a solution that works on both IOS and Android that can be used in an titanium app?

      — commented May 17th 2013 by Sreekanth Kesari
    • Hey Sreekanth, I took a minute to checkout the current situation. First, you can't see fmt_stream_map unless you're sending a mobile useragent. Second, here's something I crafted in a matter of seconds: https://gist.github.com/KenanSulayman/5601881. It's not tested — tell me if it works for you.

      — commented May 17th 2013 by Kenan Sulayman
  • Here is a spin-off of Kenan's solution that works on both iOS and Android:

    var lib = Alloy.Globals;
    
    exports.play = function(id) {
        getVideo(id);
    };
    
    function getVideo(id) {
        var client = Ti.Network.createHTTPClient();
        client.onload = function () {
            var json = decodeURIComponent(decodeURIComponent(decodeURIComponent(decodeURIComponent(this.responseText.substring(4, this.responseText.length)))));
            var response = JSON.parse(json);
            var video = response.content.video;
            var streamUrl = video['fmt_stream_map'] ? video['fmt_stream_map'][0].url : video.stream_url;
            Ti.API.info("stream url: " + streamUrl);
            playVideo(streamUrl);
        };
        client.setRequestHeader('Referer', 'http://www.youtube.com/watch?v=' + id);
        client.setRequestHeader('User-Agent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/536.26.14 (KHTML, like Gecko) Version/6.0.1 Safari/536.26.14');
        client.open('GET', 'http://m.youtube.com/watch?ajax=1&feature=related&layout=mobile&tsp=1&&v=' + id);
        client.send();
    }
    
    function playVideo(url) {
        var win = Ti.UI.createWindow({
            title: 'Video Player',
            backButtonTitle: 'Videos',
            barColor: '#000',
            backgroundColor: '#000'
        });
        videoPlayer = Ti.Media.createVideoPlayer({
            backgroundColor: '#000',
            fullscreen: true,
            url: url,
            autoplay: true,
            scalingMode: Ti.Media.VIDEO_SCALING_ASPECT_FIT,
            mediaControlMode: Ti.Media.VIDEO_CONTROL_NONE
        });
        /*videoPlayer.addEventListener('complete', function(e) { 
            if (e.reason === 0) {
                Ti.API.info('complete exit');
                win.close();
            };
        });*/
        videoPlayer.addEventListener('fullscreen', function (e) {
            if (!e.entering) {
                Ti.API.info('fullscreen exit');
                win.close();
            }
        });
        if(!lib.constants.IS_ANDROID) {
            win.add(videoPlayer);
        }
        win.open();
    }
    
    — answered May 21st 2013 by Justin Toth
    permalink
    15 Comments
    • Here is an updated version that handles: (1.) High quality videos now shown on Android (2.) Handle Android back button exiting video player (3.) Auto-close video player after video completes.

      var lib = Alloy.Globals;
      
      var win = null,
          videoPlayer = null;
      
      exports.isPlaying = false;
      
      exports.play = function(id) {
          exports.isPlaying = true;
          getVideo(id);
      };
      
      function getVideo(id) {
          var client = Ti.Network.createHTTPClient();
          client.onload = function () {
              var json = decodeURIComponent(decodeURIComponent(decodeURIComponent(decodeURIComponent(this.responseText.substring(4, this.responseText.length)))));
              var response = JSON.parse(json);
              var video = response.content.video;
              var isHighQuality = video['fmt_stream_map'] != null;
              var streamUrl = isHighQuality ? video['fmt_stream_map'][0].url : video.stream_url;
              if(!isHighQuality) {
                  Ti.API.info('using low quality video because fmt_stream_map does not exist in json response, User-Agent probably is not being sent correctly');
              }
              Ti.API.info('stream url: ' + streamUrl);
              playVideo(streamUrl);
          };
          if(lib.constants.IS_IOS) {
              client.setRequestHeader('Referer', 'http://www.youtube.com/watch?v=' + id);
              client.setRequestHeader('User-Agent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/536.26.14 (KHTML, like Gecko) Version/6.0.1 Safari/536.26.14');
          }
          client.open('GET', 'http://m.youtube.com/watch?ajax=1&layout=mobile&tsp=1&utcoffset=330&v=' + id);
          if(lib.constants.IS_ANDROID) {
              client.setRequestHeader('Referer', 'http://www.youtube.com/watch?v=' + id);
              client.setRequestHeader('User-Agent', 'Mozilla/5.0 (Linux; U; Android 2.2.1; en-gb; GT-I9003 Build/FROYO) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1');
          }
          client.send();
      }
      
      function playVideo(url) {
          if(lib.constants.IS_IOS) {
              win = Ti.UI.createWindow({
                  title: 'View Training Video',
                  backgroundColor: '#000'
              });
          }
          videoPlayer = Ti.Media.createVideoPlayer({
              backgroundColor: '#000',
              url: url,
              fullscreen: true,
              autoplay: true,
              scalingMode: Ti.Media.VIDEO_SCALING_ASPECT_FIT,
              mediaControlMode: Ti.Media.VIDEO_CONTROL_DEFAULT   
          });
          videoPlayer.addEventListener('complete', function(e) { 
              Ti.API.info('video player complete');
              exports.close();
          });
          videoPlayer.addEventListener('fullscreen', function(e) {
              if (!e.entering) {
                  Ti.API.info('video player fullscreen exit');
                  exports.close();
              }
          });
          if(lib.constants.IS_IOS) {
              win.add(videoPlayer);
              win.open();
          }
      }
      
      exports.close = function() {
          Ti.API.info('closing video player');
          if(lib.constants.IS_IOS) {
              videoPlayer.fullscreen = false;
              win.close();
          }
          else {
              videoPlayer.hide();
              videoPlayer.release();
              videoPlayer = null;
          }
          exports.isPlaying = false;
      };
      

      — commented May 22nd 2013 by Justin Toth
    • Very nice ! Thank you. I've only a problem: when I rotate the mobile (android), the video player stops and exits. Have you met this problem?

      — commented May 28th 2013 by Kevin Purnelle
    • No I'm not seeing that issue on my S3. Can you try a few more devices to see if it's a device-specific issue? Also, you have the orientation opts set correctly for the window as well as the Android activity?

      — commented May 28th 2013 by Justin Toth
    • The window is only needed for iOS, in android there is no window so I can't fix the orientation.

      In my device (HTC Sensation) I've seen that the 'complete' event is fired when I rotate the device. So if I remove the 'exports.close()' line in the callback, what it does is reload the video at the beginning.

      Now maybe the activity as you said, is the problem. But I don't know what's the name of the videoplayer own activity and what I should put in the manifest.. Maybe a landscape constraint?

      — commented May 29th 2013 by Kevin Purnelle
    • I've been investigating but I am sure how to resolve the problem. I've read Android doc and maybe it's related to that: http://developer.android.com/guide/topics/resources/runtime-changes.html the activity is closed and then launched again when orientation changes. I don' t know what to do on Ti side.

      — commented May 29th 2013 by Kevin Purnelle
    • (sorry I meant 'I'm not sure how to solve the problem')

      — commented May 29th 2013 by Kevin Purnelle
    • I've solved my problem this way (I force / constraint lanscape mode)
      In tiapp.xml, in android / manifest section this is what I've added:

      <activity android:name="ti.modules.titanium.media.TiVideoActivity" android:launchMode="singleTask" android:screenOrientation="landscape" android:configChanges="keyboardHidden|orientation|screenSize" android:theme="@android:style/Theme.NoTitleBar.Fullscreen"/>
      

      I suppose that this ti.modules.titanium.media.TiVideoActivity is the same for any video player activity. (when we lanch it fullscreen without adding it to a view / window)

      — commented May 29th 2013 by Kevin Purnelle
    • Awesome, great to hear you solved the issue.

      — commented May 29th 2013 by Justin Toth
    • If you are interested. I also handle the case where there was an error returned by youtube. This is how my onload function looks like. (basically just check response.result) The youtube error messages are in an array at response.errors

      client.onload = function () {
      
          var json = decodeURIComponent(decodeURIComponent(decodeURIComponent(decodeURIComponent(this.responseText.substring(4, this.responseText.length)))));
          var response = JSON.parse(json);
          var video, isHighQuality, streamUrl;
      
          if (response.result === 'ok') {
      
              video = response.content.video;
              isHighQuality = video['fmt_stream_map'] != null;
              streamUrl = isHighQuality ? video['fmt_stream_map'][0].url : video.stream_url;
      
              if (!isHighQuality) {
                  Ti.API.info('using low quality video because fmt_stream_map does not exist in json response, User-Agent probably is not being sent correctly');
              }
      
              Ti.API.info('stream url: ' + streamUrl)
              playVideo(streamUrl)
          }
          else {
      
              alert('The video could not be loaded. ' + response.errors[0])
          }
      }
      

      — commented May 29th 2013 by Kevin Purnelle
    • It is bad practice to alert an error.

      — commented May 29th 2013 by Kenan Sulayman
    • This is an example, the point was to show that youtube can return an error (video not found, account deleted, …) and how we can handle it.

      I don't see why it's bad practice. At least say why or give a link where it is explained.
      If it's because the type of the message is too "technical" and not useful for an end user, well maybe.

      — commented May 30th 2013 by Kevin Purnelle
    • Hi all, I am trying out the code on Android but still finding problem getting mp4 video after two days of trying various ways. Do any of you have the same problems on Android? I am using s3.

      — commented July 18th 2013 by Mong Suan Yee
    • Is this classic or alloy?

      — commented February 18th 2014 by Gustavo Severo
    • Any idea for alloy mode?

      Because a tried to use the codes posted for Jutin Toth and nothing happen!
      Thanks.

      — commented February 20th 2014 by Gustavo Severo
    • the iOS solution seems not working anymore from one week… We should change the User Agent? or what?

      — commented August 25th 2014 by Francesco Aiello
  • As long as you can get the MP4 version of the file I don't think it'll be an issue. I've been adding Revsion3 videos to my app (both for Android and iPhone) and it's now working fine. It took a bit of trial and error to get the code to work across both platforms.

    On Android it will always fire up a new window.. i.e. the video isn't embedded like you can do on the iPhone.

    — answered October 15th 2010 by Matt Collinge
    permalink
    1 Comment
    • how did you did that, can you guide me on that?

      — commented March 28th 2012 by Abrar Sair
  • Unfortunately I don't have control over the media type. It may not always be an MP4.

    — answered October 15th 2010 by Mansoor Charaniya
    permalink
    2 Comments
    • It will. (check the syntax of the returned JSON)

      — commented May 17th 2013 by Kenan Sulayman
    • Sorry Kenan, I tried various ways. Mansoor is right. It is not always MP4. I only get .3gp format and I did verify on the json.

      — commented July 18th 2013 by Mong Suan Yee
  • i have searched all the net, nothing happens, i really need to learn playing youtube videos, is this really so hard?nobody can't do that?

    — answered May 4th 2011 by Graham Jeffrey
    permalink
    0 Comments
  • : (
    @ since 2 weeks with Martin Guillon script -> HTTP-Fehler 403 (Forbidden): Der Server hat die Verarbeitung der Anforderung verweigert.

    help please.

    — answered October 12th 2012 by Jonathan Schneider
    permalink
    0 Comments
  • @ Martin Guillon
    I am newbie in Titanium Can You please post the whole code along with design to get the complete functionality i.e. running video from Youtube ..

    — answered February 8th 2013 by Muhammad Burhan
    permalink
    1 Comment
    • I am sorry but no. Sharing code snippet is a good thing but sharing full design/implementation is kind of too much.
      Sorry

      — commented February 8th 2013 by Martin Guillon
  • This code works on Android, but the format is .3GP (low quality) :

      function convert(a){
        //where "a" is video ID;
        var xhr = Ti.Network.createHTTPClient();
        xhr.setRequestHeader("Referer", "http://www.youtube.com/watch?v=" + a);
        xhr.setRequestHeader("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/536.26.14 (KHTML, like Gecko) Version/6.0.1 Safari/536.26.14");
        xhr.open("GET", "http://m.youtube.com/watch?ajax=1&feature=related&layout=mobile&tsp=1&&v=" + a);
        xhr.onload = function () {
                x = decodeURIComponent(decodeURIComponent(decodeURIComponent(decodeURIComponent(this.responseText.substring(4, this.responseText.length)))));
                y = OS_IOS ? JSON.parse(x).content.video["fmt_stream_map"][0].url : JSON.parse(x).content.video["stream_url"];
    
                movie.url = y;
                win.add(movie);
        };
        xhr.send();
    }
    
    — answered May 7th 2013 by Thomas Lemaitre
    permalink
    1 Comment
    • Checkout the version I created for Sreekanth: https://gist.github.com/KenanSulayman/5601881; might be straightforward.

      — commented May 17th 2013 by Kenan Sulayman
  • hi, if creating a webview? is not good?

    — answered December 3rd 2014 by Diego Schnider
    permalink
    0 Comments
  • i figured out how to play youtube videos with a regular video player ( Titanium.Media.VideoPlayer, or native as MPMoviePlayerController) - msg me at sircambridge at gmail

    — answered August 20th 2011 by gene tsai
    permalink
    6 Comments
    • hey Gene,

      Can you post here your solution for how to play Youtube videos using VideoPlayer, please?

      Thanks,
      Sridevi

      — commented October 24th 2011 by Sridevi Kolluri
    • I would also like to see your solution for playing the youtube vids

      thanks

      — commented November 12th 2011 by Sam Witteveen
    • that solution … please :-)

      — commented June 25th 2012 by George Georgiou
    • I would also like to see your solution for playing the youtube vids plz frward to
      hafsalrahman13@gmail.com

      — commented February 25th 2013 by hafsal Rahman
    • Here's my (simplified) version of the code:

      var win = Titanium.UI.createWindow({
          backgroundColor:'white'
      })
      
      var movie = Titanium.Media.createVideoPlayer({
          fullscreen: false,
          autoplay: false,
          width:320,height:180,bottom:0,left:0,
          backgroundColor: '#111',
          mediaControlStyle: Titanium.Media.VIDEO_CONTROL_DEFAULT,
          scalingMode: Titanium.Media.VIDEO_SCALING_ASPECT_FIT
      });
      
      convert('W4NoqRbhlFE');
      
      function convert(a){
          //where "a" is video ID;
          var xhr = Ti.Network.createHTTPClient();
          xhr.setRequestHeader("Referer", "http://www.youtube.com/watch?v=" + a);
          xhr.setRequestHeader("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/536.26.14 (KHTML, like Gecko) Version/6.0.1 Safari/536.26.14");
          xhr.open("GET", "http://m.youtube.com/watch?ajax=1&feature=related&layout=mobile&tsp=1&&v=" + a);
          xhr.onload = function () {
                  x = decodeURIComponent(decodeURIComponent(decodeURIComponent(decodeURIComponent(this.responseText.substring(4, this.responseText.length)))));
                  y = JSON.parse(x).content.video["fmt_stream_map"][0].url;
      
                  movie.url = y;
                  win.add(movie)
          };
          xhr.send()   
      }
      
      win.open();
      

      — commented March 1st 2013 by Carlos Henrique Lustosa Zinato
    • I had problem with the codes above… This message appears:
      "y = JSON.parse(x).content.player_data["fmt_stream_map"][0].url;"

      — commented February 18th 2014 by Gustavo Severo
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.