I have some audio files on my http server, and I would like to write a Flash client in ActionScript3 to load those audio file and play them smoothly. Of course I can just create a Sound object and load it by .load() with a URL request. But for saving the bandwidth, I prefer to load audio file chunks on demand. For example, there is an audio file let’s say 100MB. If we try to load as fast as possible when user open the page
<--------- 100MB ----------->
The downloading may finished within minutes, but let’s say, if user stop listener in halfway, that’s kind of waste to load whole soundtrack at first.
<--------- 100MB ----------->
^--- user may stop here
To solve the problem, I think it’s better to split the big audio file into small chunks, load and play them on demands.
<--- 10MB ---><--- 10MB ---><--- 10MB ---> ...
^--- user current position
I want to design the player, let it load audio chunk by chunk, and only load it when it’s near the end of current chunk.
Here comes the question – How to load those chunks and play them smoothly? I can probably create Sound object for each chunks. But how to play them seamless?
You probably will want to use
SoundChannel, and see the example there, and the tutorial. Once you get a sound loaded, you can play the sound, store the position, and get the length to find out the time left to play. From there, probably dispatch an event to load up the next sound. Derived from the second example (you will have to put it your class structure):