hermancain
hermancain

Reputation: 1622

How can I use the React media synthetic event listener on an audio element?

facebook/React lists the "Media Events" on this page:

https://facebook.github.io/react/docs/events.html

I am trying to execute a function on pause/play and this is what I'm trying:

      <audio                     
        id="globalAudio"         
        onPlay={this._onPlay}    
        onPause={this._onPause}> 
      </audio>         

But my functions aren't firing. I'm aware I can just add an event listener like:

let ga = document.getElementById("globalAudio");        
ga.addEventListener("play", this._onPlay);               
ga.addEventListener("pause", this._onPause);             

But I'm wondering how exactly to use the syntheticEvent that they talk about in the above link, or if there is some other convention that is followed by react for listening to events like these.

Upvotes: 1

Views: 766

Answers (1)

hermancain
hermancain

Reputation: 1622

I needed to upgrade react. I was still using the version they had listed in the todo list tutorial.

Upvotes: 1

Related Questions