19Jun
Simple Video Player
No commentsSo I want to get down the basics of creating a video player and found this code over at adobe. This will just simply pull in an .flv file and automatically play, nothing too glamorous, but will be a good foundation for when I start a project on creating a full player. [ code pulled from Adobe Docs ]
package {
import flash.display.Sprite;
import flash.events.NetStatusEvent;
import flash.events.SecurityErrorEvent;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.events.Event;
public class VideoPlayerExample extends Sprite {
private var videoURL:String = "path/to/movie.flv";
private var connection:NetConnection;
private var stream:NetStream;
public function VideoPlayerExample() {
connection = new NetConnection();
connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
connection.connect(null);
}
private function netStatusHandler(event:NetStatusEvent):void {
switch (event.info.code) {
case "NetConnection.Connect.Success":
connectStream();
break;
case "NetStream.Play.StreamNotFound":
trace("Stream not found: " + videoURL);
break;
}
}
private function securityErrorHandler(event:SecurityErrorEvent):void {
trace("securityErrorHandler: " + event);
}
private function connectStream():void {
stream = new NetStream(connection);
stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
stream.client = new CustomClient();
var video:Video = new Video();
video.attachNetStream(stream);
stream.play(videoURL);
addChild(video);
}
}
}
class CustomClient {
public function onMetaData(info:Object):void {
trace("metadata: duration=" + info.duration + " width=" + info.width + " height=" + info.height + " framerate=" + info.framerate);
}
public function onCuePoint(info:Object):void {
trace("cuepoint: time=" + info.time + " name=" + info.name + " type=" + info.type);
}
}
Categories: Actionscript 3, Video
Thursday, June 19th, 2008 at 11:31 am and is filed under Actionscript 3, Video. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.