Peter Burkert
Peter Burkert

Reputation: 451

Force opening app for embedded youtube video

I would like to embed a youtube video (with the standard iframe). Can I ensure that the video is played in the youtube app, if it is clicked on using a smartphone?
For completeness my video including code (using bootstrap 3.3.1.):

<div class="embed-responsive embed-responsive-16by9">
    <iframe class="embed-responsive-item" src="https://www.youtube.com/embed/<?php echo $Elem->video; ?>"> 
    </iframe>
</div>

Thank you

Upvotes: 0

Views: 3379

Answers (1)

Gonzalingui
Gonzalingui

Reputation: 1405

I'm just trying to do the same thing and I can tell you that there is no native way to specify that behaviour as a parameter.

The only workaround (I'm still trying to implement it) is to use YouTube's Player API for iframe. I think you should use that API to embed the video on the webpage and add a listener to the first "play" event, in that event you should check if the user is using a mobile device (using another JS library to check that) and stop the playback (the stop() API call will also stop the loading of the video file) and then redirect the user to the video URL (like youtube.com/xxxxxx). At that time, at least in Android, the user will be asked to open the link in the browser or the YouTube app. I think most user have the app as the default option.

That's the idea, I'll try it and if it works will edit this response with the code I've used.

This is the link where you can read about embedding the player, it's events and API calls: https://developers.google.com/youtube/iframe_api_reference#Loading_a_Video_Player

Upvotes: 1

Related Questions