Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/tech check #3

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion examples/example-1.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@


Recorder.initialize({
swfSrc: "../recorder.swf"
swfSrc: "../recorder.swf",
onPrivacyChange: function (allowed) {
console.log(allowed);
},
noMicrophone: function(){
console.log('No microphone');
}
});

function record(){
Expand All @@ -38,6 +44,9 @@
},
progress: function(milliseconds){
document.getElementById("time").innerHTML = timecode(milliseconds);
},
hold: function() {
console.log('hold');
}
});
}
Expand Down Expand Up @@ -66,6 +75,10 @@
}
});
}

function setupPrivacy(){
Recorder.setupPrivacy();
}
</script>

<div id="wrapper">
Expand All @@ -80,6 +93,7 @@ <h1><a href="http://github.com/jwagener/recorder">Recorder Example</a></h1>
<a href="javascript:play()" id="play" >Play</a>
<a href="javascript:stop()" id="stop" >Stop</a>
<a href="javascript:upload()" id="upload" >Upload (faked)</a>
<a href="javascript:setupPrivacy()" id="setting" >Setting</a>
</div>

<span id="time">0:00</span>
Expand Down
130 changes: 88 additions & 42 deletions flash/Recorder.as
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ package

private var logger : Logger;
public function addExternalInterfaceCallbacks():void {
ExternalInterface.addCallback("record", this.record);
ExternalInterface.addCallback("_stop", this.stop);
ExternalInterface.addCallback("setupPrivacy", this.setupPrivacy);
ExternalInterface.addCallback("record", this.record);
ExternalInterface.addCallback("_stop", this.stop);
ExternalInterface.addCallback("_play", this.play);
ExternalInterface.addCallback("upload", this.upload);
ExternalInterface.addCallback("audioData", this.audioData);
Expand Down Expand Up @@ -115,23 +116,36 @@ package
protected var mp3Encoder : ShineMp3Encoder;
protected var encoding : Boolean;
protected var lastUploadCall : Array;
protected function record():void

protected function setupPrivacy():void
{
if(!microphone){
setupMicrophone();
if(setupMicrophone())
{
triggerEvent('privacy', !microphone.muted);
showFlash();
}
}

microphoneWasMuted = microphone.muted;
if(microphoneWasMuted){
logger.log('showFlashRequired');
triggerEvent('showFlash','');
}
protected function record():void
{
if(setupMicrophone())
{
microphoneWasMuted = microphone.muted;
if(microphoneWasMuted)
{
logger.log('showFlashRequired');
triggerEvent('showFlash','');
} else {
flash.utils.clearTimeout(timeoutIdDetectMicrophone);
timeoutIdDetectMicrophone = flash.utils.setTimeout(noSignal, RECORD_DATA_TIMEOUT * 1000);
}

buffer = new ByteArray();
buffer = new ByteArray();

// To avoid microphone error (PepperFlashPlayer.plugin: 0x2A052 is not valid resource ID.)
microphone.removeEventListener(SampleDataEvent.SAMPLE_DATA, recordSampleDataHandler);
microphone.addEventListener(SampleDataEvent.SAMPLE_DATA, recordSampleDataHandler);
// To avoid microphone error (PepperFlashPlayer.plugin: 0x2A052 is not valid resource ID.)
microphone.removeEventListener(SampleDataEvent.SAMPLE_DATA, recordSampleDataHandler);
microphone.addEventListener(SampleDataEvent.SAMPLE_DATA, recordSampleDataHandler);
}
}

protected function recordStop():int
Expand Down Expand Up @@ -364,7 +378,7 @@ package

protected function audioData(newData:String=null):String
{
var delimiter = ";"
var delimiter = ";";
if(newData){
buffer = new ByteArray();
var splittedData = newData.split(delimiter);
Expand All @@ -386,38 +400,57 @@ package
protected function showFlash():void
{
Security.showSettings(SecurityPanel.PRIVACY);
triggerEvent('showFlash','');
triggerEvent('showFlash','');
}

/* Recording Helper */
protected function setupMicrophone():void
/* Recording Helper */
private function noSignal():void
{
logger.log('setupMicrophone');
microphone = Microphone.getMicrophone();
microphone.codec = "Nellymoser";
microphone.setSilenceLevel(0);
microphone.rate = sampleRate;
microphone.gain = 100;
microphone.addEventListener(StatusEvent.STATUS, function statusHandler(e:Event) {
logger.log('Microphone Status Change');
if(microphone.muted){
triggerEvent('recordingCancel','');
}
else {
if (microphoneWasMuted) {
microphoneWasMuted = false;
triggerEvent('hideFlash', '');
}
timeoutIdDetectMicrophone = flash.utils.setTimeout(function () {
if (!isRecording) {
microphone.removeEventListener(SampleDataEvent.SAMPLE_DATA, recordSampleDataHandler);
triggerEvent('recordingCancel', '');
}
}, RECORD_DATA_TIMEOUT * 1000);
if (!isRecording) {
triggerEvent('recordingHold', '');
timeoutIdDetectMicrophone = flash.utils.setTimeout(noSignal, RECORD_DATA_TIMEOUT * 1000);
}
}

function onMicStatusHandler(event:StatusEvent):void
{
logger.log('Microphone Status Change');

triggerEvent('privacy', !microphone.muted);

if(microphone.muted) {
flash.utils.clearTimeout(timeoutIdDetectMicrophone);
}
else {
if (microphoneWasMuted) {
microphoneWasMuted = false;
triggerEvent('hideFlash', '');
}
});
timeoutIdDetectMicrophone = flash.utils.setTimeout(noSignal, RECORD_DATA_TIMEOUT * 1000);
}
}

logger.log('setupMicrophone done: ' + microphone.name + ' ' + microphone.muted);
protected function setupMicrophone():Boolean
{
if(Microphone.names.length == 0)
{
triggerEvent('noMicrophone', false);
return false;
}
else
{
if(!microphone){
logger.log('setupMicrophone');
microphone = Microphone.getMicrophone();
microphone.codec = "Nellymoser";
microphone.setSilenceLevel(0);
microphone.rate = sampleRate;
microphone.gain = 100;
microphone.addEventListener(StatusEvent.STATUS, onMicStatusHandler);
logger.log('setupMicrophone done: ' + microphone.name + ' ' + microphone.muted);
}
return true;
}
}

protected function notifyRecordingStarted():void
Expand Down Expand Up @@ -507,5 +540,18 @@ package
{
ExternalInterface.call("Recorder.triggerEvent", eventName, arg0, arg1);
}

public static function log(msg:String, caller:Object = null):void{
var str:String = "";
if(caller){
str = getQualifiedClassName(caller);
str += ":: ";
}
str += msg;
trace(str);
if(ExternalInterface.available){
ExternalInterface.call("console.log", str);
}
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "recorder.js",
"version": "0.3.7",
"version": "0.3.8",
"dependencies": {
"grunt": ">=0.4.1",
"underscore": "~1.5.2",
Expand Down
8 changes: 7 additions & 1 deletion recorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,19 @@
this.bind('showFlash', this.options.onFlashSecurity || this._defaultOnShowFlash);
this.bind('hideFlash', this._defaultOnHideFlash);
this.bind('incompatible', this.options.incompatible || this._showFlashRequiredDialog);
this.bind('privacy', this.options.onPrivacyChange);
this.bind('noMicrophone', this.options.noMicrophone);
this._loadFlash();
},

clear: function () {
Recorder._events = {};
},

setupPrivacy: function(){
this.flashInterface().setupPrivacy();
},

record: function (options) {
options = options || {};
this.clearBindings("recordingStart");
Expand All @@ -51,7 +57,7 @@
this.bind('recordingStart', options['start']);
this.bind('recordingProgress', options['progress']);
this.bind('recordingCancel', options['cancel']);

this.bind('recordingHold', options['hold']);
this.flashInterface().record();
},

Expand Down