OLD | NEW |
---|---|
1 var consoleDiv = null; | 1 var consoleDiv = null; |
2 | 2 |
3 function consoleWrite(text) | 3 function consoleWrite(text) |
4 { | 4 { |
5 if (!consoleDiv && document.body) { | 5 if (!consoleDiv && document.body) { |
6 consoleDiv = document.createElement('div'); | 6 consoleDiv = document.createElement('div'); |
7 document.body.appendChild(consoleDiv); | 7 document.body.appendChild(consoleDiv); |
8 } | 8 } |
9 var span = document.createElement('span'); | 9 var span = document.createElement('span'); |
10 span.appendChild(document.createTextNode(text)); | 10 span.appendChild(document.createTextNode(text)); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
64 var keyId = new Uint8Array([ | 64 var keyId = new Uint8Array([ |
65 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | 65 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
66 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F | 66 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F |
67 ]); | 67 ]); |
68 return stringToUint8Array(createKeyIDs(keyId)); | 68 return stringToUint8Array(createKeyIDs(keyId)); |
69 } | 69 } |
70 | 70 |
71 throw 'initDataType ' + initDataType + ' not supported.'; | 71 throw 'initDataType ' + initDataType + ' not supported.'; |
72 } | 72 } |
73 | 73 |
74 // Returns a MediaKeySystemConfiguration for |initDataType|. Since Chromium | |
75 // only supports WebM by default, use an audio codec so that at least one | |
76 // capability is specified. | |
77 function simpleConfigurationForInitDataType(initDataType) | |
ddorwin
2016/06/23 22:52:38
// NOTE: Supporting user agents that don't support
jrummell
2016/06/24 00:12:29
Done.
| |
78 { | |
79 return [ { | |
80 initDataTypes: [ initDataType ], | |
81 audioCapabilities: [ { contentType: 'audio/webm; codecs="vorbis"' } ] | |
82 } ]; | |
83 } | |
84 | |
85 // Returns a MediaKeySystemConfiguration for 'webm' that specifies | |
86 // both audio and video capabilities. | |
87 function webmConfiguration() | |
ddorwin
2016/06/23 22:52:38
Just FTR, this would be avConfiguration, with type
jrummell
2016/06/24 00:12:29
Done this now.
| |
88 { | |
89 return [ { | |
90 initDataTypes: [ 'webm' ], | |
91 audioCapabilities: [ { contentType: 'audio/webm; codecs="vorbis"' } ], | |
92 videoCapabilities: [ { contentType: 'video/webm; codecs="vp8"' } ] | |
93 } ]; | |
94 } | |
95 | |
74 function waitForEventAndRunStep(eventName, element, func, stepTest) | 96 function waitForEventAndRunStep(eventName, element, func, stepTest) |
75 { | 97 { |
76 var eventCallback = function(event) { | 98 var eventCallback = function(event) { |
77 if (func) | 99 if (func) |
78 func(event); | 100 func(event); |
79 } | 101 } |
80 if (stepTest) | 102 if (stepTest) |
81 eventCallback = stepTest.step_func(eventCallback); | 103 eventCallback = stepTest.step_func(eventCallback); |
82 | 104 |
83 element.addEventListener(eventName, eventCallback, true); | 105 element.addEventListener(eventName, eventCallback, true); |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
261 // Create a MediaKeys object for Clear Key with 1 session. KeyId and key | 283 // Create a MediaKeys object for Clear Key with 1 session. KeyId and key |
262 // required for the video are already known and provided. Returns a promise | 284 // required for the video are already known and provided. Returns a promise |
263 // that resolves to the MediaKeys object created. | 285 // that resolves to the MediaKeys object created. |
264 function createMediaKeys(keyId, key) | 286 function createMediaKeys(keyId, key) |
265 { | 287 { |
266 var mediaKeys; | 288 var mediaKeys; |
267 var mediaKeySession; | 289 var mediaKeySession; |
268 var request = stringToUint8Array(createKeyIDs(keyId)); | 290 var request = stringToUint8Array(createKeyIDs(keyId)); |
269 var jwkSet = stringToUint8Array(createJWKSet(createJWK(keyId, key))); | 291 var jwkSet = stringToUint8Array(createJWKSet(createJWK(keyId, key))); |
270 | 292 |
271 return navigator.requestMediaKeySystemAccess('org.w3.clearkey', [{}]).then(f unction(access) { | 293 return navigator.requestMediaKeySystemAccess('org.w3.clearkey', simpleConfig urationForInitDataType('keyids')).then(function(access) { |
272 return access.createMediaKeys(); | 294 return access.createMediaKeys(); |
273 }).then(function(result) { | 295 }).then(function(result) { |
274 mediaKeys = result; | 296 mediaKeys = result; |
275 mediaKeySession = mediaKeys.createSession(); | 297 mediaKeySession = mediaKeys.createSession(); |
276 return mediaKeySession.generateRequest('keyids', request); | 298 return mediaKeySession.generateRequest('keyids', request); |
277 }).then(function() { | 299 }).then(function() { |
278 return mediaKeySession.update(jwkSet); | 300 return mediaKeySession.update(jwkSet); |
279 }).then(function() { | 301 }).then(function() { |
280 return Promise.resolve(mediaKeys); | 302 return Promise.resolve(mediaKeys); |
281 }); | 303 }); |
282 } | 304 } |
283 | 305 |
284 // Play the specified |content| on |video|. Returns a promise that is resolved | 306 // Play the specified |content| on |video|. Returns a promise that is resolved |
285 // after the video plays for |duration| seconds. | 307 // after the video plays for |duration| seconds. |
286 function playVideoAndWaitForTimeupdate(video, content, duration) | 308 function playVideoAndWaitForTimeupdate(video, content, duration) |
287 { | 309 { |
288 video.src = content; | 310 video.src = content; |
289 video.play(); | 311 video.play(); |
290 return new Promise(function(resolve) { | 312 return new Promise(function(resolve) { |
291 video.addEventListener('timeupdate', function listener(event) { | 313 video.addEventListener('timeupdate', function listener(event) { |
292 if (event.target.currentTime < duration) | 314 if (event.target.currentTime < duration) |
293 return; | 315 return; |
294 video.removeEventListener('timeupdate', listener); | 316 video.removeEventListener('timeupdate', listener); |
295 resolve('success'); | 317 resolve('success'); |
296 }); | 318 }); |
297 }); | 319 }); |
298 } | 320 } |
OLD | NEW |