OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 cr.define('media', function() { | |
6 | |
7 /** | |
8 * This class stores information about an open media player. | |
9 */ | |
10 function MediaPlayer(source, renderer) { | |
11 this.properties = {}; | |
12 this.renderer = renderer; | |
13 this.source = source; | |
14 | |
15 this.events_ = new media.EventList; | |
16 this.li_ = media.createDetailsLi(); | |
17 this.metrics_ = new media.Metrics; | |
18 this.propertyTable_ = document.createElement('table'); | |
19 | |
20 this.li_.id = source; | |
21 this.li_.details.open = true; | |
22 var properties = media.createDetailsLi(); | |
23 properties.summary.textContent = 'Properties:'; | |
24 properties.details.appendChild(this.propertyTable_); | |
25 | |
26 var ul = document.createElement('ul'); | |
27 ul.appendChild(properties); | |
28 ul.appendChild(this.metrics_.li); | |
29 ul.appendChild(this.events_.li); | |
30 this.li_.details.appendChild(ul); | |
31 }; | |
32 | |
33 MediaPlayer.prototype = { | |
34 /** | |
35 * Record an event and update statistics etc. | |
36 * @param {Object} event The event that occurred. | |
37 */ | |
38 addEvent: function(event) { | |
39 for (key in event.params) | |
arv (Not doing code reviews)
2011/08/16 19:29:03
missing var. Use strict mode?
arv (Not doing code reviews)
2011/08/16 19:29:03
Missing {
Scott Franklin
2011/08/16 23:33:52
Done.
Scott Franklin
2011/08/16 23:33:52
Didn't realize those were necessary one single-lin
| |
40 this.properties[key] = event.params[key]; | |
41 | |
42 if (event.type == 'BUFFERED_EXTENTS_CHANGED') | |
43 return; | |
44 this.events_.addEvent(event); | |
45 this.metrics_.addEvent(event); | |
46 }, | |
47 | |
48 /** | |
49 * Render this MediaPlayer as a <li>. | |
arv (Not doing code reviews)
2011/08/16 19:29:03
Why don't you just make MediaPlayer a sub class of
Scott Franklin
2011/08/16 23:33:52
Because I didn't realize such a thing was possible
| |
50 * Updates this summary line and redraws the canvas. | |
51 * @return {HTMLElement} A <li> representing this MediaPlayer. | |
52 */ | |
53 toListItem: function() { | |
54 media.printDictionaryToTable(this.properties, this.propertyTable_); | |
55 | |
56 this.li_.setAttribute('status', this.properties.state); | |
57 this.li_.summary.textContent = ''; | |
58 this.li_.summary.appendChild(document.createTextNode( | |
59 this.source + ' (' + media.clipURL(this.properties.url) + '):')); | |
60 this.li_.summary.appendChild(document.createElement('br')); | |
61 | |
62 // Draw the state of BufferedResourceLoader. | |
63 var canvas = document.createElement('canvas'); | |
64 canvas.width = media.BAR_WIDTH; | |
65 canvas.height = 3 * media.BAR_HEIGHT + 2; | |
66 canvas.className = 'buffer-canvas'; | |
67 this.li_.summary.appendChild(canvas); | |
68 | |
69 var context = canvas.getContext('2d'); | |
70 context.textAlign = 'center'; | |
71 context.textBaseline = 'middle'; | |
72 context.fillStyle = '#aaa'; | |
73 context.fillRect(0, 0, canvas.width, canvas.height); | |
74 | |
75 var size = this.properties.total_bytes; | |
76 if (!size) { | |
77 context.fillStyle = '#fff'; | |
78 context.fillText('Unknown file size.', canvas.width / 2, | |
79 canvas.height / 2); | |
80 return this.li_; | |
81 } | |
82 | |
83 var left = this.properties.buffer_start / size * canvas.width; | |
84 var middle = this.properties.buffer_current / size * canvas.width; | |
85 var right = this.properties.buffer_end / size * canvas.width; | |
86 context.fillStyle = '#a0a'; | |
87 context.fillRect(left, 0, middle - left, media.BAR_HEIGHT); | |
88 context.fillStyle = '#aa0'; | |
89 context.fillRect(middle, 0, right - middle, media.BAR_HEIGHT); | |
90 | |
91 media.drawLine(context, media.BAR_HEIGHT + 0.5); | |
92 | |
93 context.fillStyle = '#fff'; | |
94 context.fillText('Buffered by player.', canvas.width / 2, | |
95 media.BAR_HEIGHT / 2); | |
96 | |
97 if (!media.cacheEntriesByKey[this.properties.url]) { | |
98 context.fillText('No cache entry for this file.', canvas.width / 2, | |
99 2 * canvas.height / 3); | |
100 } else { | |
101 var cached = media.cacheEntriesByKey[this.properties.url].canvas; | |
102 var data = cached.getContext('2d').getImageData(0, 0, cached.width, | |
103 cached.height); | |
104 context.putImageData(data, 0, media.BAR_HEIGHT + 1); | |
105 } | |
106 | |
107 return this.li_; | |
108 }, | |
109 }; | |
110 | |
111 return { | |
112 MediaPlayer: MediaPlayer, | |
113 }; | |
114 }); | |
OLD | NEW |