Titanium Community Questions & Answer Archive

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

iphone open youtube video embed in the webview, not in the built in youtube player

Hi,

I use the following code to open a youtube video:

var movie = '<html><head></head><body style="margin:0"><embed id="yt" src="' + $url + '" type="application/x-shockwave-flash" width="' + $width + '" height="' + $height + '"></embed></body></html>';
var webView = Titanium.UI.createWebView({
            html : movie,
            backgroundColor : "#000000",
            width : $width,
            height : $height,
            top : 0,
            left : 0
        });

This code loads an image in the webview with a play button in it and when the user clicks on it, it loads in a new window using the built-in youtube player. Is there a way to load the youtube video in my webview using the size I set and play it in there instead of loading it in the built-in player?

— asked February 14th 2012 by Onoma Epitheto
  • iphone
  • portrait
  • youtube
0 Comments

1 Answer

  • Hello,

    you are forcing the system to load the mobile version of the video in the webview. You should provide an url like the one described here and if you want, you can use the Youtube api to get the screenshot of the video into your webview.

    Best,

    Mauro

    — answered February 14th 2012 by Mauro Parra
    permalink
    4 Comments
    • Thank you for your feedback!
      I'm trying to use url of this type: "http://www.youtube.com/v/TllTPnH3qP4" but the app crashes with the following error:

      [ERROR] Error loading: http://www.youtube.com/v/TllTPnH3qP4, Error: Error Domain=WebKitErrorDomain Code=102 "Frame load interrupted" UserInfo=0x8ebac50 {NSErrorFailingURLKey=http://www.youtube.com/v/TllTPnH3qP4, NSErrorFailingURLStringKey=http://www.youtube.com/v/TllTPnH3qP4, NSLocalizedDescription=Frame load interrupted}
      

      Do you have any idea why? Using the format "http://www.youtube.com/watch?v=TllTPnH3qP4" works fine but I need the other one in order to show only the video and not the other data around the player (like the metadata, suggested videos etc).

      — commented February 15th 2012 by Onoma Epitheto
    • Which sdk?

      — commented February 15th 2012 by Mauro Parra
    • Can you show some code about how you do it?

      — commented February 15th 2012 by Mauro Parra
    • Hello!

      Could you help me?

      I use this code:

      var ytVideoSrc = "http://www.youtube.com/v/" + vguid;
      var videoWindow = Titanium.UI.createWindow({
          modal:false
      });
      var webView = Ti.UI.createWebView({
          top : 0,
          left : 0,
          width : "100%",
          height : "100%",
          url:ytVideoSrc
      });
      videoWindow.add(webView)
      videoWindow.open()
      

      But instead of video in Web View i get only white screen. :(

      URL that I get from YouTube - http://www.youtube.com/v/JDq5YUbq4Rc

      I use:

      • Motorola Xomm

      • Android 4.0.3

      • SDK version 1.8.2

      • Windows7

      — commented March 27th 2012 by Andrew Vesel4ak
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.