Manipulating MP3 speed and direction
Here is one of those examples that I did just for the hell of it. I often wondered how hard it would be to play an MP3 in reverse. It turns out that it is really easy with Flash Player 10. Now my implementation of reverse is pretty weak and I’m sure guys like Andre Michelle could make something that sounded perfect. Click the button below to try it out. You can reverse direction and speed it up.
[/kml_flashembed]
You surely heard the jerkiness and little glitches and that could surely be corrected with more work. All of this is possible thanks to the new Sound.extract() method. This allows you to grab the bytes from a loaded sound and then manipulate them before passing them to the sound card. You tell the method how many sound samples you want to extract and what position to start from in the file. It is this position property that allows you to move in any direction in the file. Subtracting a number makes it go in reverse and adding to it moves the music forward.
Now one thing that screwed me up at first is the fact that the extract method deals with samples, not bytes. A sample is 8 total bytes of audio data with 4 bytes being for each channel. Another thing that is tricky is getting the total number of samples in a file. I used the method of multiplying 44100 by the number of seconds in the file. Obviously it will only work on files set at that sample rate and it isn’t foolproof. But this method could be useful to allow people to scrub back and forth through an audio file.
The code is shown below and you can also download the FLA. I created in Flash but you could easily dump this into Flash Builder as well. I’d be interested to hear if someone gets it sounding totally smooth. The real trick would be extract a chunk of samples and then reverse the bytes of the samples. I tried that but couldn’t figure it out.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | var ex:Sound; var ns:Sound; var position:int; var max:int; var speed:int = 4096; c.b1.addEventListener(MouseEvent.CLICK, function(){speed=-8192;}); c.b2.addEventListener(MouseEvent.CLICK, function(){speed=-4096;}); c.b3.addEventListener(MouseEvent.CLICK, function(){speed=4096;}); c.b4.addEventListener(MouseEvent.CLICK, function(){speed=8192;}); lclip.visible = false; c.visible = false; loadmusic.addEventListener(MouseEvent.CLICK, init); function init(e:Event):void { position = 0; loadmusic.visible = false; lclip.visible = true; ex = new Sound(new URLRequest("col.mp3")); ex.addEventListener(Event.COMPLETE, onComplete); ns = new Sound(); ns.addEventListener(SampleDataEvent.SAMPLE_DATA, onData); } function onComplete(e:Event):void { lclip.visible = false; c.visible = true; max = 44100 * (ex.length/1000) - 4096; position = max; ns.play(); } function onData(e:SampleDataEvent):void { var bytes:ByteArray = new ByteArray(); ex.extract(bytes, 4096, position); e.data.writeBytes(bytes); position += speed; if(position < 0) position = max; else if(position > max) position = 0; } |
Two weeks off
![]() |
Things have been kind of slow here on my blog and on Twitter over the last week. The reason is that I am on a two week vacation. In actual fact we are moving into our new house and are also remodeling a bathroom and updating the electrical service. I can honestly say that I’ve never worked as hard as I have over the last week. All of us in cushy computer jobs should take a minute and be thankful how easy we have it The photo at the left is me right after an extensive bit of tile cutting. I have also installed recessed lighting, wired receptacles and switches, and almost every other construction job. I have one more week of vacation and then I’ll be back with more tutorials and Flash-related posts. |
Lee
The Flashbelt dead drop explained
I am now home from Flashbelt and I had a great time in the 24 hours that I was there. In addition to giving two sessions I also did another dead drop. This one was very interesting for a few reasons. Firstly, many of the people who participated were actually speakers at the conference. Flash conference regulars like Geoff Stearns, Phillip Kerman, Robert Reinhardt, and many others worked together to try to solve the clues. I also gave hints to people who were having trouble getting past a certain point. Read below to see the steps that made up this drop.
The Carriage ID
In my initial blog post about the drop there was a form where people needed to enter their email address. After submitting the form they received an email welcoming them to the competition. It also contained a link to the first puzzle which you can see here. It contains an illustration of a carriage and has a text input where you have to enter the carriage ID. This one was tricky because the carriage ID was actually in a custom header that I set in the original email. Always question everything and viewing the email for hidden information would have quickly revealed the ID.

Jimmy Johns Meter
After the carriage ID you were taken to another Flash application that had some GPS coordinates, an electricity icon, and another text input. The GPS location too you to a Jimmy John’s sandwich shop and you had to enter the serial number off of the power meter to get to the next step. Phillip and the guys from Influxis actually found a transformer with a sticker on it that looked identical to the one on the website but this was just a coincidence. Because of this I gave out a clue on Twitter explaining that the meter was the intended target.

SQL Injection
After Jimmy Johns you were taken to another Flash application that consisted of a syringe and a text input asking for the Agent ID. So what was the agent ID that you needed to enter? It didn’t matter what you entered so long as you realized that the syringe meant you had to perform a SQL injection attack. Check out the Wikipedia page on SQL injection to get the details. All you had to enter was something like 7864′ or ‘t=t in order to get to the next stage. I saw Mario helping out Geoff to construct the SQL attack. I also had to do some work to make my PHP backend vulnerable to SQL injection.
Gold Medal Flour
The next clue was a photo of a theater located about 4 blocks from the conference. The word “CUE” was also on the image as there is a restaurant in the theater by that name. After going to the location you had to figure out that I removed something in the photo. Below you can see the before and after showing that the Gold Medal Flour sign had been Photoshopped out. This was what you had to enter in the text input to get to the last clue.

Lock Picking
Earlier in the week I Twittered a YouTube video that I created showing how you can easily pick simple office-style locks using simple office supplies. The last clue sent you to the Aloft hotel in Minneapolis and more specifically the handicapped stall in the lobby bathroom. There you had to pick the lock on the toilet paper dispenser to get the winning code, which I had written using a sharpie. The guys from Influxis who won actually asked a guy who worked there to open the lock so they didn’t have to pick it. That was good thinking although in an actual operation you would never expose yourself like that.

This one was kind of topsy turvy but was a lot of fun nonetheless. Many attendees were confused about what the dead drop was so I’m going to have to do a better job of getting the information out next time. Congratulations to the guys from Influxis for capturing the prize.
Lee
The Flashbelt dead drop has begun
Update: this dead drop has been found. More details to come.
I have just finished setting up the Flashbelt dead drop. I think this one should be pretty interesting. I have upped the prizes on this one. The winner will receive Master Collection CS4, Flex 3 Professional, and some books from O’Reilly. Hurry up because as you know, these contests are often over rather fast.
Submit your email using the form located at the link below to get started. This is just so I can track participants and I won’t be using your email address for anything not related to the dead drop. If you are going to Twitter at all please use the #deaddrop hashtag. Good luck!
Lee
Dead drop, Catalyst, and ByteArrays
![]() |
Tomorrow I will be leaving for Flashbelt and I will be cramming a whole bunch of stuff into the 24 hours that I will be there. First there will a Master Collection dead drop which will begin sometime tomorrow night. Stay tuned here and on Twitter (#deaddrop) for the start of the challenge. On Tuesday morning I will be taking over Mark Anders’ session on Flash Catalyst. Mark is sick and will be unable to attend. The session may differ in that I have much more of a Flash-heavy perspective on the tool. After lunch is my ByteArray session which I think you will enjoy. I’ll be hanging around for a bit and then flying home on Tuesday night. |
Lee










