AS3 notification for first frame of video
When I play a video in Flash it first starts buffering and then when the buffer is full it plays. While the buffer fills up, the associated Video object automatically displays the first frame of the video.
Is there a way to get notified when this frame is available? As I want to hide the video component until there is an image to be displayed.
I am currently processing a full NetStreamEvent buffer so it is displayed when it starts playing. But now I need a bigger buffer (10 seconds), so waiting 10 seconds to show something to the user is not good.
+2
a source to share
1 answer
you must listen to "NetStream.Play.Start";
package {
import flash.display.Sprite;
import flash.events. *;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
public class VideoExample extends Sprite {
private var videoURL: String = "someVideo.flv";
private var connection: NetConnection;
private var stream: NetStream;
private var video: Video;
public function VideoExample () {
connection = new NetConnection ();
connection.addEventListener (NetStatusEvent.NET_STATUS, netStatusHandler);
connection.addEventListener (SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
connection.connect (null);
}
private function netStatusHandler (event: NetStatusEvent): void {
trace ("event.info.code" + event.info.code);
switch (event.info.code) {
case "NetConnection.Connect.Success":
connectStream ();
break;
case "NetStream.Play.Start":
addChild (video);
break;
case "NetStream.Play.StreamNotFound":
trace ("Unable to locate video:" + videoURL);
break;
}
}
private function connectStream (): void {
var stream: NetStream = new NetStream (connection);
stream.addEventListener (NetStatusEvent.NET_STATUS, netStatusHandler);
stream.addEventListener (AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
video = new Video ();
video.attachNetStream (stream);
stream.play (videoURL);
}
private function securityErrorHandler (event: SecurityErrorEvent): void {
trace ("securityErrorHandler:" + event);
}
private function asyncErrorHandler (event: AsyncErrorEvent): void {
// ignore AsyncErrorEvent events.
}
}
}
0
a source to share