src/sound/sound.js
function() {
            for (var i = 0; i < this.channels.length; i++) {
                var chan = this.channels[i];
                /*
                   * Second test looks for stuff that's out of use,
                   * but fallen foul of Chromium bug 280417
                   */
                if (
                    chan.active === false ||
                    (chan.obj.ended &&
                        chan.repeat <= this.sounds[chan.id].played)
                ) {
                    chan.active = true;
                    return chan;
                }
            }
            // If necessary, create a new element, unless we've already reached the max limit
            if (i < this.maxChannels) {
                var c = {
                    obj: this.audioElement(),
                    active: true,
                    // Checks that the channel is being used to play sound id
                    _is: function(id) {
                        return this.id === id && this.active;
                    }
                };
                this.channels.push(c);
                return c;
            }
            // In that case, return null
            return null;
        }
function() {
            for (var i = 0; i < this.channels.length; i++) {
                var chan = this.channels[i];
                /*
                   * Second test looks for stuff that's out of use,
                   * but fallen foul of Chromium bug 280417
                   */
                if (
                    chan.active === false ||
                    (chan.obj.ended &&
                        chan.repeat <= this.sounds[chan.id].played)
                ) {
                    chan.active = true;
                    return chan;
                }
            }
            // If necessary, create a new element, unless we've already reached the max limit
            if (i < this.maxChannels) {
                var c = {
                    obj: this.audioElement(),
                    active: true,
                    // Checks that the channel is being used to play sound id
                    _is: function(id) {
                        return this.id === id && this.active;
                    }
                };
                this.channels.push(c);
                return c;
            }
            // In that case, return null
            return null;
        }
function ( ) { for ( var i = 0 ; i < this . channels . length ; i ++ ) { var chan = this . channels [ i ] ; /*
                   * Second test looks for stuff that's out of use,
                   * but fallen foul of Chromium bug 280417
                   */ if ( chan . active === false || ( chan . obj . ended && chan . repeat <= this . sounds [ chan . id ] . played ) ) { chan . active = true ; return chan ; } } // If necessary, create a new element, unless we've already reached the max limit if ( i < this . maxChannels ) { var c = { obj : this . audioElement ( ) , active : true , // Checks that the channel is being used to play sound id _is : function ( id ) { return this . id === id && this . active ; } } ; this . channels . push ( c ) ; return c ; } // In that case, return null return null ; }
Finds an unused audio element, marks it as in use, and return it.
Finds an unused audio element marks it as in use and return it .