Youtube video is not playing in android. Please help.

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

Hi,

I am used many methods for playing youtube video in webview. Last time I tried was using iframe. The player comes, but the video is not playing.

I have my code here.

< iframe title="YouTube video player" type="text/html" width="425" height="349" src="http://www.youtube.com/embed/ydLiasdJeoo" frameborder="0">
This is inside <body> tag of the HTML file that I am loading in to the webview.

But the video is not working.

Please help me. or give me another working code in android.

3 Answers

It appears from other questions that Youtube support on Android is pretty weak. Though not ideal, here's a quick workaround to play a youtube video from an Android device:

Ti.Platform.openURL('http://www.youtube.com/embed/ydLiasdJeoo');

— answered 3 years ago by Tony Lukasavage
answer permalink
4 Comments
  • But it will load the entire youtube page, right?

    Do we have an option to load only the video player?

    — commented 3 years ago by Sreekumar K U

  • Unfortunately it does not appear so at this time. Here's another recent thread with a little more detail on the subject: <http://developer.appcelerator.com/question/51151/flash-en-webview-android-videos-youtube>

    There is mention of someone building a module to allow it, but I don't think it exists yet.

    — commented 3 years ago by Tony Lukasavage

  • So you are saying that there is no way other than

    Ti.Platform.openURL();
    ????

    Thank you Tony.

    — commented 3 years ago by Sreekumar K U

  • Show 1 more comment

Check the AndroidManifest.xml file and make sure you have the following uses-permission clause:

<uses-permission android:name="android.permission.INTERNET"/>
If this is the case, can you show the code for creating your webview and any other HTML that will be loaded in it?

— answered 3 years ago by Tony Lukasavage
answer permalink
1 Comment
  • It is there in my AndroidManifest.xml file.

    My code is

    media_tableview.addEventListener('click',function(e)
    {
            var win = Ti.UI.createWindow({barColor:'brown', title:e.rowData.subTitle})
                    blogview = Ti.UI.createWebView
                ({
                    url:e.rowData.filepath
                });
                win.add(blogview);
             win.rowData = e.rowData;
            Ti.UI.currentTab.open(win);
    });
    and in my html file
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
     
    Nunzio's Little Place On The Web
     
     
    </head>
    <body>
        < iframe title="YouTube video player" type="text/html" width="425" height="349" src="http://www.youtube.com/embed/ydLiasdJeoo" frameborder="0"> 
    </body>
    </html>
    If you have other options please help.

    — commented 3 years ago by Sreekumar K U

Are you testing this in the emulator or on a device? You should test this on a device, because the Android emulator images don't have a YouTube app installed.

On an actual device I'd use a VND URL to launch the YouTube app, e.g.

var intent = Titanium.Android.createIntent({ action: vnd:youtube:XZ5TajZYW6Y });
titanium.Android.currentActivity.startActivity(intent);

— answered 3 years ago by Allan Kim
answer permalink
4 Comments
  • Thank you

    But I don't know how to use this code in my file. Could you please explain it in some detail? Where should I have to use this?

    — commented 3 years ago by Sreekumar K U

  • SreeKumar,

    Did you ever find out how to do this? Here is how I implemented it -

    // Opening an Intent for opening Youtube player 
    var openYouTubeVideo = function(appFile){
        var tmpFile = undefined,
            newPath = undefined;
     
            try {
                if(Ti.Android.currentActivity == null){
                    // alert("Current activity is null");
     
                }
                var intent = Ti.Android.createIntent({
                    action: Ti.Android.ACTION_VIEW,             
                    data: 'vnd.youtube:' + appFile
                     });
                Ti.Android.currentActivity.startActivity(intent);
    //               
                 // var intent = Ti.Android.createIntent({
                     // action: 'null',
                     // data: 'ytv://'+appFile,
                     // packageName: 'com.keyes.youtube',
                     // className: 'com.keyes.youtube.OpenYouTubePlayerActivity'
                 // });
     
            }
            catch (err) {
     
                var alertDialog = Titanium.UI.createAlertDialog({
                    title: 'No Youtube player',
                    message: 'We tried to open a Youtube but failed. Do you want to search the marketplace for a Youtube viewer?',
                    buttonNames: ['Yes','No'],
                    cancel: 1
                });
                alertDialog.show();
                alertDialog.addEventListener('click', function(evt) {
                    if (evt.index == 0) {
                        Ti.Platform.openURL('http://search?q=pdf');
                    }
                });
            }
     
    }
    And you just call the openYouTubeVideo () function from wherever you want to, passing the youtube video id for the video.

    Hope this helps. If you have any questions, let me know.

    — commented 2 years ago by Sridevi Kolluri

  • hey Allan Kim,

    I dont know if you following this post or not, but hope you do.

    I used the same method to view Youtube videos. Do you know if we can open the video in youtube directly in fullscreen mode this way? If so, how?

    Anyone?

    Thanks!

    Sridevi

    — commented 2 years ago by Sridevi Kolluri

  • Show 1 more comment

Your Answer

Think you can help? Login to answer this question!