var sound:Sound = new Sound();
var req:URLRequest = new URLRequest(url);
sound.load(url)
I want to modify the sound data (an mp3) as it comes in. Specifically, the mp3 will be encrypted using a 开发者_如何转开发stream cipher and I want to decrypt the data as it comes in. Is this possible using some type of event?
To process an existing audio stream, you have to set up an output Sound object, without loading a sound into it. Then listen on that sound object for the SampleDataEvent.SAMPLE_DATA, which is fired whenever a Sound object, for which the buffer is empty, starts playing. You will need to fill it's buffer with stereo PCM data (pairs of floating point numbers.)
To get those numbers, use the Sound.extract() method on your input Sound object (the one you've simply called sound in your code above) to read PCM data to a ByteArray. Process the data of that ByteArray however you want, and put it in the output buffer.
var input : Sound;
var output : Sound;
// ... set up your input sound source ... //
output = new Sound();
output.addEventListener(SampleDataEvent.SAMPLE_DATA, handleSampleData);
output.play();
// The SAMPLE_DATA event is dispatched whenever the output Sound object
// buffer is empty. Fill the buffer to keep playing sound.
function handleSampleData(ev : SampleDataEvent) : void
{
var buffer : ByteArray = new ByteArray;
input.extract(buffer, 2048);
// PCM data from input is now in the buffer ByteArray. Filter the sound
// data according to your requirements here.
ev.data.writeBytes(buffer);
}
There's also some sample code on the subject in the reference documentation for the extract() method.
In flash 10 you can do that. I am not sure if it is possible in previous versions. in flash 10 Sound class has one new type of event SampleDataEvent which actually get fired whenever play is called on a Sound Object and if there is no data available for Sound object to play i.e. it requests the data. Then catch the event write some mp3 data and Sound object can play that. this link might be of some help.
精彩评论