Re: [ACTION-59] Introduce lookup by id structures for streams and tracks.

On 15 November 2012 02:47, Adam Bergkvist <adam.bergkvist@ericsson.com> wrote:
> I'd like to add a third:
> 3) Get the only track of a certain kind (if any) from a stream created by
> getUserMedia().
>
> The forEach() approach has gotten some support, but I think it's a bit
> clumsy doing 3) from the list of common uses.
>
> var theTrack;
> stream.audioTracks.forEach(function (track) {
>     theTrack = track;
> });

That would not be ideal; it selects the last audio track by iterating
over the whole collection.

We have better tools available:

MediaStream.prototype.getAudioTracks = function() {
    return this.getTracks().filter(function(track) {
        return track.type === 'audio';
    });
};

Whether that is provided by the browser, or needs to be polyfilled, I
don't care.  getTracks() is the key interface.

How important is it for application developers to be able to mess with
the contents of their MediaStreams anyway?

Received on Thursday, 15 November 2012 21:02:14 UTC