Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error handling to getSeekableBlob #515

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions RecordRTC.js
Original file line number Diff line number Diff line change
Expand Up @@ -1881,6 +1881,7 @@ function setSrcObject(stream, element) {
/**
* @param {Blob} file - File or Blob object.
* @param {function} callback - Callback function.
* @returns {Blob} seekableFile - New seekable File or Blob; returns null if error occurred
* @example
* getSeekableBlob(blob or file, callback);
* @see {@link https://github.com/muaz-khan/RecordRTC|RecordRTC Source Code}
Expand All @@ -1897,18 +1898,28 @@ function getSeekableBlob(inputBlob, callback) {

var fileReader = new FileReader();
fileReader.onload = function(e) {
var ebmlElms = decoder.decode(this.result);
ebmlElms.forEach(function(element) {
reader.read(element);
});
reader.stop();
var refinedMetadataBuf = tools.makeMetadataSeekable(reader.metadatas, reader.duration, reader.cues);
var body = this.result.slice(reader.metadataSize);
var newBlob = new Blob([refinedMetadataBuf, body], {
type: 'video/webm'
});
try {
var ebmlElms = decoder.decode(this.result);
ebmlElms.forEach(function(element) {
reader.read(element);
});
reader.stop();
var refinedMetadataBuf = tools.makeMetadataSeekable(reader.metadatas, reader.duration, reader.cues);
var body = this.result.slice(reader.metadataSize);
var newBlob = new Blob([refinedMetadataBuf, body], {
type: 'video/webm'
});

callback(newBlob);
callback(newBlob);
}
catch (error) {
console.error("Could not decode file to make it seekable", {error});
callback(null);
}
};
fileReader.onerror = function(error) {
console.error("An error occurred attempting to load file", {error});
callback(null);
};
fileReader.readAsArrayBuffer(inputBlob);
}
Expand Down