[whatwg] <video> resource selection algorithm and NETWORK_NO_SOURCE

On Tue, 27 Jul 2010 00:01:26 +0200, Silvia Pfeiffer  
<silviapfeiffer1 at gmail.com> wrote:

> On Tue, Jul 27, 2010 at 1:37 AM, Philip J?genstedt  
> <philipj at opera.com>wrote:
>
>> On Mon, 26 Jul 2010 16:53:43 +0200, Silvia Pfeiffer <
>> silviapfeiffer1 at gmail.com> wrote:
>>
>>  On Mon, Jul 26, 2010 at 11:25 PM, Philip J?genstedt <philipj at opera.com
>>> >wrote:
>>>
>>>    <video controls width="400px">
>>>>   </video>
>>>>   <script type="text/javascript">
>>>>     var video = document.querySelector("video");
>>>>     var exts = ["mp4", "webm", "ogv"];
>>>>     exts.forEach(function(ext) {
>>>>       var source = document.createElement("source");
>>>>       source.src = "HelloWorld."+ext;
>>>>       source.type = "video/"+ext;
>>>>       video.appendChild(source);
>>>>     });
>>>>     video.play();
>>>>   </script>
>>>>
>>>>
>>>
>>> Does this actually work in Opera now?
>>>
>>
>> Yes, when I have a HelloWorld.webm file available it starts playing. It
>> also works in Firefox 4b1 and it should work in Chrome and Safari too  
>> unless
>> they are buggy.
>
>
>
> Right, so it works if you create the <source> elements newly, but it  
> still
> doesn't work when you have previously created the <source> element just  
> with
> an empty @src attribute (which I think is legal). Both of these work in  
> all
> the other browsers, btw.

Yes, but it shouldn't work, and will stop working as soon as they  
implement the new resource selection algorithm. It is very important that  
authors don't depend on this bug, so I hope you'll change any code where  
you have accidentally done so.

> Right, I realize there are actually situations where it isn't a pointless
>> exercise as in the above. If you're already using scripts, though, you  
>> could
>> actually call canPlayType yourself and use the first one that works:
>>
>>      exts.forEach(function(ext) {
>>        if (video.canPlayType("video/"+ext)) {
>>          video.src = "movie_300."+ext;
>>          return false;
>>        }
>>      });
>
>
>> I expect this will be interoperable right now and it's easier to  
>> understand
>> exactly what's going on.
>>
>
>
> Yes, it is and works in all browsers. But I still see it as a bug if  
> you're
> not allowed to change the @src on the <source> elements and get the video
> reloaded. Why would @src on <source> elements be mutable in the first  
> place
> then?

All attributes are mutable via setAttribute. The reason that src, type and  
media are also reflected as properties on HTMLSourceElement is so that  
it's easier to write code like this:

var v = document.querySelector('video');
var s = document.createElement('source');
s.src = 'foo.webm';
s.type = 'video/webm';
v.appendChild(s);

>> Looking again at the resource selection algorithm, the second step is to
>> await a stable state, i.e. wait until the current script has finished.  
>> Given
>> that, it wouldn't be a big problem to let modification of src  
>> attributes on
>> source elements trigger resource selection, you won't get the 3-2-1  
>> problem
>> I mentioned earlier. However, then I would argue that modifying type and
>> media should also have the same effect, as those affect the outcome of
>> resource selection. In the end, my suggestion is still no spec change,
>> except for editorial changes to clarify.
>
>
> No matter what we call it, there is currently no mention of @src change  
> (and
> indeed @type and @media change) on <source> to cause resource selection  
> and
> this has caused diverging implementations in browsers. A clarification is
> certainly necessary.

Right, clarification of that would be helpful, not least for authors. This  
isn't the actual reason for the current incompatible behavior though, the  
reason is that only Opera uses the NETWORK_NO_SOURCE state as per the spec.

-- 
Philip J?genstedt
Core Developer
Opera Software

Received on Tuesday, 27 July 2010 01:17:33 UTC