I have a youtube player on a web page created with the YouTube IFrame API
When I get an onStateChange
event, like in the code example:
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '390',
width: '640',
videoId: 'M7lc1UVf-VE',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
When onPlayerStateChange
is being called, I would like to be able to differentiate between
player.playVideo()
, player.pauseVideo()
etc)Currently both result in exactly the same event.
I think you are going to run into the cross-domain iframe problem.
As I mentioned in my comment, there might be some useful information in the event object that is passed to the event listeners. I browsed at least two levels and could find no difference between a user click action and an API call. However, there is a lot of information in the object and possibly something that would help distinguish the two actions.
If your code is making the API calls, perhaps you could track this some other way. Then your code could tell if an API call was made. Maybe store the current call and a timestamp -- something along those lines.
Finally, maybe there is another way to capture the information you are after. Your question doesn't really specify the ultimate goal. I'd recommend exploring alternatives as a simple solution doesn't appear possible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With