Skip to content

Instantly share code, notes, and snippets.

@weyert
Created January 20, 2011 18:52
Show Gist options
  • Save weyert/788374 to your computer and use it in GitHub Desktop.
Save weyert/788374 to your computer and use it in GitHub Desktop.
NetStream code
public function loadVideo(): void {
// create the video related variables
_netConnection = new NetConnection();
_netConnection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
_netConnection.addEventListener( NetStatusEvent.NET_STATUS, netStatusHandler);
_netConnection.connect( null );
}
/**
* Connect to the video stream
*/
private function connectVideostream():void {
_netStream = new NetStream( _netConnection );
_netStream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
_netStream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
_netStream.bufferTime = 5;
_netStream.client = this;
_videoScreen = new Video( ApplicationConstants.STAGE_WIDTH, ApplicationConstants.STAGE_HEIGHT );
_videoScreen.attachNetStream( _netStream );
contentLoaded();
}
// event handler
private function netStatusHandler(event: NetStatusEvent): void {
switch (event.info.code) {
case "NetConnection.Connect.Success":
connectVideostream();
break;
case "NetConnection.Connect.Failed":
case "NetConnection.Connect.Rejected":
contentError();
break;
case "NetStream.Play.Stop":
contentFinished();
break;
case "NetStream.Play.StreamNotFound":
contentError();
break;
case "NetStream.Publish.BadName":
contentError();
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment