google closure compiler && audio event

226 views Asked by At

i have folowing code: (without compilation everything work fine)

var audio = new Audio("audio.ogg");
goog.events.listen(audio, 'timeupdate', function(e){

ERROR

actual parameter 1 of goog.events.listen does not match formal parameter
>> found   : Audio
>> required: (EventTarget|goog.events.Listenable|null)
>> goog.events.listen(this.audio.singing, 'timeupdate', function(e){

my Extern

/**
 * @param {string=} src
 * @constructor
 */
var Audio = function(src) {};
Audio.prototype.play = function() {};

How can i compile with internal event like this? Thank you

2

There are 2 answers

0
ellisbben On

You should certainly try augmenting your extern definition:

goog.require('goog.events.EventTarget');
/**
 * @param {string=} src
 * @constructor
 * @extends {EventTarget}
 */
var Audio = function(src) {};
Audio.prototype.play = function() {};

Edit:

So it turns out that your problem had been addressed in the Closure Compiler codebase and then that fix was reverted. See the changelog here.

The relevant part of that commit I reproduce below:

/**
* @param {string=} src address of the media resource (a URL)
* @constructor
* @extends {HTMLAudioElement}
* @see http://www.w3.org/html/wg/drafts/html/master/embedded-content-0.html#the-audio-element
*/
var Audio = function(src) {};
0
Pawel On

Closure compiler provides externs which should be added to externs list

https://github.com/google/closure-compiler/wiki/Externs-For-Common-Libraries

The one with Audio API is called html5 or something like that