fix video blob

This commit is contained in:
Marc Wäckerlin
2016-01-13 15:54:50 +00:00
parent 343bdd8c7c
commit f1042a1c2c
4 changed files with 39 additions and 16 deletions

View File

@@ -46,6 +46,14 @@ function MediaStreamRecorder(constraints) {
};
///@}
/// @name private methods
///@{
function createURL(data) {
var urlCreator = window.URL || window.webkitURL;
return urlCreator ? urlCreator.createObjectURL(data) : data;
}
///@}
/// @name internal event handlers
///@{
@@ -95,20 +103,24 @@ function MediaStreamRecorder(constraints) {
}
/// Get Stream to the Preview
/** @return Stream prepared to be used in a HTML @c src attribute
within a @c audio or @c video tag. */
/** @return Data URL prepared to be used in a HTML @c src
attribute within a @c audio or @c video tag. */
this.preview = function() {
return window.URL ? window.URL.createObjectURL(stream) : stream;
return createURL(stream);
}
/// Get Stream to the Recording
/** @return Stream prepared to be used in a HTML @c src attribute
within a @c audio or @c video tag, or to be used in a
HTML @c href attribute in a @c a tag for downloading
the recording. */
this.recording = function() {
var buff = new Blob(recordedBlobs, {type: 'video/webm'});
return window.URL ? window.URL.createObjectURL(buff) : buff;
/** @param callback Callback function that will be called with a
data url to be used in a HTML @c src attribute within a
@c audio or @c video tag, or to be used in a HTML @c
href attribute in a @c a tag for downloading the
recording. */
this.recording = function(callback) {
var reader = new FileReader();
reader.onload = function(e) {
callback(e.target.result);
}
reader.readAsDataURL(new Blob(recordedBlobs, {type: 'video/webm'}));
}
/// Start Stream Recording

View File

@@ -342,6 +342,7 @@ function guessfilename(mimetype, user, date) {
/// Display Image Attachments
function attachments(files, id, from, date) {
if (files) files.forEach(function(file) {
console.log(file);
if (!file.name) file.name = guessfilename(file.type, from, date);
var a = document.createElement('a');
a.href = file.content;
@@ -373,8 +374,10 @@ var recorder;
function done() {
if (recorder) {
recorder.stop();
previewfile(recorder.recording(), "video/webm");
abort();
recorder.recording(function(data) {
previewfile(data, "video/webm");
abort();
});
}
}