17 tháng 6, 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.
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
var netStreamStatus = "";
var videoStatus = "loading";
// Create a NetStream object and define an onStatus() function
var netStream:NetStream = new NetStream(netConn);
//status_txt.text += "creating net stream object..." + newline;
netStream.onStatus = function(infoObject) {
//var lvl = infoObject.level;
//var code = infoObject.code;
//if (infoObject.code == "NetStream.Buffer.Full") {
//status_txt.text += newline + "Status (NetStream)" + newline;
//} else {
//status_txt.text += "Status (NetStream)" + newline;
//status_txt.text += "Level: " + lvl + newline;
//status_txt.text += "Code: " + code + newline;
netStreamStatus = infoObject.code;
// Attach the NetStream video feed to the Video object
//status_txt.text += "attach net streaming video" + newline;
// Set the buffer time
//status_txt.text += "set buffer time" + newline;
// Begin playing the FLV file

//status_txt.text += "start streaming play" + newline;
this.onEnterFrame = function() {
if (netStreamStatus == "NetStream.Play.Start") {
var pos = status_txt.text.indexOf("buffering: ");
if(pos>-1) {
status_txt.replaceText(pos, status_txt.length, "buffering: " + netStream.bytesLoaded + " bytes loaded");
videoStatus = "buffering";
} else {
status_txt.text += "buffering: " + netStream.bytesLoaded + " bytes loaded "+ newline;
videoStatus = "buffering";
} else if (netStreamStatus == "NetStream.Buffer.Full") {
if(videoStatus == "buffering") {
status_txt.text += newline + "buffer loaded..." + newline + "playing movie" + newline;
videoStatus = "playing";
//status_txt.text += "video stat: " + videoStatus + newline;
} else if (netStreamStatus == "NetStream.Play.Stop") {
if(videoStatus == "playing") {
status_txt.text += "movie stopped" + newline;
videoStatus = "stopped";
//status_txt.text += "video stat: " + videoStatus + newline;
} else if (netStreamStatus == "NetStream.Buffer.Empty") {
if(videoStatus == "stopped") {
status_txt.text += "buffer empty..." + newline;
videoStatus = "empty";
//status_txt.text += "video stat: " + videoStatus + newline;
-->đọc tiếp...

NetStream.Play.Stop & NetStream.Buffer.Flush

var nc:NetConnection = new NetConnection();
var ns:NetStream = new NetStream(nc);
ns.addEventListener(NetStatusEvent.NET_STATUS, statusHandler);

function statusHandler(e:NetStatusEvent):void {
switch(e.info.code) {
case "NetStream.Play.Stop":
case "NetStream.Buffer.Flush":
-->đọc tiếp...

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)
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 Pro or the Flix Exporter.

Checking for the end of the playback using metadata is quite straightforward. Just add a loop to check if the current playback time is equal to or greater than the duration. You can view the implementation of this method by examining the code on the frame 2 and 3 of the main timeline of the sample movie.

var maxIdle=5;
if (myStreamDuration>0){
if (myDelta<0)myDelta=-myDelta;

if (myDelta<2){
if (myDelta==lastDelta){
if (noStreamMovement>maxIdle){
-->đọc tiếp...

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){
if (info.code == "NetStream.Play.Stop"){
// Set flag, we will need to wait for
// "NetStream.Buffer.Empty" before
// actually restarting the movie.
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){
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 playback buffer to be empty, we should wait for the NetStream.Buffer.Empty event as well. When both conditions are met, then we’re ready to replay the movie.
Second Example:
private function onStatus(object) {
if (object.code == "NetStream.Play.Start") {
// this is invoked when the stream starts playing
} else if(object.code == "NetStream.Buffer.Full") {
// this is invoked when the stream is buffered
} else if(object.code == "NetStream.Play.Stop") {
// rewind and pause on when movie is finished
_timeline.playBut._visible = true;
_timeline.pauseBut._visible = false;
if( _mediaType == "audio" ){
-->đọc tiếp...

Using System.onStatus

Using System.onStatus
System.onStatus = function(InfoObject:Object) {
// your statements
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 Microphone classes also have onStatus handlers but do not pass information objects with a level property of "error". Therefore, System.onStatus is not called if you don't specify a function for these handlers.
The following example shows how to create a System.onStatus function to process information objects when a class-specific onStatus function does not exist:
// Create generic function
System.onStatus = function(genericError:Object){
// Your script would do something more meaningful here
trace("An error has occurred. Please try again.");
The following example shows how to create an onStatus function for an instance of the NetStream class:
// Create function for NetStream object
videoStream_ns.onStatus = function(infoObject:Object) {
if (infoObject.code == "NetStream.Play.StreamNotFound") {
trace("Could not find video file.");
See also
Camera.onStatus, LocalConnection.onStatus, Microphone.onStatus, NetStream.onStatus, SharedObject.onStatus
-->đọc tiếp...

Using NetStream.onStatus

my_ns.onStatus = function(infoObject:Object) : Void{
// Your code here
infoObject A parameter defined according to the status or error message. For more information about this parameter, see "Description," below.
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 activities occur.
- NetStream.Buffer.Empty: Data is not being received quickly enough to fill the buffer. Data flow will be interrupted until the buffer refills, at which time a NetStream.Buffer.Full message will be sent and the stream will begin playing again.
- NetStream.Buffer.Full: The buffer is full and the stream will begin playing.
- NetStream.Play.Start: Playback has started.
- NetStream.Play.Stop: Playback has stopped.
- NetStream.Play.StreamNotFound: The FLV passed to the play() method can't be found.
The following example displays data about the stream in the Output panel:
var connection_nc:NetConnection = new NetConnection();
var stream_ns:NetStream = new NetStream(connection_nc);
//Create a movieclip to store the audio of our netstream
this.createEmptyMovieClip("snd", this.getNextHighestDepth());
//Attach the netstream audio to the newly created symbol
//we can now alter the volume of the netstream by setting the sound level of "audio"
var audio:Sound = new Sound(snd);
audio.setVolume(0); // muted sound
stream_ns.onStatus = function(infoObject:Object) {
trace("NetStream.onStatus called: ("+getTimer()+" ms)");
for (var prop in infoObject) {
See also

Camera.onStatus, LocalConnection.onStatus, Microphone.onStatus, System.onStatus, SharedObject.onStatus
-->đọc tiếp...
BlogWeb: tạo từ Blog của Google
Nội dung: lấy từ nhiều Nguồn khác nhau.
Mục đích: note lại bài Hướng dẫn hay và Đáng đọc.
Kết quả: nghiện Internet Nặng.
Tương lại: xuống lỗ Vẫn Nghiện nếu không có ai giúp.
Blog Web của: Trí Dũng đến từ Việt Nam - Liên kết đến trang Blog Cá Nhân
Tôi biết (^_^)
Thông tin về Tác giả. Chi Tiết
Sử dụng (FireFox | Google Chrome on Ubuntu) để xem tốt nhất. Học Nhiều Hơn Tại Đây
©2009 Google Blogger - HuuNguyen's Home