Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force video to open in Youtube app on Android

I have a mobile website that links to a youtube video. On Android, clicking on this link brings up a dialog asking the user to "Complete action using" their browser or the Youtube app.

Is there a way to bypass this screen and just play the video in the Youtube app? (For example with a youtube:// URL.)

Thanks!

like image 640
tba Avatar asked Jun 20 '12 06:06

tba


People also ask

How do I force YouTube to open the app?

Go to "Settings > Apps > ⁝ > Default Apps > Set as Default > YouTube > Go to Supported URLs > In this app". Your phone may look different with options like "Opening Links" and "Open supported Links" instead. Tap those options to continue.

Why YouTube opens in browser instead of app?

This behavior is because the YouTube app for Android is the default and specialized application for detection of YouTube links playing YouTube videos. Some users might not like this behavior of being forced to use the YouTube app for watching YouTube Videos and might want to use a web browser instead.


1 Answers

Try to use a JavaScript redirection like the following:

window.location = "vnd.youtube://the.youtube.video.url";

More comprehensively:

if( /Android/i.test(navigator.userAgent ) ) {
    // If the user is using an Android device.
    setTimeout(function () { window.location = "market://details?id=com.google.android.youtube"; }, 25);
    window.location = "vnd.youtube://www.youtube.com/watch?v=yourVideoId";
}

If Youtube app is disabled, the timeout function will redirect you to the youtube app on the play store to let you enable the app. The second redirect will pop up and play the youtube video on Android Youtube app.

If you are already switched to the YouTube app within the timeout interval, the timeout function will not be called and you are not switched to the play store but stay in the YouTube app.

like image 115
Casper Avatar answered Sep 28 '22 10:09

Casper