Created
July 19, 2012 19:34
-
-
Save 4rn0/3146246 to your computer and use it in GitHub Desktop.
Trigger fullscreen HTML5 video on iPad
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
If you never reset the interval and have multiple videos to play, your application will probably crash soon!
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.
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.
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
Just what I have been looking for, lifesaver! Thanks for sharing!