abhiprays
Posts: 0
Joined: Sat Jun 21, 2014 4:44 am

Get Youtube Player object in JS

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...

Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

Get Youtube Player object in JS

Hello,

You can add this, please read for more information here http://devcenter.appery.io/documentat...

abhiprays
Posts: 0
Joined: Sat Jun 21, 2014 4:44 am

Get Youtube Player object in JS

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&quot 
   var firstScriptTag = document.getElementsByTagName('script')[0]; 
   firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); 

   &#47;&#47; 3&#46; This function creates an <iframe> (and YouTube player) 
   &#47;&#47;    after the API code downloads&#46; 
   var player; 
   function onYouTubeIframeAPIReady() { 
     player = new YT&#46;Player('player', { 
       height: '390', 
       width: '640', 
       videoId: 'M7lc1UVf-VE', 
       events: { 
         'onReady': onPlayerReady, 
         'onStateChange': onPlayerStateChange 
       } 
     }); 
   } 

   &#47;&#47; 4&#46; The API will call this function when the video player is ready&#46; 
   function onPlayerReady(event) { 
     event&#46;target&#46;playVideo(); 
   } 

   &#47;&#47; 5&#46; The API calls this function when the player's state changes&#46; 
   &#47;&#47;    The function indicates that when playing a video (state=1), 
   &#47;&#47;    the player should play for six seconds and then stop&#46; 
   var done = false; 
   function onPlayerStateChange(event) { 
     if (event&#46;data == YT&#46;PlayerState&#46;PLAYING && !done) { 
       setTimeout(stopVideo, 6000); 
       done = true; 
     } 
   } 
   function stopVideo() { 
     player&#46;stopVideo(); 
   } 

/code

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Get Youtube Player object in JS

Hello,

You may use youtube component http://devcenter.appery.io/documentat...

abhiprays
Posts: 0
Joined: Sat Jun 21, 2014 4:44 am

Get Youtube Player object in JS

Yes, but how do I get the JavaScript Youtube player object that lets me know the state of the player on a button click?!

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Get Youtube Player object in JS

You should use

codeApperyio("youtube_5")&#46;data("youtube-player-object")/code

where youtube_5 - name of youtube component

for example

codeApperyio("youtube_5")&#46;data("youtube-player-object").getPlayerState()/code

abhiprays
Posts: 0
Joined: Sat Jun 21, 2014 4:44 am

Get Youtube Player object in JS

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()?

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Get Youtube Player object in JS

Hi,

For now, there is no difference. Starting from the next release, we will use only codeApperyio()/code.

http://devcenter.appery.io/documentat...

Return to “Issues”