Skip to content

Commit

Permalink
Merge pull request mozilla#687 from PinZhang/pzhang/fix-snapshot
Browse files Browse the repository at this point in the history
Fix issue: only first snapshot sucess
  • Loading branch information
Marco committed Dec 5, 2014
2 parents c503810 + 22e15e2 commit f4eb28c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,10 @@ DumbPipe.registerOpener("camera", function(message, sender) {
document.body.appendChild(video);
video.style.position = "absolute";
video.style.visibility = "hidden";
// Some MIDlets need user touch/click on the screen to complete the snapshot,
// to make sure the MIDlet itself instead of the video element can capture
// the mouse/touch events, we need to set `pointer-events` as `none`.
video.style.pointerEvents = "none";
video.addEventListener('canplay', function(ev) {
// We should use videoWidth and videoHeight, but they are unavailable (https://bugzilla.mozilla.org/show_bug.cgi?id=926753)
Expand Down
10 changes: 7 additions & 3 deletions midp/media.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ ImageRecorder.prototype.recipient = function(message) {

MIDP.sendNativeEvent({
type: MIDP.MMAPI_EVENT,
intParam1: this.playerContainer.handle,
intParam1: this.playerContainer.pId,
intParam2: 0,
intParam3: 0,
intParam4: Media.EVENT_MEDIA_SNAPSHOT_FINISHED,
Expand Down Expand Up @@ -499,8 +499,12 @@ ImageRecorder.prototype.getSnapshotData = function(imageType) {
return this.snapshotData;
}

function PlayerContainer(url) {
function PlayerContainer(url, pId) {
this.url = url;
// `pId` is the player id used in PlayerImpl.java, don't confuse with the id we used
// here in Javascript. The reason we need to hold this `pId` is we need to send it
// back when dispatch Media.EVENT_MEDIA_SNAPSHOT_FINISHED.
this.pId = pId;

this.mediaFormat = url ? this.guessFormatFromURL(url) : "UNKNOWN";
this.contentType = "";
Expand Down Expand Up @@ -870,7 +874,7 @@ AudioRecorder.prototype.close = function() {
Native.create("com/sun/mmedia/PlayerImpl.nInit.(IILjava/lang/String;)I", function(appId, pId, jURI) {
var url = util.fromJavaString(jURI);
var id = pId + (appId << 32);
Media.PlayerCache[id] = new PlayerContainer(url);
Media.PlayerCache[id] = new PlayerContainer(url, pId);
return id;
});

Expand Down
9 changes: 7 additions & 2 deletions native.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ Native.create("java/lang/System.getProperty0.(Ljava/lang/String;)Ljava/lang/Stri
value = "file:///";
break;
case "fileconn.dir.photos":
value = "file:///Photos/";
// We need to create the dir in the FS init process if it's
// not the root dir.
value = "file:///";
break;
case "fileconn.dir.roots.names":
// The names here should be localized.
Expand Down Expand Up @@ -194,7 +196,10 @@ Native.create("java/lang/System.getProperty0.(Ljava/lang/String;)Ljava/lang/Stri
value = "audio/ogg";
break;
case "video.snapshot.encodings":
value = "encoding=jpeg";
// FIXME Some MIDlets pass a string that contains lots of constraints
// as the `imageType` which is not yet handled in DirectVideo.jpp, let's
// just put the whole string here as a workaround and fix this in issue #688.
value = "encoding=jpeg&quality=80&progressive=true&type=jfif&width=400&height=400";
break;
default:
console.warn("UNKNOWN PROPERTY (java/lang/System): " + util.fromJavaString(key));
Expand Down

0 comments on commit f4eb28c

Please sign in to comment.