OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This file performs actions on media elements. | 5 // This file performs actions on media elements. |
6 (function() { | 6 (function() { |
7 function playMedia(selector) { | 7 function playMedia(selector) { |
8 // Performs the "Play" action on media satisfying selector. | 8 // Performs the "Play" action on media satisfying selector. |
9 var mediaElements = window.__findMediaElements(selector); | 9 var mediaElements = window.__findMediaElements(selector); |
10 for (var i = 0; i < mediaElements.length; i++) { | 10 for (var i = 0; i < mediaElements.length; i++) { |
11 console.log('Playing element: ' + mediaElements[i].src); | 11 console.log('Playing element: ' + mediaElements[i].src); |
12 play(mediaElements[i]); | 12 play(mediaElements[i]); |
13 } | 13 } |
14 } | 14 } |
15 | 15 |
16 function play(element) { | 16 function play(element) { |
17 if (element instanceof HTMLMediaElement) | 17 if (element instanceof HTMLMediaElement) |
18 playHTML5Element(element); | 18 playHTML5Element(element); |
19 else | 19 else |
20 throw new Error('Can not play non HTML5 media elements.'); | 20 throw new Error('Can not play non HTML5 media elements.'); |
21 } | 21 } |
22 | 22 |
23 function playHTML5Element(element) { | 23 function playHTML5Element(element) { |
24 window.__registerHTML5ErrorEvents(element); | 24 window.__registerHTML5ErrorEvents(element); |
25 window.__registerHTML5EventCompleted(element, 'playing'); | 25 window.__registerHTML5EventCompleted(element, 'playing'); |
26 window.__registerHTML5EventCompleted(element, 'ended'); | 26 window.__registerHTML5EventCompleted(element, 'ended'); |
| 27 element.addEventListener('durationchange', function(e) { |
| 28 performance.mark('duration-' + element.duration); |
| 29 }); |
27 | 30 |
28 var willPlayEvent = document.createEvent('Event'); | 31 var willPlayEvent = document.createEvent('Event'); |
29 willPlayEvent.initEvent('willPlay', false, false); | 32 willPlayEvent.initEvent('willPlay', false, false); |
30 element.dispatchEvent(willPlayEvent); | 33 element.dispatchEvent(willPlayEvent); |
31 element.play(); | 34 element.play(); |
32 } | 35 } |
33 | 36 |
34 window.__playMedia = playMedia; | 37 window.__playMedia = playMedia; |
35 })(); | 38 })(); |
OLD | NEW |