Bài đăng

Đang hiển thị bài đăng từ tháng 6 15, 2008

Three things in order to run video flv:

1. Create blank new flash file. Open library, add "New video" object to library, then add it to stage with the instance name "my_video". 2. Create new layer with a multy-line input text field w/ a border that lies above the "blank video object". The instance name of the txt object must be: "status_txt" 3. Add script written below to the first frame of the flash movie. Save flash movie with the name you want + put following FLV file (videoFile.flv) in the same directory where you're going to execute SWF for streaming. ****************************Code************************************ status_txt.text += "initialize streaming engine" + newline; // Create a NetConnection object var netConn:NetConnection = new NetConnection(); status_txt.text += "creating net connection object..." + newline; // Create a local streaming connection netConn.connect(null); var netStreamStatus = ""; var videoStatus = "loading";...

NetStream.Play.Stop & NetStream.Buffer.Flush

var nc:NetConnection = new NetConnection(); nc.connect(null); var ns:NetStream = new NetStream(nc); video.attachNetStream(ns); ns.play("video1.flv"); ns.addEventListener(NetStatusEvent.NET_STATUS, statusHandler); function statusHandler(e:NetStatusEvent):void { trace(e.info.code); switch(e.info.code) { case "NetStream.Play.Stop": break; case "NetStream.Buffer.Flush": break; } }

Using metadata to detect end of the movie and then loop

Beginning with FLV version 1.1, Macromedia has added a metadata section into a FLV file. The metadata contains the duration of the FLV, among other things. We can use the duration information to check whether a movie has reached the end of playback. Note that not all FLV files have metadata (you will need to use software that supports metadata to create the FLV). We can retrieve the duration information by using the following code (frame 1 of the main timeline of the sample movie): myStream.onMetaData = function(obj) { myStreamDuration=obj.duration; trace("metadata duration="+myStreamDuration); } If the FLV has metadata, the code snippet above will show the duration of the FLV. You can use the Flix Pro 4 FLV to SWF Converter to check for the presence of metadata – if the FLV has no metadata, Flix will show: “[Flv has no metadata]”. If your FLV does not have metadata information, it is recommended that you re-encode the FLV with programs that supports metadata, such as Flix Pr...

Using the onStatus event handler to detect the end of the FLV playback and then loop

onStatus is a method of the NetStream class. To check for the end of FLV playback, we can override it. You can view the implementation of this method by examining the onStatus function on frame 1 of the main timeline of the sample movie. myStream.onStatus = function(info){ trace("info="+info.code); if (info.code == "NetStream.Play.Stop"){ // Set flag, we will need to wait for // "NetStream.Buffer.Empty" before // actually restarting the movie. stopped=true; } if (info.code == "NetStream.Buffer.Empty"){ // At this point, the movie has stopped, and // the buffer is empty. // We're ready to restart the movie. if (stopped){ myStream.seek(0) myStream.play(videoUrl); stopped=false; }}} Here we need to check if the event being sent is NetStream.Play.Stop . When you receive NetStream.Play.Stop , it means that the movie has stopped playing. Note however, because Flv playback has a tendency to freeze when you start a movie without waiting for the playb...

Using System.onStatus

Using System.onStatus Usage System.onStatus = function(InfoObject:Object) { // your statements } Description Event handler: provides a super event handler for certain objects. The LocalConnection, NetStream, and SharedObject classes provide an onStatus event handler that uses an information object for providing information, status, or error messages. To respond to this event handler, you must create a function to process the information object, and you must know the format and contents of the returned information object. In addition to these specific onStatus methods, Flash also provides a super function called System.onStatus, which serves as a secondary error message handler. If an instance of the LocalConnection, NetStream, or SharedObject class passes an information object with a level property of "error", but you have not defined an onStatus function for that particular instance, then Flash uses the function you define for System.onStatus instead. Note: The Camera and...

Using NetStream.onStatus

Usage my_ns.onStatus = function(infoObject:Object) : Void{ // Your code here } Parameters infoObject A parameter defined according to the status or error message. For more information about this parameter, see "Description," below. Returns Nothing. Description Event handler; invoked every time a status change or error is posted for the NetStream object. If you want to respond to this event handler, you must create a function to process the information object. The information object has a code property containing a string that describes the result of the onStatus handler, and a level property containing a string that is either status or error. In addition to this onStatus handler, Flash also provides a "super" function called System.onStatus. If onStatus is invoked for a particular object and there is no function assigned to respond to it, Flash processes a function assigned to System.onStatus if it exists. The following events notify you when certain NetStream ac...