Fix the timing issue when media permission prompt is not disabled.

Also add audio-capture to permissions of manifest.webapp.
This commit is contained in:
Pin Zhang 2014-11-24 13:52:14 +08:00
Родитель 137be70042
Коммит c04486a44e
4 изменённых файлов: 36 добавлений и 11 удалений

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

@ -267,7 +267,11 @@ DumbPipe.registerOpener("socket", function(message, sender) {
DumbPipe.registerOpener("audiorecorder", function(message, sender) {
var mediaRecorder = null;
var localAudioStream = null;
function startRecording(localStream) {
localAudioStream = localStream;
mediaRecorder = new MediaRecorder(localStream, {
mimeType: message.mimeType // 'audio/3gpp' // need to be certified app.
});
@ -309,22 +313,23 @@ DumbPipe.registerOpener("audiorecorder", function(message, sender) {
mediaRecorder.onstart = function(e) {
sender({ type: "start" });
};
}
navigator.mozGetUserMedia({
audio: true
}, function(localStream) {
sender({ type: "start" });
startRecording(localStream);
}, function(e) {
sender({ type: "error", error: e });
});
mediaRecorder.start();
}
return function(message) {
switch(message.type) {
case "start":
try {
if (mediaRecorder.state == "paused") {
if (!mediaRecorder) {
navigator.mozGetUserMedia({
audio: true
}, function(localStream) {
startRecording(localStream);
}, function(e) {
sender({ type: "error", error: e });
});
} else if (mediaRecorder.state == "paused") {
mediaRecorder.resume();
} else {
mediaRecorder.start();
@ -351,6 +356,9 @@ DumbPipe.registerOpener("audiorecorder", function(message, sender) {
case "stop":
try {
mediaRecorder.stop();
localAudioStream.stop();
mediaRecorder = null;
localAudioStream = null;
} catch (e) {
sender({ type: "error", error: e });
}

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

@ -23,7 +23,10 @@
"mobilenetwork": {
"description:": "Required to verify your phone number"
},
"browser": {}
"browser": {},
"audio-capture": {
"description": "Required to capture audio via getUserMedia"
}
},
"type": "privileged"
}

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

@ -646,10 +646,12 @@ AudioRecorder.prototype.start = function() {
return new Promise(function(resolve, reject) {
this.onstart = function() {
this.onstart = null;
this.onerror = null;
resolve(1);
}.bind(this);
this.onerror = function() {
this.onstart = null;
this.onerror = null;
resolve(0);
}.bind(this);

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

@ -18,6 +18,7 @@ import javax.microedition.media.Player;
import javax.microedition.media.control.RecordControl;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import javax.microedition.media.PlayerListener;
public class AudioRecorder extends MIDlet implements CommandListener,
ItemCommandListener {
@ -71,6 +72,17 @@ public class AudioRecorder extends MIDlet implements CommandListener,
try {
player = Manager.createPlayer("capture://audio");
player.realize();
player.addPlayerListener(new PlayerListener() {
public void playerUpdate(Player player, String event, Object eventData) {
if (PlayerListener.RECORD_ERROR.equals(event)) {
logMessage("Error occurs when start recording: " + eventData);
recording = false;
updateRecordingMessage();
}
}
});
recordControl = (RecordControl) player
.getControl("RecordControl");
outputStream = new ByteArrayOutputStream();