Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(311)

Side by Side Diff: telemetry/telemetry/internal/actions/play.js

Issue 3002623002: [WIP] Port media metrics to TBMv2 (Closed)
Patch Set: Change console.time to performance.mark Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | telemetry/telemetry/internal/actions/seek.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 })();
OLDNEW
« no previous file with comments | « no previous file | telemetry/telemetry/internal/actions/seek.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698