Changes between Version 2 and Version 3 of Ticket #4692, comment 1


Ignore:
Timestamp:
Jul 2, 2015, 1:14:19 AM (4 years ago)
Author:
ronag
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #4692, comment 1

    v2 v3  
    1 Here is a html page which can be opened in Chrome to test.
     1[https://gist.github.com/ronag/4a63111a968e3c8b3734 Here is a html page which can be opened in Chrome to test.]
     2
     3You need a simple http server to run it. e.g. using [https://nodejs.org nodejs].
    24
    35{{{
    4 <video controls="" autoplay="" width="320" height="240"></video>
    5 <script>
    6 var video = document.querySelector('video');
    7 
    8 video.addEventListener('error', onVideoError);
    9 
    10 window.MediaSource = window.MediaSource || window.WebKitMediaSource;
    11 
    12 var mediaSource = new MediaSource();
    13 
    14 video.src = window.URL.createObjectURL(mediaSource);
    15 
    16 mediaSource.addEventListener('sourceopen', function(){
    17   window.video.pause();
    18   window.mediaSource.mode = 'sequence'
    19   window.sourceBuffer = window.mediaSource.addSourceBuffer('audio/webm; codecs="opus"');
    20 
    21   fileDownload('0.webm', function(ar) {
    22     var appendTime = 0
    23     sourceBuffer.timestampOffset = appendTime - 648/48000;
    24     sourceBuffer.appendWindowEnd = appendTime + 5;
    25     sourceBuffer.appendWindowStart = appendTime;
    26     window.sourceBuffer.appendBuffer(new Uint8Array(ar));
    27 
    28     fileDownload('1.webm', function(ar) {
    29       var appendTime = 5//window.sourceBuffer.buffered.end(0);
    30       sourceBuffer.timestampOffset = appendTime - 648/48000;
    31       sourceBuffer.appendWindowEnd = appendTime + 5;
    32       sourceBuffer.appendWindowStart = appendTime;
    33       window.sourceBuffer.appendBuffer(new Uint8Array(ar));
    34 
    35       fileDownload('2.webm', function(ar) {
    36         var appendTime = 10//window.sourceBuffer.buffered.end(0);
    37         sourceBuffer.timestampOffset = appendTime - 648/48000;
    38         sourceBuffer.appendWindowEnd = appendTime + 5;
    39         sourceBuffer.appendWindowStart = appendTime;
    40         window.sourceBuffer.appendBuffer(new Uint8Array(ar));
    41         window.video.play();
    42       });
    43     });
    44   });
    45 });
    46 
    47 function onVideoError() {
    48   var error = video.error
    49   switch (error.code) {
    50     case error.MEDIA_ERR_DECODE:
    51       console.error(`[MediaLoader] Error: Failed to decode media.`)
    52       break
    53     case error.MEDIA_ERR_SRC_NOT_SUPPORTED:
    54       console.error(`[MediaLoader] Error: Source is not supported.`)
    55       break
    56     case error.MEDIA_ERR_NETWORK:
    57       console.error(`[MediaLoader] Error: Network error.`)
    58       break
    59     case error.MEDIA_ERR_ABORTED:
    60       console.error(`[MediaLoader] Error: Aborted.`)
    61       break
    62   }
    63 }
    64 
    65 function fileDownload(url, cb) {
    66   var xhr = new XMLHttpRequest();
    67   xhr.open('GET', url, true);
    68   xhr.responseType = 'arraybuffer';
    69   xhr.send();
    70   xhr.onload = function(e) {
    71     cb(xhr.response);
    72   };
    73 };
    74 </script>
     6 << ls
     7 >> index.html 0.webm 1.webm 2.webm
     8 << npm install -g http-server
     9 << http-server --cors
     10}}}