Create a full-featured flvplayer
The flvplayer we made consists of the following parts:
A video object used to display video images,
Three buttons are used to play, pause, and stop a video respectively,
And a dynamic text used to display the buffer loading progress.
1. Create three button components, named "play", "pause", and "stop" respectively, and drag and drop one of their instances to the scene stage.
2. Create a video component, drag an instance to the scene stage, and assign its instance name myvideo.
3. Place a dynamic text on the scene stage and assign its instance name mytext.
4. Bind The following script to the 1st frame of the root timeline:
// Create a netconnection object.
Myflvconnection = new netconnection ();
// Create a stream connection.
Myflvconnection. Connect (null );
// Create a netstream object.
// Myflvconnection is specified to the netstream object.
Myflvstream = new netstream (myflvconnection );
// Myflvstream is bound to the video object myvideo:
Myvideo. attachvideo (myflvstream );
// Set the buffer time.
Myflvstream. setbuffertime (10 );
After analyzing this script, I first created a netconnection object myflvconnection, and then I called the connect () method of the netconnection object to open a stream connection () you must pass it a null value as a parameter.
Next, I will use myflvstream = new netstream (myflvconnection); this lineCodeA netstream object myflvstream is created. When creating a netstream object, I need to inform it of the "connection" provided for the "stream, that is, the myflvconnection object is passed as a parameter to the constructor of the netstream class.
Then, I bound myflvstream ("stream") to the video object myvideo. Then, I also used the setbuffertime () method of the netstream class to specify a buffer time in seconds, that is, how long the data can be played in the buffer before playing.
5. Bind The following script to the "play" button instance:
On (release ){
// Load and play FLV files.
Myflvstream. Play ("myflv. FLV ");
// Define the bufferload function for the setinterval function to display the buffer progress.
Function bufferload (){
// Display the buffer loading progress in dynamic text.
Mytext. Text = "buffer loaded" + int (myflvstream. bytesloaded/myflvstream. bytestotal) * 100) + "% ";
}
// Set the interval.
Setinterval (bufferload, 20 );
}
This line of code-myflvstream. Play ("myflv. FLV"); is used to load and play FLV files. If your FLV file is located at an HTTP address or somewhere in the local file system, you can use http: // or file: // use this format as the path prefix to specify the location of the FLV file.
This expression-myflvstream. bytesloaded/myflvstream. bytestotal is used to check the ratio of byte loaded in the buffer zone to the total byte to be loaded in the buffer zone. Bytesloaded and bytestotal are two attributes of the netstream class.
6. Bind The following script to the pause button instance:
On (release ){
// Pause the FLV file.
Myflvstream. Pause ();
}
7. Bind The following script to the "stop" button instance:
On (release ){
// Stop the FLV file and delete the downloaded FLV file.
Myflvstream. Close ();
}
8. production is complete. You should test the flvplayer on your website.