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

callback_finished_sending event fired before URL request completes #2

Open
shanplourde opened this issue Jan 17, 2012 · 10 comments
Open

Comments

@shanplourde
Copy link

At this time, callback_finished_sending is firing before the HTTP response is received from the audio stream upload. As shown in the current implementation of Main.as, private function finalize_recording():void below, ExternalInterface.call() is invoked right after new URLLoader(req).

if(_var1 != '')
{
var req:URLRequest = new URLRequest(_var1);
req.contentType = 'application/octet-stream';
req.method = URLRequestMethod.POST;
req.data = recorder.output;

var loader:URLLoader = new URLLoader(req);
ExternalInterface.call("$.jRecorder.callback_finished_sending");

}

The issue is that new URLLoader(req) invokes an HTTP request, but does not block until the response is returned. Thus the JavaScript callback_finished_sending is invoked before the HTTP request completes. As I don't have a Flash IDE to build this project, and limited Flash knowledge, the only thing that I can do is suggest a fix similar to the following, based on the Adobe API reference at http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLLoader.html:

if(_var1 != '')
{
var req:URLRequest = new URLRequest();
req.addEventListener(Event.COMPLETE, postAudio_urlLoader_complete);
req.data = recorder.output;
req.contentType = 'application/octet-stream';
req.method = URLRequestMethod.POST;
req.load(_var1);

}

function postAudio_urlLoader_complete(evt:Event):void {
ExternalInterface.call("$.jRecorder.callback_finished_sending");
}

It would be great if someone or the author of this component integrate this change and validate that callback_finished_sending is invoked after urlLoader_complete() returns.

Thanks
Shan

@sythoos
Copy link
Owner

sythoos commented Jan 18, 2012

Good point, I shall update the code based on your comment, thanks

@MaciejLisCK
Copy link

I spotted the same issue, I hope some one will fix that.

@gabceb
Copy link

gabceb commented Mar 18, 2013

This fork https://github.com/gabceb/jRecorder contains a fix for this, PR #6, #7 and support for playback before the audio is sent to the server.

@r0dy
Copy link

r0dy commented Mar 28, 2013

Are you sure the swf file is updated ?
Cause i just downloaded it and when i replace my old one with this one,

  • the callback_finished_sending event is still called before the request completes (and this makes that the data received is null)
  • the callback_activityLevel looks way slower (with the old one my level bar would go smoothly along the sound level, now it's refreshed at a very low frequency so it looks bad)

@gabceb
Copy link

gabceb commented Mar 28, 2013

Did you try the swf file on my branch? Maybe @harrisonmgordon can give you more details since he is the Flash gooru

@r0dy
Copy link

r0dy commented Mar 28, 2013

Thanks, I just tried it... but with that one the flash object doesn't event load properly.
I switched back :

swf_path : 'js/jRecorder.swf'
//swf_path : 'js/AudioRecorderCS4_CS5.swf'

and it worked...
When I use yours and try to start recording, i get :
Uncaught TypeError: Object # has no method 'jStartRecording'

(same thing with the jRecorder.swf file found in /html )

@harrisonmgordon
Copy link

The branch was just updated with the latest .swf files - try using "/html/jRecorder.swf" and let us know if it's working. Make sure to refresh your flash cache - we've had troubles on our end updating due to that before.

@r0dy
Copy link

r0dy commented May 16, 2013

The finished_sending callback is ok, but there's a problem with data writing.
See my php code :

$fp = fopen($fullWavPath, "wb") or die ("cant open wav file");

$fcontent = file_get_contents('php://input');

fwrite($fp, $fcontent) or die ("cant write to wav file");

And I get "cant write to wav file"
If i switch back to the old swf, this part works fine.
I cleared my cache every time of course (anyway you can tell if you are seeing the old or the new by hearing or not the auto-preview playing).
I tried compiling it myself but it's the same.

If I print out the content of $fcontent, I get an empty string. It's not a problem of writing rights on the directory. When I switch back to the older version of the swf, it works.

@r0dy
Copy link

r0dy commented May 17, 2013

Precision : that's really strange because when I look into the Chrome console I can see in the "Request Payload" :
--cnyrkvnipkbkjrdedoefubflrljhunqx
Content-Disposition: form-data; name="file"; filename="null"
Content-Type: audio/wav
And then the beginning of the wav : RIFF, �WAVEfmt ���D¬ˆX���data �wa���ý�“�1�Sþ!�Mæuæ‡�ïøÑÓû1
So it IS actually sent...
But I can't get it through php:input, $_FILES or any $_REQUEST...

If I use the working one (which auto-previews the wav file), the content of Request Payload is directly :
RIFF,€�WAVEfmt ���D¬ˆX���data€�E��ã

(no Content-stuff data)

Hope it helps.

@r0dy
Copy link

r0dy commented May 17, 2013

Got the solution :
commented out everything you added in the request header and copied back some code of the original branch... works :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants