Reputation: 82219
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.
Upvotes: 0
Views: 683
Reputation: 15722
Today, with Flash out of the equation, the media fragment is the best way to go.
Since 2012, there is a W3C specification recommendation for Media Fragments. The specification proposes a way to restrict the media resource presentation in the client to a subset of the complete media resource. While the specification mentions temporal, spacial, track and id dimensions, the ability to set an offset time for playback is the most interesting part.
Here is a blog post of mine, showing how playback from a point in time works.
The web server must support HTTP range requests to make this efficient in terms of bandwidth.
Upvotes: 0
Reputation: 6127
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
Upvotes: 1