test_TruncatedDuration_mp4.html (2228B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title>MSE: truncating the media seeks to end of media and update buffered range</title> 5 <script src="/tests/SimpleTest/SimpleTest.js"></script> 6 <script type="text/javascript" src="mediasource.js"></script> 7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 8 </head> 9 <body> 10 <pre id="test"> 11 <script class="testbody" type="text/javascript"> 12 13 // This test append data to a mediasource and then seek to half the duration 14 // of the video. 15 // We then shorten the video to 1/3rd of its original size. 16 // We ensure that the buffered range immediately reflect the truncation 17 // and that we've seeked to the new end of the media as per W3C spec and 18 // video.currentTime got updated. 19 20 SimpleTest.waitForExplicitFinish(); 21 22 const round = n => Math.round(n * 1000) / 1000; 23 24 runWithMSE(async (ms, v) => { 25 await once(ms, "sourceopen"); 26 const sb = ms.addSourceBuffer("video/mp4"); 27 28 sb.appendBuffer(new Uint8Array(await fetchWithXHR("bipbop/bipbop2s.mp4"))); 29 await once(sb, "updateend"); 30 // mp4 metadata states 10s when we only have 1.6s worth of video. 31 sb.remove(sb.buffered.end(0), Infinity); 32 await once(sb, "updateend"); 33 ms.duration = sb.buffered.end(0); 34 is(v.duration, ms.duration, "current time updated with mediasource duration"); 35 v.currentTime = v.duration / 2; 36 is(v.currentTime, v.duration / 2, "current time was updated"); 37 ok(v.seeking, "seeking is true"); 38 await once(v, "seeked"); 39 const duration = round(v.duration / 3); 40 is(sb.updating, false, "sourcebuffer isn't updating"); 41 sb.remove(duration, Infinity); 42 await once(sb, "updateend"); 43 ms.duration = duration; 44 // frames aren't truncated, so duration may be slightly more. 45 isfuzzy(v.duration, duration, 1 / 30, "element duration was updated"); 46 sb.abort(); // this shouldn't abort updating the duration (bug 1130826). 47 ok(v.seeking, "seeking is true"); 48 // test playback position was updated (bug 1130839). 49 is(v.currentTime, v.duration, "current time was updated"); 50 is(sb.buffered.length, 1, "One buffered range"); 51 // Truncated mediasource duration will cause the video element to seek. 52 await once(v, "seeking"); 53 SimpleTest.finish(); 54 }); 55 56 </script> 57 </pre> 58 </body> 59 </html>