4 <title>Clear Key Play Two Videos At Same Time
</title>
5 <script src=
"encrypted-media-utils.js"></script>
6 <script src=
"../../resources/testharness.js"></script>
7 <script src=
"../../resources/testharnessreport.js"></script>
10 <video id=
"testVideo"></video>
11 <video id=
"secondVideo"></video>
14 // As this code doesn't wait for the 'message' event to simplify
15 // the code, specify the key ID and key used by the encrypted
17 var keyId
= stringToUint8Array('0123456789012345');
18 var rawKey
= new Uint8Array([0xeb, 0xdd, 0x62, 0xf1, 0x68, 0x14, 0xd2, 0x7b,
19 0x68, 0xef, 0x12, 0x2a, 0xfc, 0xe4, 0xae, 0x3c]);
21 promise_test(function(test
)
24 play_video_as_promise(document
.getElementById('testVideo'), '../content/test-encrypted.webm'),
25 play_video_as_promise(document
.getElementById('secondVideo'), '../content/test-encrypted.webm')
27 return Promise
.all(promises
);
28 }, 'Play two videos at the same time.');
30 function play_video_as_promise(video
, content
)
32 return navigator
.requestMediaKeySystemAccess('org.w3.clearkey', [{}]).then(function(access
) {
33 return access
.createMediaKeys();
34 }).then(function(mediaKeys
) {
35 return video
.setMediaKeys(mediaKeys
);
36 }).then(function(result
) {
39 return wait_for_encrypted_message(video
);
40 }).then(function(result
) {
41 return wait_for_timeupdate_message(video
);
45 function wait_for_encrypted_message(video
)
47 var encryptedEventCount
= 0;
48 return new Promise(function(resolve
) {
49 video
.addEventListener('encrypted', function listener(e
) {
50 // The same decryption key is used by both the audio
51 // and the video streams so only create a session once.
52 // Create the session on the second event. This also
53 // ensures we see both events.
54 if (++encryptedEventCount
!= 2)
56 video
.removeEventListener(listener
);
58 var mediaKeySession
= video
.mediaKeys
.createSession();
59 mediaKeySession
.generateRequest(e
.initDataType
, e
.initData
).then(function(result
) {
60 // Don't bother waiting for the 'message' event.
61 // Just call update() since we know the keyId
63 var jwkSet
= stringToUint8Array(createJWKSet(createJWK(keyId
, rawKey
)));
64 return mediaKeySession
.update(jwkSet
);
65 }).then(function(result
) {
72 function wait_for_timeupdate_message(video
)
74 return new Promise(function(resolve
) {
75 video
.addEventListener('timeupdate', function listener(e
) {
76 if (e
.target
.currentTime
< 0.2)
78 video
.removeEventListener(listener
);