How can I get the Youtube player JS object? I would like to get the player's state as well as be able to start and stop the player on a button press. I would like to get the player object as described here: https://developers.google.com/youtube...
How can I get the Youtube player JS object? I would like to get the player's state as well as be able to start and stop the player on a button press. I would like to get the player object as described here: https://developers.google.com/youtube...
Hello,
You can add this, please read for more information here http://devcenter.appery.io/documentat...
Could you be more elaborate on how that could help me get Appery's Youtube player as a JS object?
I have also tried creating the youtube player manually but it doesn't work. I create an empty div called 'player' and then on page load, I invoke the following JS:
code
// 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
Code: Select all
tag.src = "https://www.youtube.com/iframe_api"
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// 3. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '390',
width: '640',
videoId: 'M7lc1UVf-VE',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
event.target.playVideo();
}
// 5. The API calls this function when the player's state changes.
// The function indicates that when playing a video (state=1),
// the player should play for six seconds and then stop.
var done = false;
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.PLAYING && !done) {
setTimeout(stopVideo, 6000);
done = true;
}
}
function stopVideo() {
player.stopVideo();
} /code
Hello,
You may use youtube component http://devcenter.appery.io/documentat...
Yes, but how do I get the JavaScript Youtube player object that lets me know the state of the player on a button click?!
You should use
codeApperyio("youtube_5").data("youtube-player-object")/code
where youtube_5 - name of youtube component
for example
codeApperyio("youtube_5").data("youtube-player-object").getPlayerState()/code
Thanks. Where is the documentation for the Apperyio functions that you use? I don't see links for them on the documentation page.
What's the difference between Appery() and Apperyio()?
Hi,
For now, there is no difference. Starting from the next release, we will use only codeApperyio()/code.