Sunday, November 6, 2016

Re: Bug in Audio addEndedHandler



On Sunday, November 6, 2016 at 6:10:08 AM UTC+1, Craig Mitchell wrote:
If you want to listen for the end of an audio track, calling MediaBase.addEndedHandler won't work, as it is using BrowserEvents.ENDED which is set to "ended".

The correct event is actually "onended". Ref:  http://www.w3schools.com/tags/av_event_ended.asp

Wrong.
The event name is "ended", the "event handler" name is "onended" (see https://html.spec.whatwg.org/multipage/webappapis.html#events)
You use the event name with addEventListener, and the event handler name for the event handler attribute.

You'll note that even W3Schools talks about the "ended event" too.
 
So, here is a little JSNI function to do it:

public static native final void listenForEnd(AudioElement aud, Command onComplete) /*-{
   aud.onended = function() {
      onComplete.@com.google.gwt.user.client.Command::execute(*)();
   };
}-*/
;

Hope that helps someone.

In which browser is this not working?

Because addEndedHandler works for me in Chrome and Firefox with the following code:

Audio audio = Audio.createIfSupported();
audio.setControls(true);
audio.setAutoplay(true);
audio.setSrc("http://www.html5tutorial.info/media/vincent.mp3");
audio.addEndedHandler(e -> Window.alert("Ended"));
RootPanel.get().add(audio);
 

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment