@Override public boolean play() { AudioElement elem = audio.getAudioElement(); elem.pause(); try { // IE9 has been seen to throw an exception here elem.setCurrentTime(0); } catch (Exception ignore) { } if (elem.getCurrentTime() != 0) { /* * Workaround Chrome's inability to play the same audio twice: * http://code.google.com/p/chromium/issues/detail?id=71323 * http://code.google.com/p/chromium/issues/detail?id=75725 */ createAudioElement(); } elem.play(); // best guess is that the sound played, so return true return true; }
private void createAudioElement() { if (endedRegistration != null) { endedRegistration.removeHandler(); } if (audio != null) { // TODO: remove, once DOM attachment no longer required to sink (bitless) events audio.removeFromParent(); } assert Audio.isSupported(); audio = Audio.createIfSupported(); assert audio != null; AudioElement elem = audio.getAudioElement(); assert elem != null; endedRegistration = audio.addEndedHandler(endedHandler); // TODO: remove, once DOM attachment no longer required to sink (bitless) events RootPanel.get().add(audio); if (isCrossOrigin()) { elem.setAttribute("crossOrigin", "anonymous"); } elem.setSrc(getUrl()); }