| OLD | NEW |
| 1 <html> | 1 <html> |
| 2 <head> | 2 <head> |
| 3 <title>Test media source config changes.</title> | 3 <title>Test media source config changes.</title> |
| 4 </head> | 4 </head> |
| 5 <body onload="runTest();"> | 5 <body onload="runTest();"> |
| 6 <video controls></video> | 6 <video controls></video> |
| 7 <script src='eme_player_js/app_loader.js' type='text/javascript'></script> | 7 <script src='eme_player_js/app_loader.js' type='text/javascript'></script> |
| 8 <script type="text/javascript"> | 8 <script type="text/javascript"> |
| 9 var testConfig; | 9 var testConfig; |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 var MEDIA_2_LENGTH = 2.75; | 24 var MEDIA_2_LENGTH = 2.75; |
| 25 | 25 |
| 26 // The time in secs to append the second media source. | 26 // The time in secs to append the second media source. |
| 27 var APPEND_TIME = 1; | 27 var APPEND_TIME = 1; |
| 28 // DELTA is the time after APPEND_TIME where the second video dimensions | 28 // DELTA is the time after APPEND_TIME where the second video dimensions |
| 29 // are guaranteed to take effect. | 29 // are guaranteed to take effect. |
| 30 var DELTA = 0.1; | 30 var DELTA = 0.1; |
| 31 // Append MEDIA_2 source at APPEND_TIME, so expected total duration is: | 31 // Append MEDIA_2 source at APPEND_TIME, so expected total duration is: |
| 32 var TOTAL_DURATION = APPEND_TIME + MEDIA_2_LENGTH; | 32 var TOTAL_DURATION = APPEND_TIME + MEDIA_2_LENGTH; |
| 33 | 33 |
| 34 var firstFile; |
| 35 var secondFile; |
| 36 |
| 34 function initTestConfig() { | 37 function initTestConfig() { |
| 35 testConfig = new TestConfig(); | 38 testConfig = new TestConfig(); |
| 36 testConfig.loadQueryParams(); | 39 testConfig.loadQueryParams(); |
| 37 } | 40 } |
| 38 | 41 |
| 42 function setMediaFiles() { |
| 43 switch (testConfig.configChangeType) { |
| 44 case CONFIG_CHANGE_TYPE.CLEAR_TO_CLEAR: |
| 45 console.log('Config change type: clear to clear.'); |
| 46 firstFile = CLEAR_MEDIA_1; |
| 47 secondFile = CLEAR_MEDIA_2; |
| 48 break; |
| 49 case CONFIG_CHANGE_TYPE.CLEAR_TO_ENCRYPTED: |
| 50 console.log('Config change type: clear to encrypted.'); |
| 51 firstFile = CLEAR_MEDIA_1; |
| 52 secondFile = ENCRYPTED_MEDIA_2; |
| 53 break; |
| 54 case CONFIG_CHANGE_TYPE.ENCRYPTED_TO_CLEAR: |
| 55 console.log('Config change type: encrypted to clear.'); |
| 56 firstFile = ENCRYPTED_MEDIA_1; |
| 57 secondFile = CLEAR_MEDIA_2; |
| 58 break; |
| 59 case CONFIG_CHANGE_TYPE.ENCRYPTED_TO_ENCRYPTED: |
| 60 console.log('Config change type: encrypted to encrypted.'); |
| 61 firstFile = ENCRYPTED_MEDIA_1; |
| 62 secondFile = ENCRYPTED_MEDIA_2; |
| 63 break; |
| 64 } |
| 65 } |
| 66 |
| 39 function appendNextSource(mediaSource) { | 67 function appendNextSource(mediaSource) { |
| 40 console.log('Appending next media source at ' + APPEND_TIME + 'sec.'); | 68 console.log('Appending next media source at ' + APPEND_TIME + 'sec.'); |
| 41 var xhr = new XMLHttpRequest(); | 69 var xhr = new XMLHttpRequest(); |
| 42 var mediaFile = | 70 xhr.open("GET", secondFile); |
| 43 (testConfig.runEncrypted == 1) ? ENCRYPTED_MEDIA_2 : CLEAR_MEDIA_2; | |
| 44 xhr.open("GET", mediaFile); | |
| 45 xhr.responseType = 'arraybuffer'; | 71 xhr.responseType = 'arraybuffer'; |
| 46 xhr.addEventListener('load', function(e) { | 72 xhr.addEventListener('load', function(e) { |
| 47 var onUpdateEnd = function(e) { | 73 var onUpdateEnd = function(e) { |
| 48 console.log('Second buffer append ended.'); | 74 console.log('Second buffer append ended.'); |
| 49 srcBuffer.removeEventListener('updateend', onUpdateEnd); | 75 srcBuffer.removeEventListener('updateend', onUpdateEnd); |
| 50 mediaSource.endOfStream(); | 76 mediaSource.endOfStream(); |
| 51 if (!mediaSource.duration || | 77 if (!mediaSource.duration || |
| 52 Math.abs(mediaSource.duration - TOTAL_DURATION) > DELTA) { | 78 Math.abs(mediaSource.duration - TOTAL_DURATION) > DELTA) { |
| 53 Utils.failTest('Unexpected mediaSource.duration = ' + | 79 Utils.failTest('Unexpected mediaSource.duration = ' + |
| 54 mediaSource.duration + ', expected duration = ' + | 80 mediaSource.duration + ', expected duration = ' + |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 } | 140 } |
| 115 | 141 |
| 116 function logVideoDimensions() { | 142 function logVideoDimensions() { |
| 117 console.log('video.currentTime = ' + video.currentTime + | 143 console.log('video.currentTime = ' + video.currentTime + |
| 118 ', video dimensions = ' + video.videoWidth + 'x' + | 144 ', video dimensions = ' + video.videoWidth + 'x' + |
| 119 video.videoHeight + '.'); | 145 video.videoHeight + '.'); |
| 120 } | 146 } |
| 121 | 147 |
| 122 function runTest() { | 148 function runTest() { |
| 123 initTestConfig(); | 149 initTestConfig(); |
| 124 testConfig.mediaFile = | 150 setMediaFiles(); |
| 125 (testConfig.runEncrypted == 1) ? ENCRYPTED_MEDIA_1 : CLEAR_MEDIA_1; | 151 testConfig.mediaFile = firstFile; |
| 126 testConfig.mediaType = mediaType; | 152 testConfig.mediaType = mediaType; |
| 127 video.addEventListener('timeupdate', onTimeUpdate); | 153 video.addEventListener('timeupdate', onTimeUpdate); |
| 128 video.addEventListener('ended', Utils.failTest); | 154 video.addEventListener('ended', Utils.failTest); |
| 129 var mediaSource = MediaSourceUtils.loadMediaSourceFromTestConfig( | 155 var mediaSource = MediaSourceUtils.loadMediaSourceFromTestConfig( |
| 130 testConfig, appendNextSource); | 156 testConfig, appendNextSource); |
| 131 if (testConfig.runEncrypted == 1) { | 157 if (testConfig.configChangeType != CONFIG_CHANGE_TYPE.CLEAR_TO_CLEAR) { |
| 132 var emePlayer = PlayerUtils.createPlayer(video, testConfig); | 158 var emePlayer = PlayerUtils.createPlayer(video, testConfig); |
| 133 emePlayer.registerEventListeners() | 159 emePlayer.registerEventListeners() |
| 134 .then(function(player) { | 160 .then(function(player) { |
| 135 video.src = window.URL.createObjectURL(mediaSource); | 161 video.src = window.URL.createObjectURL(mediaSource); |
| 136 }) | 162 }) |
| 137 .catch(function(error) { | 163 .catch(function(error) { |
| 138 Utils.failTest('Unable to register event listeners.'); | 164 Utils.failTest('Unable to register event listeners.'); |
| 139 }); | 165 }); |
| 140 } else { | 166 } else { |
| 141 video.src = window.URL.createObjectURL(mediaSource); | 167 video.src = window.URL.createObjectURL(mediaSource); |
| 142 } | 168 } |
| 143 } | 169 } |
| 144 </script> | 170 </script> |
| 145 </body> | 171 </body> |
| 146 </html> | 172 </html> |
| OLD | NEW |