Showing posts with label ActionScript. Show all posts
Showing posts with label ActionScript. Show all posts

Friday, November 16, 2012

how to know the end of the file in action script!!!


There are two ways to find the end of the file using action script for the flv files.
  1. Using meta data (which we will get by getting meta event onMetaData)
  2. Using netStatus code "NetStream.Play.Stop"
Using onMetaData: When this event occurs, we need to take the duration of the file by using mdata.duration, which gives the duration of the file. After getting the duration of the file, we need to compare with the buffer length of the file while playing. Actually playing flv file in action script is, taking the fixed buffer length and play that buffer and after completing that buffer again take buffer and play that buffer, this process will continue till it reaches empty. So if the file is empty, buffer length reaches duration of the file or more. For us this condition is important, for checking end of the file, we can check this condition as shown in the sample code below.


Getting duration of the file:
public function onMetaEvent(mdata:Object):void
{
 //taking the duraiton time for looping
 lastPosition = mdata.duration;
}
Finding the end of the file:
public function netStatus(item:Object):void
{
 //Unpause.Notify code will be generated whenever buffer fills with data
 if (item.info.code == "NetStream.Unpause.Notify")
 {
 if (Math.floor(stream.bufferLength) >= Math.floor(lastPosition))
 {
 //buffer length reaches end of the file
 }
 }
}
Using netStatus code "NetStream.Play.Stop" : Here we need to check for the NetStream status code Play.Stop. as shown in the below sample code.

public function netStatus(item:Object):void
{
 if (item.info.code == "NetStream.Play.Stop")
 {
 //reaches end of the file
 }
}
For more NetStream status codes click here.

Wednesday, November 7, 2012

Error #2044: Unhandled NetStatusEvent

Recently we worked on the simple application called face detection using actionscript. While doing this application, we faced some common problems, we are sharing here.

Scenario: When the application did not find any face in front of camera, it needs start playing some flv file. For this we created the flv player and added the flv file to the player. Below is the code for that.
nc=new NetConnection();
nc.connect(null);
ns = new NetStream(nc);
vid = new Video(320,240);
            
addChild(vid);
client = new Object();
ns.client = client;
client.onMetaData = nsMetaDataCallback;
vid.attachNetStream( ns );            
//This file we are going to play in the player
ns.play( "trailer.flv" );

When we try to compile the code, we got the below error.

Error #2044: Unhandled NetStatusEvent:. level=error, code=NetStream.Play.StreamNotFound

The reason for the above problem is, file path is not proper. Check for the file name or path for the given flv file. we have given tralier.flv instead of trailer.flv

Possible error codes are :
  • NetStream.Buffer.Empty
  • NetStream.Buffer.Full
  • NetStream.Buffer.Flush
  • NetStream.Play.Start
  • NetStream.Play.Stop
  • NetStream.Seek.InvalidTime
  • NetStream.Seek.Notify



Subscribe to: Posts (Atom)

Popular Posts

AltStyle によって変換されたページ (->オリジナル) /