How to play youtube videos.

You must Login before you can answer or comment on any questions.

Hi, I am using Titanium to develop an application. Here in this application I want play videos from youtube. I was able to play videos of type .mp4 which are in the local path of the project. But when I try to play videos from remote I am failing to play. I want to play youtube videos also. I tried using MediaPlayer and using webview also. But I can`t play the videos. Below is my code using webview...


var win = Ti.UI.createWindow({

backgroundColor : 'white',

exitOnClose : true,

layout : 'vertical',

orientationModes : [Ti.UI.PORTRAIT],

height : Ti.UI.FILL


var scrollView = Titanium.UI.createScrollView({

top : '10%',

width : 500,

height : 500,

scrollType : 'horizontal'


var baseHeight = 500;

var baseWidth = 500;

var img = Ti.UI.createImageView({ image : 'flower.jpg', height : baseHeight, width : baseWidth });


var button = Ti.UI.createButton({

top : '10%',

title : 'Click for Video',

width : Ti.UI.SIZE,

height : Ti.UI.SIZE


scrollView.addEventListener('pinch', function(e) {

if (e.scale >= 1) {

    var t = Ti.UI.create2DMatrix().scale(e.scale);

    img.transform = t;

    scrollView.showHorizontalScrollIndicator = true;

    scrollView.contentWidth = 500 * e.scale;

    scrollView.left = scrollView.left;



button.addEventListener('click', function() {

var win1 = Ti.UI.createWindow({

    backgroundColor : 'white',

    orientationModes : [Ti.UI.LANDSCAPE_LEFT, Ti.UI.LANDSCAPE_RIGHT],

    fullscreen : true


var webVideo = Ti.UI.createWebView({

    width : Ti.UI.FILL,

    height : Ti.UI.FILL,

    url : 'video.html'









    &lt;script type=&quot;text/javascript&quot;&gt;

        function tiPlay() {



        function tiPause() {





&lt;body style=&quot;margin:0; padding: 0&quot;&gt;

    &lt;video id=&quot;viddlerVideo-87cd75f3&quot; src=&quot;; type=

"video/mp4" width="320" height="180" poster="" controls="con

trols" onPlay="tiPlay();" onPause="tiPause();"></video>



But still I am unable to play videos. There is a youtube video url in video tag. Even I tried using MediaPlayer by specifying the same url to the url property of MediaPlayer. But no use. I want to play this video automatically when I click on the button and should close the video and should return to previous window once video gets completed. Can anyone share a possible solution.

Thanks in Advance


1 Answer

— answered 2 years ago by Jigar Maheshwari
answer permalink
  • hi jigar,

    I tried the code in the link you given. But still it is not playing any video. Can you suggest the modifications in the code which I posted.

    — commented 2 years ago by Prasad M.R.C

  • hi jigar,

    Can you share any sample code that works fine in both android and ios platforms for accessing remote videos using media player of titanium.

    Thanks in Advance

    — commented 2 years ago by Prasad M.R.C

Your Answer

Think you can help? Login to answer this question!