Take a shot from the camera stream

This commit is contained in:
Marco Castelluccio 2014-11-25 17:04:34 +01:00
Родитель 2605d35a5a
Коммит 79332d5314
2 изменённых файлов: 37 добавлений и 0 удалений

Просмотреть файл

@ -384,6 +384,24 @@ DumbPipe.registerOpener("camera", function(message, sender) {
video.style.visibility = message.visible ? "visible" : "hidden";
break;
case "snapshot":
var canvas = document.createElement("canvas");
canvas.width = curW;
canvas.height = curH;
var ctx = canvas.getContext("2d");
ctx.drawImage(video, 0, 0, curW, curH);
// TODO: Remove hardcoded image type
canvas.toBlob(function(blob) {
var fileReader = new FileReader();
fileReader.onload = function(data) {
sender({ type: "snapshot", data: fileReader.result });
}
fileReader.readAsArrayBuffer(blob);
}, "image/jpeg");
break;
case "close":
if (mediaStream) {
mediaStream.stop();

Просмотреть файл

@ -404,6 +404,8 @@ function ImageRecorder(playerContainer) {
this.isAudioControlSupported = false;
this.realizeResolver = null;
this.snapshotData = null;
}
ImageRecorder.prototype.realize = function() {
@ -421,6 +423,11 @@ ImageRecorder.prototype.recipient = function(message) {
this.realizeResolver(true);
this.realizeResolver = null;
break;
case "snapshot":
this.snapshotData = new Int8Array(message.data);
break;
}
}
@ -455,6 +462,10 @@ ImageRecorder.prototype.setVisible = function(visible) {
this.sender({ type: "setVisible", visible: visible });
}
ImageRecorder.prototype.startSnapshot = function(imageType) {
this.sender({ type: "snapshot", imageType: imageType });
}
function PlayerContainer(url) {
this.url = url;
@ -666,6 +677,10 @@ PlayerContainer.prototype.getRecordedData = function(offset, size, buffer) {
this.audioRecorder.data = new Uint8Array(this.audioRecorder.data.buffer.slice(toRead));
};
PlayerContainer.prototype.startSnapshot = function(imageType) {
this.player.startSnapshot(imageType);
}
var AudioRecorder = function(aMimeType) {
this.mimeType = aMimeType || "audio/ogg";
this.eventListeners = {};
@ -1088,3 +1103,7 @@ Native.create("com/sun/mmedia/NativeTonePlayer.nStopTone.(I)Z", function(appId)
console.warn("com/sun/mmedia/NativeTonePlayer.nStopTone.(I)Z not implemented.");
return true;
});
Native.create("com/sun/mmedia/DirectPlayer.nStartSnapshot.(ILjava/lang/String;)V", function(handle, imageType) {
Media.PlayerCache[handle].startSnapshot(imageType);
});