I’m using the API to embed videos direct into a site. And I’m having issues with the javascript events. The events just don’t seem to trigger. I ideally want to use .ONLINE but am currently using .PAUSED as it’s easier to test.
var player = new Twitch.Player("twitchplayer", options);
player.addEventListener('Twitch.Player.PAUSED', function() {
console.log('paused');
});
I wouldn’t use events for that. Since then you are fighting autoplay/muted logic in browsers even more so.
Either just show the player regardless of stream status, as doing it pure player reading you have to show the player, wait for it to read the status, then show/hide then you don’t know if autoplay was aborted by the browser or not.
I’d pull the data from the API or via Webhooks and frontend based on that so if the page is open and the stream state changes the palyer wouldn’t appear until reload
Additionally if you hide the player via CSS, there is no guarantee the browser will allow the player to auto play when the stream goes live, blocking the event triggers.
See I’ve got it to work so that when the video ends, it hides using .getEnded().
Could you elaborate on this please?
Either just show the player regardless of stream status, as doing it pure player reading you have to show the player, wait for it to read the status, then show/hide then you don’t know if autoplay was aborted by the browser or not.
But conversely the other way you may have issues as a hidden dom element may get blocked by the browser for autoplay, so you may not see any events trigger.