diff --git a/index.js b/index.js index feef7f79a..1d5e0292c 100644 --- a/index.js +++ b/index.js @@ -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(); diff --git a/midp/media.js b/midp/media.js index e9376740a..438aaf53d 100644 --- a/midp/media.js +++ b/midp/media.js @@ -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); +});