Use the addedToStage event with care!

Here’s something that just stung me: the addedToStage event can get fired at unexpected times e.g. if a component is sitting inside a container that has a scroll policy of ‘auto’, and something causes scrollbars to appear, the container will re-add all its children as part of introducing the scroll bar – so they will each get an addedToStage event, even though they themselves haven’t changed at all.

Recording with Java Sound on Vista

On XP, getting a line to record from can be achieved via AudioSystem.getLine(info).

Unfortunately, that doesn’t work on Vista – however it is possible to open a line by looping through the available mixers until you find one that successfully opens:

...
Mixer.Info[] mixers = AudioSystem.getMixerInfo();
for (int i=0; i<mixers.length; i++) {
	Mixer m = AudioSystem.getMixer(mixers[i]);
	try {
		targetDataLine = (TargetDataLine) m.getLine(info);
		targetDataLine.open(audioFormat);
		System.out.println("Opened a line using " + mixers[i]);
		break;
	}
	catch (Exception ex) {
		// Ignore the problem and try another mixer.	
	}
}
...

HTH

Recording audio to local file from an Air app

If you want to record audio from an Air app and store that recording locally, unfortunately you can’t simply write the sound file to disk (despite the fact Air has sufficient permissions to do that) because Flex/Air won’t encode audio or video using any of the formats you’d want to store (e.g. .mp3, .wav etc.).

Flash Player 6 and above uses the proprietary Nellymoser codec, and Flash Player 10 introduced support for the Speex codec – which is Open Source and free – but even using Speex it is not possible to write the recording to the file system (much to the annoyance of a lot of developers).

Until such a time as Adobe allow it directly, if you want to record an audio or video file there are two options (as far as I know):

1) Stream the recording to a media server (such as Adobe’s Flash Media Server, or an alternative such as Wowza) and then at the server end provide a service that will return the audio back to the client in a more useful format (e.g. mp3).  This isn’t something I’ve done, but believe it would be relatively straightforward (though does have the cost associated with providing the media server service, and obviously only works while the Air app is online).

or

2) Use another technology to record the sound (e.g. a Java application), and make that talk back and forth with the Air app, e.g. via sockets. For example, it’s possible to implement a recorder using the Java Sound library, then, on windows,  install that java app as a service that starts automatically; the Air app can then send messages to the java recorder by setting up a socket along the lines of:

...
_recorderSocket = new XMLSocket();
_recorderSocket.addEventListener(DataEvent.DATA, onIncomingData);
_recorderSocket.connect("127.0.0.1", _myPortNumber);
...
// Messages sent back from the java app will arrive here
private function handleIncomingData(event:DataEvent):void {
   switch (event.data as String) {
   ...
   }
}

Note that although it is possible to make Java Sound record in .mp3, there are licensing implications. An alternative is to record to .wav format – which Flex/Air won’t play back, but you can play back via Java, using sockets for control in the same way as recording.

This route I have done, and it seems to work just fine (though there are some complications re making Java Sound record on Vista, but I’ll blog on those separately).

HTH.

Adding a Wordpress contact form

So, I thought I’d set up a contact form for this blog, and I’m a newbie to Wordpress so I did a quick google and soon turned up a number of options.

FWIW this is what happened:

  • I downloaded Contact Form 7 (http://wordpress.org/extend/plugins/contact-form-7/) and tried that.  The installation instructions were slightly out of date, but I worked out that it is now configured via the ‘Settings’ link under Tools – Plugins.  Despite it’s name, it offers sophisticated control over the contact form it provides – including easy definition drop-downs in the form. However, I wanted a ‘CAPTCHA’ box (evidently the name for the ‘enter the code below’ mechanism used to stymy bots) – and Contact Form 7 states that a 2nd plug-in (Really Simple Captcha) is needed. The blurb for that plug-in said that “In most cases you can install automatically from WordPress.” – which I didn’t understand, and then it mentioned some pre-requisites on the server … so I got cold feet and started looking elsewhere.
  • Next port of call was http://eazeenet.in/contact-form-with-captcha-plugin-for-wordpress/ – but the form didn’t seem to appear at all for me, so I moved on
  • Finally I tried Mike Challis’ Fast and Secure Contact Form from http://wordpress.org/extend/plugins/si-contact-form/. That all worked fine first time – including the CAPTCHA part. However, my one criticism is that the validation errors seem a bit unfriendly to me (e.g. “INPUT ERROR: Please make corrections below and try again”, “A proper e-mail address is required” and “Please complete the CAPTCHA” [I didn't know it was called a 'CAPTCHA' until tonight]). Also, despite lots of other configuration options, the validation messages cannot be modified via the settings.  I worked around this my modifying the si-contact-form.php directly.

Meanwhile, I discovered that my server wasn’t set up to send mail via STMP directly – so I installed ‘configure SMTP’ from http://coffee2code.com/wp-plugins/configure-smtp/ and configured it to send mail via gmail (for which of course I had to enter my gmail credentials – <gulp>).  Fear aside – having heard a piece on Radio 4 just yesterday about e-mail accounts being hacked in to – that worked perfectly.

So, in the end I got the contact form I was after, hoorah.

Having typed this up now, I suspect that the pre-requisites that Really Simple Captcha mentioned are probably in place – so I could try that (and Contact Form 7) again. Hmm, is life too short?

So, here we go …

So, after way too long, here we go, blogging.

Cue a silent fanfare :-)

Here’s looking forward to ‘putting something back’.

Search
Categories