Draw waveform for microphone in flex, is it possible? - apache-flex

I'm making a audio recorder with Adobe Flex (Microphone, NetStream), I want to get the current audio wave from Microphone to display in the visualization area, any idea how can i get the data?

You'll need to be using Flash Player 10 as I think that's the first time you actually got access to to the Microphone apis.
Then there's a simple function you can call which will get the microphone data:
private var soundBytes:ByteArray = new ByteArray;
SoundMixer.computeSpectrum(soundBytes, false);
I usually call the computeSpectrum code in an enter frame handler and draw out the wave form from there.
Edit: I don't want to mislead you. I think the above code is for a pre-recorded audio file. If you want to user the microphone in flash 10. You do it like this:
private var _mic:Microphone;
_mid = Microphone.getMicrophone();
_mic.addEventListener( SampleDataEvent.SAMPLE_DATA, onSampleData );
protected function onSampleData( event:SampleDataEvent ):void {
while( event.data.bytesAvailable ){
var n:Number = event.data.readFloat();
}
}

Related

Qt: Use QAudioRecorder to return buffer

I want to use QAudioRecorder to record an audio and save as a file and display the filepath to the user. I had tried using the the example from Qt but there's no feed on the buffer value when I tested it on Android. It works on my Desktop though. Below are part of my codes:
AudioRecord::AudioRecord(QWidget *parent)
{
audioRecorder = new QAudioRecorder(this);
probe = new QAudioProbe;
connect(probe, SIGNAL(audioBufferProbed(QAudioBuffer)),
this, SLOT(processBuffer(QAudioBuffer)));
probe->setSource(audioRecorder);
}
void AudioRecord::processBuffer(const QAudioBuffer& buffer)
{
qDebug()<<"Testing Successful";
}
The processBuffer function does not seems to be called. What should I do to get the buffer value work? Is there any other way around?
Thanks!

Flex web application: prevent framerate drop when window is invisible

So there's been a new "feature" in the flash player since version 10.1, which reduces the player's framerate to 2 fps when the application window is out of view. This is good news for performance, but it can break some functionality, such as the Timer class.
I have an application which uses a Timer to display a countdown. Given the nature of the application, it is required for the Timer to complete its countdown even if the user is not there to see it. Imagine that you need to give the user only 10 seconds to perform a task. If the user minimizes the window halfway through the counter, they can take as much time as they want and still have 5 seconds left when they return to the window. This apparently can not be avoided with the newer flash players.
In Air applications there is the backgroundFrameRate property which can be set to prevent this behavior, but this is part of the WindowedApplication class, so it seems that it is not available in a web application. Does anyone know a way to keep a constant frame rate even when the window is not visible? Thanks
Setting the wmode parameter of the embedded swf to opaque will prevent the framerate throttling.
Brian
I've not tried myself, but maybe you can try to force the framerate onDeactivate:
stage.addEventListener(Event.DEACTIVATE, onDeactivate);
function onDeactivate (e:Event):void
{
//eg myFrameRate=24
stage.frameRate = myFrameRate;
}
Let me know if this works.
Testing with:
private var numer:int = 0;
private var prevNumer:int = 0;
private var timer:Timer = new Timer( 1000, 0 )
[...]
var tf:TextField = new TextField ();
addChild (tf);
addEventListener ( Event.ENTER_FRAME, onEnterFrame )
timer.addEventListener (TimerEvent.TIMER, onTimer )
timer.start()
function onTimer ( e:TimerEvent ):void
{ tf.appendText (' ' + (numer - prevNumer)); prevNumer = numer;}
function onEnterFrame ( e:Event ):void { numer++ }
shows clearly, that when You see the flash, tf appends numbers equal to Your FPS. If timer would get changed together with FPS, You wouldn't see a difference when minimizing a window. But, coming back You see 2 2 2 2 2, that is, FPS dropped to 2.
onDeactivate solution by AsTheWormTurns doesn't work. Event is fired, but fps not changed.
wmode=opaque solution by Mr Brian Bishop doesn't work too
something obvious to try: change onEnterFrame function to set FPS:
function onEnterFrame ( e:Event ):void { numer++; stage.frameRate = 30 }
Obviously You can't set FPS when flash is not visible! Well, You can't set FPS unless You set it to 1.
Workaround to Your problem is simple, just make another timer similar to this above but with additional conditional:
function onTimer ( e:TimerEvent ):void {
if ( numer - prevNumer == 2 ) adjustOriginalTimer();
tf.appendText (' ' + (numer - prevNumer)); prevNumer = numer;
}
E: You can read about it here: http://help.adobe.com/en_US/as3/mobile/WS4bebcd66a74275c36cfb8137124318eebc6-8000.html

Sending POST variables to a browser window from AIR application

I'm building an AIR application. Basically, what I'm looking to do is using navigateToUrl() to open a browser window, assign it a "name" and then, send variables to that newly opened window using the POST method.
EDIT : I need the window to be visible, this is why I absolutely need to use the navigateToUrl() function
I already know that I CAN'T DO something like this, that the AIR application will send the variables using the GET method...
var vars:URLVariables = new URLVariables();
vars.myVar = "Hello my friend";
var req:URLRequest = new URLRequest("http://example.com/my-page.php");
req.method = "POST":
req.data = vars;
navigateToURL(req);
Considering the amount of variables I have to send (multiline texts) I absolutely need to send my variables using the POST method else Internet Explorer is truncating the query string... Works fine in Firefox and Safari but unfortunately, we will always have (hope not!) to deal with IE..
So I was thinking something like this :
import flash.net.navigateToURL;
private var _timer:Timer;
protected function loadPage():void
{
var req:URLRequest = new URLRequest("http://example.com/my-page.php");
navigateToURL(req, "myPageName");
_timer = new Timer(3000, 1);
_timer.addEventListener(TimerEvent.TIMER, postVars);
_timer.start();
}
protected function postVars(event:TimerEvent):void
{
// I'm looking to send variables using the POST method to "myPageName"
// and possibly using URLVariables()??
_timer.stop();
}
Any idea Flex coders? THANKS!
I think what you're going to need to do is open up a page you have control over, then use ExternalInterface to inject the values into a hidden form and then execute the post operation in that page form.submit(), etc.
This can happen almost instantly and it will all appear very seamless to the end user.

Flex/Flash Shoutcast player

I am trying to build a flash player for my company's Shoutcast server, and have seen a few articles about it on the 'net, including this SO question here.
However, I can't seem to get the audio stream to actually play. It seems to be connecting alright, but calling stream.play() doesn't seem to do anything.
I have tried the code in the SO question I have linked to, and have also tried something similar to this (sorry i don't remember the exact syntax):
public function stream() {
private var url:URLREQUEST = "my.domain.com";
private var sStream:Sound = new Sound();
sStream.load(url);
sStream.play();
}
If anyone has any revelations for me I'd appreciate it.
I just posted a solution on this thread:
How to stream a shoutcast radio broadcast in Flash (Shoutcast Flash Player)
Did you try this - (corrected some typos in the code you posted)?
public function stream()
{
private var url:URLRequest = new URLRequest("my.domain.com/song.mp3");
private var sStream:Sound = new Sound();
sStream.load(url);
sStream.play();
}

Get the status of a live stream for a VideoDisplay control

I'm looking for a way to find the status of a live stream through a VideoDisplay (or any other method really). I am interested to know if the stream is currently being published to or if the publisher has stopped. This is for a Flex/Flash ActionScript 3 project.
Is there a way to do this or is this ANOTHER oversight by adobe?
flex flash adobe adobe-flex actionscript
I've only found one solution, and that's using the NetStream object in combination with a video control.
The video control must be manually added to an
nsListen = new NetStream(nc);
nsListen.addEventListener(NetStatusEvent.NET_STATUS, nsListenHandler);
nsListen.play(streamname);
var v:Video = new Video();
v.attachStream(nsListen);
uicontrol.add(v);
Finally, the event status is returned in nsListenHandler:
private function nsListenHandler(e:Event):void
{
if(e is NetStatusEvent)
{
var nse:NetStatusEvent = NetStatusEvent(e);
if(nse.info.code == "NetStream.Play.Failed")
{
// Big error.
}
if(nse.info.code == "NetStream.Play.PublishNotify")
{
// Stream has just been published
}
if(nse.info.code == "NetStream.Play.UnpublishNotify")
{
// Stream has just been unpublished
}
trace(NetStatusEvent(e).info.code);
trace(NetStatusEvent(e).info.description);
}
}
Only this code wont do is tell you if a stream is already successfully being published to.
You can dig into NetStatusEvent events.
Check this live docs

Resources