actionscript-3htmlaudiobufferhtml5-audio

HTML: How to start Sound playback from URL mid-file without buffering all sound data to that point


I have a long mp3 file hosted on a standard apache server (30 minutes long so far, but I would like it to work with longer sounds too).

I'd like to start playback of this audio within at a specified point.

When attempting to use Flash Actionscript 3, my basic tests show that ALL the audio from the start to the position I choose is buffered before playback (Sound.bytesLoaded was my friend here). If I start one second in, it takes about 3 seconds to start playback, 30 seconds in, takes about 25 seconds. Obviously with a really long mp3, like skipping playback to the middle of a 3-hour audiobook, this isn't going to be practical.

Here's the ActionScript 3.0 code I'm using:

button.addEventListener(MouseEvent.MOUSE_DOWN, function():void {
 var s:Sound = new Sound(); 
 var req:URLRequest = new URLRequest("http://example.com/audio.mp3"); 
 s.load(req); 
 s.play(30 * 60 * 1000); // start 30 seconds in.
} 
);

Anyone know if this is even possible in Flash?

If not, is it even possible to do this from a web page without installing any server-side solution?

Thanks a lot.


Solution

  • As I understand it, it is a question of regular "progressive download" over HTTP vs streaming.

    In a standard setup, a regular HTTP server and Flash Player cannot skip past parts of an mp3 or video, all the data up to that point has to be downloaded first, as you describe.

    One way to enable skiping/seeking is using a streaming server like Adobe's Flash Media Streaming Server or the open source alternative Red5 to serve the mp3's.

    But there are also ways to set up so called "pseudostreaming" on a HTTP server:

    http://flowplayer.org/plugins/streaming/pseudostreaming.html