5

I'm streaming audio using NetConnection and NetStream. I know that you can modify sample data in real-time with the Sound object, however I cannot find the SampleDataEvent for audio playing with the NetStream object. Is there a way to pass the audio from the NetStream object to a Sound object and modify the sound at that object instead?

Edit: I'm willing to do any kind of crazy hacks, so any solution is OK!

Johan
  • 1,897
  • 5
  • 23
  • 29
  • how is audio data located on the server side, could you show an example url? do you have a new url for every new track or is it always the same? does the server allow to download much faster than playback speed and is it possible to get the complete file? – www0z0k Feb 04 '11 at 04:12
  • i think i know the way, just need more info – www0z0k Feb 04 '11 at 13:47
  • The data is streamed via standard RTMP and only MP3. Example URL would be something like http://host:1935/mp3playback/mp3:hello.mp3. There is a new URL for each track. It is, of course, possible to do progressive download via the Sound() object to achieve what I want, but I want to do it using NetStream(). – Johan Feb 05 '11 at 13:39
  • @ Johan - so it's totally impossible to get it directly by url without connecting a `NetConnection` first? is it hosted on flash media server? do you have access to server settings? – www0z0k Feb 05 '11 at 16:45
  • It's not impossible, but I want to avoid direct HTTP access to the MP3 files. Yes, I have access to any server settings, but I'm using C++ RTMP Server (http://www.rtmpd.com/). – Johan Feb 05 '11 at 17:20
  • @ Johan - does it support server-side actionscript? – www0z0k Feb 05 '11 at 18:19
  • It might, what did you have in mind? If not, it supports C++ :). – Johan Feb 06 '11 at 23:07
  • @ Johan - you need to access the bytecode of the sound, if using netstream it's possible only by passing it to the `NetStream.send()` *in addition* to the data being streamed. else you'll need something like a direct url for a `Sound` or `URLStream` – www0z0k Feb 07 '11 at 11:43

2 Answers2

2

you need to access the bytecode of the sound, if using netstream it's possible only by passing it to (requesting it by) NetStream.send() / NetConnection.call() in addition to the data being streamed. else you'll need something like a direct url for a Sound or URLStream

www0z0k
  • 4,444
  • 3
  • 27
  • 32
2

Depending on the quality you're looking for, it you can sacrifice it down to a mono signal with low-bitrate, you may be able to stream it to obtain it as a URLStream on the client side, and then feed the data of that URLStream to a SampleDataEvent of an empty Sound object, progressively at runtime.

The extra work would mostly be on the server side, decompressing your MP3 to a Waveform stream of floating-numbers (a stream of a single-channel [mono] signal or a blend of the two combined to mono) and then pushing that out to your client side application.

As the URLStream gets loaded, append it's downloaded bytes to the ByteArray available on the Sound's SampleDataEvent (also give it some buffer "time" to load sufficient waveform data). For each mono-sample's read from the URLStream, you should write the same value twice to the SampleDataEvent.data object (once to the Left channel, once to the Right).

All this being said, downgrading the WAV-like sound stream to mono may not be sufficient to cut down on bandwidth and reach a wide target audience. Perhaps a look at an OGG library for AS3 (which should exists) would be a better alternative, and should certainly support decoding partially downloaded streams.

chamberlainpi
  • 4,854
  • 8
  • 32
  • 63