Skip to content

Commit

Permalink
Take a shot from the camera stream
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Castelluccio committed Nov 25, 2014
1 parent 2605d35 commit 79332d5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
18 changes: 18 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
19 changes: 19 additions & 0 deletions midp/media.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,8 @@ function ImageRecorder(playerContainer) {
this.isAudioControlSupported = false;

this.realizeResolver = null;

this.snapshotData = null;
}

ImageRecorder.prototype.realize = function() {
Expand All @@ -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;
}
}

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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 = {};
Expand Down Expand Up @@ -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);
});

0 comments on commit 79332d5

Please sign in to comment.