Last active
August 9, 2016 17:21
-
-
Save fantasywind/ce686fde14084f54560a6d12ed89d7e5 to your computer and use it in GitHub Desktop.
AAMS iOS YouTube Frame
This file contains 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> | |
<body> | |
<div id="player"></div> | |
<script> | |
var apiLoaded = false; | |
var playerReady = false; | |
var player; | |
function onYouTubeIframeAPIReady() { | |
apiLoaded = true; | |
} | |
function onPlayerReady(e) { | |
playerReady = true; | |
window.location = 'youtube-ready://ok'; | |
} | |
function playVideo() { | |
if (!playerReady) return alert('Player is not ready'); | |
player.playVideo(); | |
} | |
function pauseVideo() { | |
if (!playerReady) return alert('Player is not ready'); | |
player.pauseVideo(); | |
} | |
function seekVideoTo(seconds = 0) { | |
if (!playerReady) return alert('Player is not ready'); | |
player.seekTo(seconds); | |
} | |
function loadVideo(videoId) { | |
if (!apiLoaded) return alert('API Not Loaded, please wait...'); | |
if (!videoId) return alert('Cannot found videoId'); | |
player = new YT.Player('player', { | |
height: document.documentElement.clientHeight, | |
width: document.documentElement.clientWidth, | |
videoId, | |
events: { | |
'onReady': onPlayerReady, | |
}, | |
playerVars: { | |
loop: 0, | |
enablejsapi: 1, | |
rel: 0, | |
controls: 0, | |
autoplay: 1, | |
playsinline: 1, | |
showinfo: 0, | |
}, | |
}); | |
} | |
</script> | |
<script src="https://www.youtube.com/iframe_api"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment