Merge pull request #698 from PinZhang/pzhang/no-camera

VM stops if no camera is found.
This commit is contained in:
PinZhang 2014-12-15 10:27:17 +08:00
Родитель 00a858438f c79d67bf1b
Коммит f14d593c1f
2 изменённых файлов: 15 добавлений и 1 удалений

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

@ -375,6 +375,7 @@ DumbPipe.registerOpener("camera", function(message, sender) {
video.play();
}, function(err) {
console.log("Error: " + err);
sender({ type: "initerror", name: err.name, message: err.message });
});
return function(message) {

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

@ -422,17 +422,30 @@ function ImageRecorder(playerContainer) {
ImageRecorder.prototype.realize = function() {
return new Promise((function(resolve, reject) {
this.realizeResolver = resolve;
this.realizeRejector = reject;
this.sender = DumbPipe.open("camera", {}, this.recipient.bind(this));
}).bind(this));
}
ImageRecorder.prototype.recipient = function(message) {
switch (message.type) {
case "initerror":
if (message.name == "PermissionDeniedError") {
this.realizeRejector(new JavaException("java/lang/SecurityException", "Not permitted to init camera"));
} else {
this.realizeRejector(new JavaException("javax/microedition/media/MediaException", "Failed to init camera, no camera?"));
}
this.realizeResolver = null;
this.realizeRejector = null;
this.sender({ type: "close" });
break;
case "gotstream":
this.width = message.width;
this.height = message.height;
this.realizeResolver(true);
this.realizeResolver = null;
this.realizeRejector = null;
break;
case "snapshot":
@ -580,7 +593,7 @@ PlayerContainer.prototype.realize = function(contentType) {
} else {
this.player = new ImagePlayer(this);
}
this.player.realize().then(resolve);
this.player.realize().then(resolve, reject);
} else {
console.warn("Unsupported media format (" + this.mediaFormat + ") for " + this.url);
resolve(false);