|
-
Happy FK'er
Flash+iPhone inputs
Hey guys
Let's say I've got a soundboard application built in Flash. It works fine when ported to an iPhone/iPod Touch (exported via iPhone OS compiler in CS5)
(Before you mention it, I know that I can't put this app on the App Store... it's for private use only... besides, I'm not reducing myself to put soundboard apps on the App Store)
At the moment, it works with a touch input. That is, you press a button on the screen to play a sound. That's all fine, but let's say I want to add an external control to interface with the Flash application to play the sounds.
My question is: Does Flash support any external input to an iPhone/iPod Touch? Like a Bluetooth listener, USB peripheral listener, microphone pitch listener, etc?
Why I ask is because if I were to stick with the touch listener, I would have to build some sort of typewriter mechanism to press the buttons on the screen.
Thank you for reading!
TheWaste
"Good lord, you're wasting thousands of dollars worth of Interferon!"
"... and you're Interferon with our good time!"
-
First of all it is impossible to hook up bluetooth with your pc unlesss you have the proper USB for it.
Even if you get the USB for it flash cannot detect it because
"you can't flash is a webprogramming language it doesn't understand hardware...flash is not a programming language so to speak it is a scripted language" ~ calmchess
and I do beleive it is still the same for CS5.
As for microphones, yes it does work and I have found a great tutorial on how to use it for the new flash player 10.1.
The tutorial is in french and I have translated it for you...
Since Flash Player 10.1, it is now possible to record the flow of the microphone as ByteArray, to listen, and then save it on your hard drive.
In fact, since Flash Player 10.1, using SampleDataEvent.SAMPLE_DATA, we may acquire in the raw stream from the microphone.
In this example, you can register, you listen, and then save the sound file in WAVE.
Code:
PHP Code:
import pack.WAVEncoder; var soundBytes:ByteArray = new ByteArray(); soundBytes.endian = Endian.LITTLE_ENDIAN; var mic:Microphone = Microphone.getMicrophone(); mic.gain = 100; mic.rate = 44; rec.addEventListener(MouseEvent.CLICK,onClickk); function onClickk(e:Event):void { mic.addEventListener(SampleDataEvent.SAMPLE_DATA, micSampleDataHandler); } function micSampleDataHandler(event:SampleDataEvent):void { while (event.data.bytesAvailable) { var sample:Number = event.data.readFloat(); soundBytes.writeFloat(sample); } } function playbackSampleHandler(event:SampleDataEvent):void { for (var i:int = 0; i < 8192 && soundBytes.bytesAvailable > 0; i++) { var sample:Number = soundBytes.readFloat(); event.data.writeFloat(sample); event.data.writeFloat(sample); } } eco.addEventListener(MouseEvent.CLICK,onClick); function onClick(e:Event):void { mic.removeEventListener(SampleDataEvent.SAMPLE_DATA, micSampleDataHandler); soundBytes.position = 0; var sound:Sound = new Sound(); sound.addEventListener(SampleDataEvent.SAMPLE_DATA, playbackSampleHandler); sound.play(); } function _saveFileHandler(e:Event):void { var encoder:WAVEncoder = new WAVEncoder ( ); var fileRef:FileReference = new FileReference ( ); fileRef.save( encoder.addHeaders ( testConvert(soundBytes) ), "monSon.wav" ); } function testConvert( p:ByteArray ):ByteArray { var ba:ByteArray = new ByteArray ( ); ba.endian = Endian.LITTLE_ENDIAN; p.position = 0; while ( p.position < p.length ) { ba.writeShort( p.readFloat ( ) * 32767); } return ba; } mySaveButton.addEventListener(MouseEvent.CLICK,_saveFileHandler);
-
Happy FK'er
That looks fantastic! Thank you for the effort involved with the translation!
However, CS5 is telling me there is no such class as 'pack.WAVEncoder', and searching on Google I can't seem to be able to even confirm it exists. Am I missing something?
Regards,
TheWaste
"Good lord, you're wasting thousands of dollars worth of Interferon!"
"... and you're Interferon with our good time!"
-
Happy FK'er
Update: Actually, I did find the WAVEncoder class, but this code example seems to reference the wrong file.
The WAVEncoder class appears to be part of the PopForge class package: http://code.google.com/p/popforge/
Changing the class path and installing the Popforge WaveEncoder class should theoretically work fine, but it is missing a 'addHeaders' function in the class to be compatible. I'm thinking the person who wrote this tutorial has made his own class out of other peoples classes (or something) which is why I'm unable to find it.
Anyway, I'm going to go ahead and call this topic resolved because it has answered my question: Flash can read the iPod/iPhone mic input level (which can be used as a data input), so thank you.
"Good lord, you're wasting thousands of dollars worth of Interferon!"
"... and you're Interferon with our good time!"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|