Skip to content

Instantly share code, notes, and snippets.

@4rn0
Created July 19, 2012 19:34
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save 4rn0/3146246 to your computer and use it in GitHub Desktop.
Save 4rn0/3146246 to your computer and use it in GitHub Desktop.
Trigger fullscreen HTML5 video on iPad
<!DOCTYPE html>
<html>
<head>
<title>Trigger fullscreen HTML5 video on iPad</title>
<style>
#video { height: 1px; opacity: 0; position: absolute; width: 1px; }
#play { width: 100px; }
</style>
</head>
<body>
<video src="http://82.201.53.54:1935/livestream/iphone538.sdp/playlist.m3u8" id="video"></video>
<button id="play">play fullscreen video</button>
<script>
var video = document.getElementById('video'),
play = document.getElementById('play'),
time;
video.addEventListener('webkitbeginfullscreen', function() {
play.innerText = 'play fullscreen video';
window.clearInterval(time);
});
video.addEventListener('webkitendfullscreen', function() {
video.pause();
});
play.addEventListener('touchstart', function() {
time = window.setInterval(function() {
try {
video.webkitEnterFullscreen();
}
catch(e) {}
}, 250);
play.innerText = 'loading ...';
video.play();
});
</script>
</body>
</html>
@heartcode
Copy link

Just what I have been looking for, lifesaver! Thanks for sharing!

@julkue
Copy link

julkue commented Dec 4, 2015

If you never reset the interval and have multiple videos to play, your application will probably crash soon!

@scoobster17
Copy link

scoobster17 commented Nov 7, 2016

Hey, thanks for this, saved me!

I didn't notice at first (just thought I would point out to others) but the method applies to the video element itself rather than a container element (e.g. div / section) which you can use videoContainer.webkitRequestFullscreen() for, for browsers other than on iPad e.g. desktop Chrome.

@MrWoofus
Copy link

Just ran across this and it's almost perfect for what I'm needing. ;)

Can someone give me a hint on how to duplicate the buttons? I'd like to put multiple buttons on the page, all pointing toward different streams.

@hgsadhrakiya
Copy link

It is working very well & helped me to implement the same effect in all the devices 🙂 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment