How can I trigger a YouTube video to play in browser on iOS by clicking on a play button instead of the embed?

andrewb

On my site, I want to have users watch an embedded YouTube video without leaving the page, but I don't want to have the not so stylistic YouTube embed visible prior to clicking.

This is entirely doable on desktop, as you can use the YouTube JavaScript API to trigger the embed to play, but on iOS, programmatic triggering of the player to play is blocked. So how can I do this on iOS?

andrewb

When thinking about this problem, I thought that one alternative route would be to have a layer that's opaque and styled, but you could click through it. This would mean the user thinks they're clicking a pretty button, when actually they're just clicking the embed to play.

Turns out there's a way of doing this, using the fancy (unofficial) CSS pointer-events property! Setting this to none means that clicks don't register, and instead punch straight through the element to whatever is behind it. In this case, the YouTube embed iframe. Support is iOS 6+.

Here's a JSFiddle of it working.

Note this is for iOS (and maybe Android) - it utilises the behaviour in which the video will automatically go full screen when it starts playing. If you watch this on desktop, the overlay remains.. overlaid.

There's some more polishing to be done with this to get it schmick:

  • Handling the initial click and altering the UI so they know immediately the video is kicking off. Perhaps hide the overlay, fade it, or change it to simply signify "Loading... "
  • On finish, resetting the video by recreating the iframe

You could do some tricky stuff with this technique, e.g. having a small player iframe overlaid by a small button. Still going to go fullscreen, so it'll work fine.

But regardless, there you go - proof of concept of playing a YouTube video on iOS without the user knowing they clicked on an embed.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I check if a YouTube video allows embedded play

From Dev

How can I play a youtube video AND ncmpcpp at the same time?

From Dev

how to play youtube video using jwplayer in ios ?

From Dev

How to play youtube video?

From Dev

How to play youtube video?

From Dev

Play/Pause button for a youtube video

From Dev

How can I overlay a "play button" over a VR Video?

From Dev

How can I overlay a "play button" over a VR Video?

From Dev

How to hide video stop and play button in iOS?

From Dev

Play embed YouTube without pressing the red button

From Dev

Can I embed my Picasa video to play on my website?

From Dev

Trigger function when clicking play button on <audio>

From Dev

Can't play video in browser

From Dev

Play Youtube Video Full Screen in Browser

From Dev

How to add a button to play YouTube video full screen using JavaScript?

From Dev

Disable clicking on the play button in video carousel

From Dev

Delay video after clicking play button

From Dev

After I played 2 videos and closed iFrame, the "Back" button on browser will play sound without video, how to fix it?

From Dev

Showing youtube video in webview its displaying the Blank page;while clicking the play button the screen will becomes blank

From Dev

How to play YouTube video without leaving app on iOS 7

From Dev

Video crashes whenever I play a video in youtube

From Dev

How can i play a video in chunks of bytes?

From Dev

How can i play a video in chunks of bytes?

From Dev

How can I play a video using AVPlayer?

From Dev

How to play youtube Embed videos on Android Device

From Dev

Adding a custom play button for Youtube video

From Java

How can I embed a YouTube video on GitHub wiki pages?

From Dev

How can i hide the play/pause button?

From Dev

How to embed youtube video in Phonegap ios app

Related Related

  1. 1

    How can I check if a YouTube video allows embedded play

  2. 2

    How can I play a youtube video AND ncmpcpp at the same time?

  3. 3

    how to play youtube video using jwplayer in ios ?

  4. 4

    How to play youtube video?

  5. 5

    How to play youtube video?

  6. 6

    Play/Pause button for a youtube video

  7. 7

    How can I overlay a "play button" over a VR Video?

  8. 8

    How can I overlay a "play button" over a VR Video?

  9. 9

    How to hide video stop and play button in iOS?

  10. 10

    Play embed YouTube without pressing the red button

  11. 11

    Can I embed my Picasa video to play on my website?

  12. 12

    Trigger function when clicking play button on <audio>

  13. 13

    Can't play video in browser

  14. 14

    Play Youtube Video Full Screen in Browser

  15. 15

    How to add a button to play YouTube video full screen using JavaScript?

  16. 16

    Disable clicking on the play button in video carousel

  17. 17

    Delay video after clicking play button

  18. 18

    After I played 2 videos and closed iFrame, the "Back" button on browser will play sound without video, how to fix it?

  19. 19

    Showing youtube video in webview its displaying the Blank page;while clicking the play button the screen will becomes blank

  20. 20

    How to play YouTube video without leaving app on iOS 7

  21. 21

    Video crashes whenever I play a video in youtube

  22. 22

    How can i play a video in chunks of bytes?

  23. 23

    How can i play a video in chunks of bytes?

  24. 24

    How can I play a video using AVPlayer?

  25. 25

    How to play youtube Embed videos on Android Device

  26. 26

    Adding a custom play button for Youtube video

  27. 27

    How can I embed a YouTube video on GitHub wiki pages?

  28. 28

    How can i hide the play/pause button?

  29. 29

    How to embed youtube video in Phonegap ios app

HotTag

Archive