How to play youtube videos.

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'









    <script type="text/javascript">

        function tiPlay() {



        function tiPause() {





<body style="margin:0; padding: 0">

    <video id="viddlerVideo-87cd75f3" src="" 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