views:

73

answers:

1

I'm having a problem when streaming video. Randomly the video isnt shown, the video is playing though as the playhead moves and audio sounds.

It's strange though because if I press pause then play the video appears and also if I make it fullscreen it appears.

private var videoURL:String = "filename.f4v";
private function setupConnection():void
{
 connection = new NetConnection();
 connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
 connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
 connection.addEventListener(AsyncErrorEvent.ASYNC_ERROR, onErrorConnect);
 connection.connect("rtmp://url to my streaming server");       
}

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":
   onPlayVideoHandler();
   break;
  case "NetStream.Play.StreamNotFound":
   trace("Stream not found: " + videoURL);
   break;
  default :
 }         
}      

private function onErrorConnect(event:AsyncErrorEvent):void
{
 trace("onErrorConnect: " + event);
}         

private function securityErrorHandler(event:SecurityErrorEvent):void
{
 trace("securityErrorHandler: " + event);
}

private function connectStream():void
{
 stream = new NetStream(connection);
 stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
 stream.bufferTime = 10;   

 var client:Object = new Object();
 client.onMetaData = onMetaData;
 stream.client   = client;   

 video    = new Video(200, 200);
 video.name  = "video";
 video.addEventListener(Event.ADDED_TO_STAGE, videoAddedToStage)
 video.attachNetStream(stream);
 video.smoothing  = true;
 video.x   = 0;
 video.y   = 0;
 mainHolder.addChild(video); 

 stream.play(videoURL, 0, 100, true);  
 stream.seek(0);
}

private function onPlayVideoHandler():void
{
  // add Controls
}

OK Ive found out the reason it doesnt show is because the video sometimes has a width and height of 0 pixels. Anybody know why it would return these values? Is it something todo with the nature of rtmp streaming videos?

A: 

I had to listen for the width and height to be greater than zero before proceeding. I never found out why but this is how to fix it.

daidai