# Twitch.Player events not firing the way they used to - change in behavior?

**URL:** <https://discuss.dev.twitch.com/t/twitch-player-events-not-firing-the-way-they-used-to-change-in-behavior/9213>\
**Category:** API\
**Created:** [February 10, 2017, 2:06am UTC](https://discuss.dev.twitch.com/t/twitch-player-events-not-firing-the-way-they-used-to-change-in-behavior/9213 "2017-02-10T02:06:27Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Argus9](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/argus9/32/1886_2.png) [@Argus9](https://discuss.dev.twitch.com/u/Argus9)\
**Post date:** [February 10, 2017, 2:06am UTC](https://discuss.dev.twitch.com/t/twitch-player-events-not-firing-the-way-they-used-to-change-in-behavior/9213/1 "2017-02-10T02:06:27Z")

</div>

Hi folks. I’ve noticed what appears to be a change in Twitch.Player events that fire when a stream goes offline, when dealing with interactive player embeds and the twitch.js library.

I’ve set up a simple test page to test which events fire when the stream goes online or offline, and when:

```auto
<head>
    <style>
        html, body {
            margin: 0;
            padding: 0;
        }
        #container {
            display: flex;
            flex-flow: row nowrap;
        }

        #streams {
            flex: 0 0 60%;
        }

        #log {
            flex: 0 0 40%;
        }

        #container > div {
            height: 100vh;
            overflow-y: auto;
        }

        #streams > div {
            width: 100%;
            height: 480px;
        }
    </style>
</head>
<script src= "http://player.twitch.tv/js/embed/v1.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<div id="container">
    <div id="streams"></div>
    <div id="log">
        Events will appear here.
        <ul id="event-list"></ul>
    </div>
</div>
<script type="text/javascript">
    var options = {width: '100%', height: '100%', channel: 'Argus9'};
    var id = 'player-' + 'Argus9';
    $('#streams').append('<div id="' + id + '"></div>');
    var player = new Twitch.Player(id, options);
    player.setMuted(false);
    player.setVolume(1);

    player.addEventListener(Twitch.Player.ONLINE, function () {
        $('#event-list').append('<li style="color: darkgreen;">[' + new Date($.now()).toISOString() + '][' + 'Argus9' + '][VISIBLE] ONLINE</li>');
    });
    player.addEventListener(Twitch.Player.OFFLINE, function () {
        $('#event-list').append('<li style="color: darkred;">[' + new Date($.now()).toISOString() + '][' + 'Argus9' + '][VISIBLE] OFFLINE</li>');
    });
    player.addEventListener(Twitch.Player.PAUSE, function () {
        $('#event-list').append('<li style="color: darkgoldenrod;">[' + new Date($.now()).toISOString() + '][' + 'Argus9' + '][VISIBLE] PAUSE</li>');
    });
    player.addEventListener(Twitch.Player.ENDED, function () {
        $('#event-list').append('<li style="color: darkred;">[' + new Date($.now()).toISOString() + '][' + 'Argus9' + '][VISIBLE] ENDED</li>');
    });
    player.addEventListener(Twitch.Player.PLAY, function () {
        $('#event-list').append('<li style="color: darkgreen;">[' + new Date($.now()).toISOString() + '][' + 'Argus9' + '][VISIBLE] PLAY</li>');
    });
    player.addEventListener(Twitch.Player.READY, function () {
        $('#event-list').append('<li style="color: darkgreen;">[' + new Date($.now()).toISOString() + '][' + 'Argus9' + '][VISIBLE] READY</li>');
    });
</script>

```

The page itself isn’t very important - it’s just a diagnostic tool to figure out the larger issue I’m writing about here.

Previously, the embedded player behaved such that it would automatically resume playing if its channel went from OFFLINE to ONLINE. In this case the Twitch.Player.ONLINE event occurs, and any event listeners on that event would fire.

When a channel goes from ONLINE to OFFLINE, the Twitch.Player.OFFLINE event (and Twitch.Player.ENDED, I believe) event(s) would fire.

Now, I’m noticing entirely different behavior:

**Behavior / Events Fired**  
Player loaded, Channel is Online / Ready, Online, Play  
Channel goes from Online to Offline / Paused, Ended  
Player loaded, Channel is Offline / Ready, Ended  
Channel goes from Offline to Online / _None_

Can anyone explain this change in behavior? This completely breaks an implementation I’m working on with multiple streams in a page, which relies on event listeners to function properly.

---

<div class="post-metadata">

**Author:** ![Argus9](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/argus9/32/1886_2.png) [@Argus9](https://discuss.dev.twitch.com/u/Argus9)\
**Post date:** [February 15, 2017, 7:30pm UTC](https://discuss.dev.twitch.com/t/twitch-player-events-not-firing-the-way-they-used-to-change-in-behavior/9213/2 "2017-02-15T19:30:11Z")

</div>

Sorry for the bump, but can anyone please provide some information on this? Even knowing it’s a known issue and being investigated would be reassuring. This is a pretty big break in functionality. I’ve been able to successfully reproduce this problem over multiple browsers (with all extensions disabled), and I’ve even found the non-interactive iframe also suffers from the inability to autoplay when a channel comes online.

Any information would be greatly appreciated. Thanks!

---

<div class="post-metadata">

**Author:** ![DallasNChains](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/dallasnchains/32/1608_2.png) [@DallasNChains](https://discuss.dev.twitch.com/u/DallasNChains)\
**Post date:** [February 15, 2017, 7:40pm UTC](https://discuss.dev.twitch.com/t/twitch-player-events-not-firing-the-way-they-used-to-change-in-behavior/9213/3 "2017-02-15T19:40:47Z")

</div>

We haven’t changed this behavior recently. Have you tried changing the event names to strings? They’re currently not strings in your code. E.g.

```
player.addEventListener('Twitch.Player.ONLINE', function () {
        $('#event-list').append('<li style="color: darkgreen;">[' + new Date($.now()).toISOString() + '][' + 'Argus9' + '][VISIBLE] ONLINE</li>');
    });
```

---

<div class="post-metadata">

**Author:** ![Argus9](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/argus9/32/1886_2.png) [@Argus9](https://discuss.dev.twitch.com/u/Argus9)\
**Post date:** [February 15, 2017, 7:43pm UTC](https://discuss.dev.twitch.com/t/twitch-player-events-not-firing-the-way-they-used-to-change-in-behavior/9213/4 "2017-02-15T19:43:01Z")

</div>

Hey @DallasNChains, thanks for reaching out. Let me give that a try and get back to you. I’d like to note, though, that it’s not that _no_ event listeners are firing, just not the ones I (used to) expect. Please see my note above under **Behavior / Events Fired** - and sorry, I couldn’t seem to get Markdown tables to work so it’s kind of messy. 🙂

I’ll try this right away and get back to you.

---

<div class="post-metadata">

**Author:** ![Argus9](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/argus9/32/1886_2.png) [@Argus9](https://discuss.dev.twitch.com/u/Argus9)\
**Post date:** [February 15, 2017, 7:47pm UTC](https://discuss.dev.twitch.com/t/twitch-player-events-not-firing-the-way-they-used-to-change-in-behavior/9213/5 "2017-02-15T19:47:22Z")

</div>

@DallasNChains changing the events to Strings didn’t work. Now none of my event listeners are firing. 😖 I know the documentation says the event is a String, but I believe it’s referring to the variable the constant “Twitch.Player.ONLINE” (etc.) refers to. For instance, Twitch.Player.ONLINE = “online”.

---

<div class="post-metadata">

**Author:** ![DallasNChains](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/dallasnchains/32/1608_2.png) [@DallasNChains](https://discuss.dev.twitch.com/u/DallasNChains)\
**Post date:** [February 15, 2017, 7:55pm UTC](https://discuss.dev.twitch.com/t/twitch-player-events-not-firing-the-way-they-used-to-change-in-behavior/9213/6 "2017-02-15T19:55:05Z")

</div>

I’ll chat with the video playback team and keep you posted! 🙂

---

<div class="post-metadata">

**Author:** ![Argus9](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/argus9/32/1886_2.png) [@Argus9](https://discuss.dev.twitch.com/u/Argus9)\
**Post date:** [February 15, 2017, 7:55pm UTC](https://discuss.dev.twitch.com/t/twitch-player-events-not-firing-the-way-they-used-to-change-in-behavior/9213/7 "2017-02-15T19:55:46Z")

</div>

Much appreciated @DallasNChains, thanks so much! 😃

---

<div class="post-metadata">

**Author:** ![Argus9](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/argus9/32/1886_2.png) [@Argus9](https://discuss.dev.twitch.com/u/Argus9)\
**Post date:** [February 22, 2017, 1:19am UTC](https://discuss.dev.twitch.com/t/twitch-player-events-not-firing-the-way-they-used-to-change-in-behavior/9213/8 "2017-02-22T01:19:31Z")

</div>

Hi @DallasNChains - were you able to speak with the video playback team on this yet? Also, just curious, but were you able to reproduce this yourself?

1. Embed an interactive video player in an HTML page for your channel or one you control (so you can go online/offline at will).
2. Add an event listener to the player for each of the supported events (Twitch.Player.x): ONLINE, OFFLINE, PAUSE, PLAY, READY, ENDED. Make the event listeners do something to make monitoring them easy; for instance, console.log to report which event fired.
3. Load the page under the following conditions and observe which callbacks fire:  
a. Load page when channel is online. Expected events: READY, ONLINE, PLAY. Actual events: READY, ONLINE, PLAY.  
b. Have the channel go offline. Expected events: OFFLINE, ENDED. Player immediately lists the channel as “OFFLINE” instead of “LIVE”. Actual events: PAUSE, ENDED. The player does not always update (or takes minutes to update) to indicate the channel is offline.  
c. Load page when channel is offline. Expected events: READY, OFFLINE. Channel is not ever listed as “LIVE”. Actual events: READY, ENDED. Channel is sometimes listed as “LIVE”.  
d. Have the channel go from offline to online. Expected events: ONLINE, PLAY. Stream begins playing automatically. Actual events: ONLINE, PLAY. Stream does not begin playing automatically and does not update its label to indicate the channel is now online.

---

<div class="post-metadata">

**Author:** ![DallasNChains](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/dallasnchains/32/1608_2.png) [@DallasNChains](https://discuss.dev.twitch.com/u/DallasNChains)\
**Post date:** [February 22, 2017, 4:29pm UTC](https://discuss.dev.twitch.com/t/twitch-player-events-not-firing-the-way-they-used-to-change-in-behavior/9213/9 "2017-02-22T16:29:46Z")

</div>

The team is looking into this. I’ll follow up again today. 🙂

---

<div class="post-metadata">

**Author:** ![Argus9](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/argus9/32/1886_2.png) [@Argus9](https://discuss.dev.twitch.com/u/Argus9)\
**Post date:** [February 22, 2017, 5:32pm UTC](https://discuss.dev.twitch.com/t/twitch-player-events-not-firing-the-way-they-used-to-change-in-behavior/9213/10 "2017-02-22T17:32:20Z")

</div>

Thanks @DallasNChains!

---

<div class="post-metadata">

**Author:** ![Argus9](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/argus9/32/1886_2.png) [@Argus9](https://discuss.dev.twitch.com/u/Argus9)\
**Post date:** [March 6, 2017, 7:02pm UTC](https://discuss.dev.twitch.com/t/twitch-player-events-not-firing-the-way-they-used-to-change-in-behavior/9213/11 "2017-03-06T19:02:12Z")

</div>

Hi @DallasNChains. Just checking in, any updates on this issue? Anything you can share? I’m still able to reproduce the above behavior.

Thank you!

---

<div class="post-metadata">

**Author:** ![DallasNChains](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/dallasnchains/32/1608_2.png) [@DallasNChains](https://discuss.dev.twitch.com/u/DallasNChains)\
**Post date:** [March 7, 2017, 3:55pm UTC](https://discuss.dev.twitch.com/t/twitch-player-events-not-firing-the-way-they-used-to-change-in-behavior/9213/12 "2017-03-07T15:55:55Z")

</div>

Hm. The fix for this was supposed to be deployed last week. I was out of the office at GDC. Let me check for you, @Argus9.

---

<div class="post-metadata">

**Author:** ![DallasNChains](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/dallasnchains/32/1608_2.png) [@DallasNChains](https://discuss.dev.twitch.com/u/DallasNChains)\
**Post date:** [March 7, 2017, 5:30pm UTC](https://discuss.dev.twitch.com/t/twitch-player-events-not-firing-the-way-they-used-to-change-in-behavior/9213/13 "2017-03-07T17:30:43Z")

</div>

@Argus9 The fix for this was actually deployed. I tested it to see what I get.

> **Stream is Online (scenario 3a)**
>
> [2017-03-07T17:04:43.107Z] READY [2017-03-07T17:04:44.198Z] ONLINE [2017-03-07T17:04:44.199Z] ONLINE [2017-03-07T17:04:44.585Z] PLAY [2017-03-07T17:04:45.713Z] PLAY [2017-03-07T17:04:45.717Z] PLAY

> **Stream goes Offline from Online (scenario 3b)**
>
> [2017-03-07T16:23:03.187Z] READY [2017-03-07T16:23:04.298Z] PLAY [2017-03-07T16:23:05.006Z] ONLINE [2017-03-07T16:23:05.007Z] ONLINE [2017-03-07T16:23:05.426Z] PLAY [2017-03-07T16:23:05.427Z] PLAY [2017-03-07T16:23:22.582Z] OFFLINE [2017-03-07T16:23:22.583Z] OFFLINE [2017-03-07T16:23:29.499Z] PAUSE [2017-03-07T16:23:29.499Z] PAUSE [2017-03-07T16:23:29.500Z] ENDED [2017-03-07T16:23:29.500Z] ENDED

> **Channel is offline (scenario 3c)**
>
> [2017-03-07T17:29:59.738Z] READY [2017-03-07T17:30:00.977Z] PLAY [2017-03-07T17:30:01.105Z] ENDED [2017-03-07T17:30:01.107Z] ENDED

I can’t get 3d to work, so I’m following up with the engineers on that one.

---

<div class="post-metadata">

**Author:** ![Argus9](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/argus9/32/1886_2.png) [@Argus9](https://discuss.dev.twitch.com/u/Argus9)\
**Post date:** [March 7, 2017, 9:00pm UTC](https://discuss.dev.twitch.com/t/twitch-player-events-not-firing-the-way-they-used-to-change-in-behavior/9213/14 "2017-03-07T21:00:01Z")

</div>

Hey @DallasNChains, thanks for the update. I can confirm that I can reproduce the log entries you mentioned above. I’m looking forward to hearing what the engineering team thinks about scenario 3d.

I assume we shouldn’t be seeing those events fire multiple times too, right?

---

<div class="post-metadata">

**Author:** ![Argus9](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/argus9/32/1886_2.png) [@Argus9](https://discuss.dev.twitch.com/u/Argus9)\
**Post date:** [March 18, 2017, 7:05pm UTC](https://discuss.dev.twitch.com/t/twitch-player-events-not-firing-the-way-they-used-to-change-in-behavior/9213/15 "2017-03-18T19:05:56Z")

</div>

Hi @DallasNChains, I checked on the state of the player now and it looks like your engineers made some great progress! Events are now firing like they used to - I’m seeing ONLINE and OFFLINE events. I noticed autoplay still isn’t working, but looking in the console I see what could be the cause:

Uncaught TypeError: Cannot read property ‘updating’ of null  
at t.Lr ([cvp.twitch.tv/1.5.1/player-core-min.js:1](http://cvp.twitch.tv/1.5.1/player-core-min.js:1))

I hope this helps! Thanks for investigating all of this so far.

---

<div class="post-metadata">

**Author:** ![DallasNChains](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/dallasnchains/32/1608_2.png) [@DallasNChains](https://discuss.dev.twitch.com/u/DallasNChains)\
**Post date:** [March 21, 2017, 8:03pm UTC](https://discuss.dev.twitch.com/t/twitch-player-events-not-firing-the-way-they-used-to-change-in-behavior/9213/16 "2017-03-21T20:03:35Z")

</div>

@argus9 Awesome! Glad the events are updated. I’ve been on vacation for the past week, so I’m just now getting back to this. The autoplay is a known issue that’s being tracked.

---

<div class="post-metadata">

**Author:** ![Argus9](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/argus9/32/1886_2.png) [@Argus9](https://discuss.dev.twitch.com/u/Argus9)\
**Post date:** [March 21, 2017, 9:29pm UTC](https://discuss.dev.twitch.com/t/twitch-player-events-not-firing-the-way-they-used-to-change-in-behavior/9213/17 "2017-03-21T21:29:15Z")

</div>

Hope you had a good time, @DallasNChains. Looking forward to Autoplay getting straightened out.

I can _sort of_ get around the issue by integrating a call to `player.play()` in the ONLINE event listener, though I noticed when doing this that the player will just sit there endlessly buffering. I’ll play around with it a little more and see if I can’t get it to work in the meantime.

Thanks again for your help on investigating this!

---

<div class="post-metadata">

**Author:** ![system](https://d2opxh93rbxzdn.cloudfront.net/original/2X/0/05909729875cce3b53e59d5561c4d23bb14948fc.png) [@system](https://discuss.dev.twitch.com/u/system)\
**Post date:** [April 20, 2017, 9:38pm UTC](https://discuss.dev.twitch.com/t/twitch-player-events-not-firing-the-way-they-used-to-change-in-behavior/9213/18 "2017-04-20T21:38:19Z")

</div>

Closed on April 20, 2017, 9:38pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
