0

My goal is to split the file and send it to over the other peer into chunks. as the chunks are blobs and i can split the file into blobs but first i want to play a video with the whole blob object in the sender side.

Here is in my code what i am doing is that i am converting the file into the blob object. after doing that i want to read the blob and then play it in html video element but i am failed to play the video. can any one help me, i am stuck here.

here is my code:

videoUpload(event) {

console.log("video event occured");
if (event.target.files && event.target.files[0]) {


  var reader2 = new FileReader();


  reader2.onload = (event: any) => {
    // CAN ANY ONE TELL ME HOW TO PLAY VIDEO BY USING THIS BLOB EVENT
  }


  **at this stage i am converting my file into the blob**
  var file = event.target.files[0];
  console.log(file.byteLength);
  var chunkSize = 6808850;
  var fileSize = file.size;
  var chunks = Math.ceil(file.size / chunkSize);
  var chunk = 0;

  console.log('file size..', fileSize);
  console.log('chunks...', chunks);

  while (chunk < chunks) {
    var offset = chunk * chunkSize;
    console.log('current chunk..', chunk);
    console.log('offset...', chunk * chunkSize);
    console.log('file blob from offset...', offset)
    var blob = file.slice(offset, offset + chunkSize);
    console.log(blob);
    chunk++;
  }

  // sending the blob to the event listener as array buffer, you can also tell me what "read as" method i can use.

  reader2.readAsArrayBuffer(blob);
}

}

Adil
  • 162
  • 1
  • 1
  • 10
  • Do you know a bit how a video file is generally composed? You have some headers, then some containers etc. It is a structured file, just like say, if you slice a word in two parts, you loose the meaning of the word, you can't slice a video file like that. So, except if you are going to actually read the whole file, what you want is already not possible. Now, if you actually want to stream the whole file content, then what you want is the [MediaSource Extension](https://developer.mozilla.org/en-US/docs/Web/API/MediaSource). – Kaiido Sep 11 '18 at 06:11
  • the total file size is 6808850, which is the chunk size. so i am not actually slicing, the file is just converting into the blob. i want to know that weather i can display video file in video tag using blob object.? – Adil Sep 11 '18 at 07:35
  • That's not what you are asking for in the question no. But if it is what you need then check https://stackoverflow.com/questions/36035721/how-can-i-set-preview-of-video-file-selecting-from-input-type-file/ even though the problem there was more about `` or https://stackoverflow.com/questions/28619550/javascript-play-uploaded-audio/28619927#28619927 even if it was for Audio, the same applies for video. – Kaiido Sep 11 '18 at 07:42

0 Answers0