Flash video bufferTime gotcha
I have recently been working on a website that contains a lot of video content, including some fairly short videos – less than 20 seconds in length. To ensure uninterrupted playback of these short clips I thought it would be smart to buffer the entire video stream before beginning playback.
In AS3 this can be achieved using the
bufferTime property, which I set to 20 seconds:
var nc:NetConnection = new NetConnection(); nc.connect(null); var ns:NetStream = new NetStream(this.introVideoConnection); ns.bufferTime = 20; var video:Video = new Video(320, 240); this.addChild(video); video.attachNetStream(ns); ns.play("myvideo.flv");
But when I tested the results on a remote server I discovered that Flash was waiting the entire 20 second duration before starting the video stream, despite the fact that the flv had fully downloaded in just a few seconds.
After scratching my head for a few moments I realised that the problem had to be the high
bufferTime. Normally playback would start as soon as the entire video was loaded to memory, regardless of the
bufferTime value, but that doesn’t appear to be the case when the
bufferTime exceeds the video duration.
bufferTime to less than the video duration worked as expected: Video playback began as soon as the buffer was full.