0

I have read this article, but this is a video's solution. Now, I want create a non vidoe/audio sourceBuffer url. I don't know how to implement it. I think that maybe mediasource is not support.

<script>
    var ms = new MediaSource();
    var src = window.URL.createObjectURL(ms);
    console.log(src);

    // sourceopen is not work.
    // I don't know if i can create a non audio/video type growing file url?
    ms.addEventListener('sourceopen', function(e) {
        var sourceBuffer = ms.addSourceBuffer('application/octet-stream');
        var xhr = new XMLHttpRequest();
        xhr.open('GET', '/test.bin', true);  // just a binary content
        xhr.responseType = 'arraybuffer';
        xhr.send();
        xhr.onload = function() {
            if (xhr.status >= 400) {
                alert('Unexpected status code ' + xhr.status);
                return false;
            }
            sourceBuffer.appendBuffer(xhr.response);
        };
    }, false);
</script>
Community
  • 1
  • 1
scott1028
  • 417
  • 2
  • 7
  • 16
  • You can define a new media type [14.1 Defining a new media type (beyond the existing Audio and Video types)](https://www.w3.org/TR/mediacapture-streams/#defining-a-new-media-type-beyond-the-existing-audio-and-video-types). What data are you trying to stream? – guest271314 Jul 12 '16 at 02:35
  • I just send a file to client. such as download zip file. – scott1028 Jul 12 '16 at 04:05
  • _"I just send a file to client, but sometime I want it to be sent only 0-300 bytes."_ What is issue? Do you send file to client as `ArrayBuffer` or `Blob`? – guest271314 Jul 12 '16 at 04:07
  • Not certain what requirement is? – guest271314 Jul 12 '16 at 04:13
  • My case is that the server side is recieving data, and send data to client at the same time. – scott1028 Jul 12 '16 at 05:58
  • Can you include `javascript` that you have tried at Question? – guest271314 Jul 12 '16 at 05:59
  • `application/octet-stream` does not appear to be not a supported type at `MediaSource`; try `MediaSource.isTypeSupported("application/octet-stream")`. Where is output of streamed data expected to be reviewed or displayed? Is file data a string? What is purpose of using `MediaSource`? – guest271314 Jul 12 '16 at 06:19
  • Are you trying to output a text stream to a ` – guest271314 Jul 12 '16 at 07:03
  • No, I just want to send file from server to client but the size of this file is growing up, maybe another process is writing it at the same time. – scott1028 Jul 13 '16 at 02:51
  • You can use `Blob`, `FileReader` to reassemble, append bytes into single file at client, see also http://stackoverflow.com/questions/35899536/method-for-streaming-data-from-browser-to-server-via-http – guest271314 Jul 13 '16 at 03:13

0 Answers0