Method 1
Procedure:
1. Create a New FLASH file and set the stage size to 300*260.
2. Drag the components mediacontroller and mediadisplay to the stage and delete them from the stage. The purpose is to load these two components into the database and prepare for loading the mediacontroller and mediadisplay components to the stage using the attachmovie () method.
3. Create a new layer named function. Enter the followingCode:
Function Init (){
Flagnum = 1;
// Video playback ID
Flvnum = 0;
Attachcontroller ();
};
// Load the mediacontroller and mediadisplay components to the stage and initialize them.
Function attachcontroller (){
// Load the mediadisplay component to the stage and define the Instance name "flvcontainer" + flagnum
_ Root. attachmovie ("mediadisplay", "flvcontainer" + flagnum, 2 );
// Set the initial component parameters
With (_ root ["flvcontainer" + flagnum]) {
_ X = 0;
_ Y = 0;
Setmedia (myarray [flvnum], "FLV"); // you can set the playback format to MP3.
}
// Load the mediacontroller component to the stage and define the Instance name "flvcontroller" + flagnum
_ Root. attachmovie ("mediacontroller", "flvcontroller" + flagnum, 1 );
// Set the initial component parameters
With (_ root ["flvcontroller" + flagnum]) {
_ X = 0;
_ Y = 190;
Activeplaycontrol = false;
Controllerpolicy = "on ";
// Associate the mediacontroller and mediadisplay Components
Associatedisplay (_ root ["flvcontainer" + flagnum]);
};
};
Function playnext (){
// Remove the mediacontroller and mediadisplay components from the stage
_ Root ["flvcontroller" + flagnum]. removemovieclip ();
_ Root ["flvcontainer" + flagnum]. removemovieclip ();
Flagnum + = 1;
Flvnum + = 1;
// If the last video is played, flvnum = 0 indicates that the video will be played from the beginning.
If (flvnum = flvtotal) flvnum = 0;
// Re-load the mediacontroller and mediadisplay components and give a new instance name
Attachcontroller ();
// After each video is played, the mediacontroller and mediadisplay components are detached from the stage.
// Then load the mediacontroller and mediadisplay components again and give another instance name
_ Root ["flvcontainer" + flagnum]. addeventlistener ("complete", mylistener );
};
4. Create a new layer named action. Enter the as code at the first frame of the layer:
Stop ();
// Array myarray is used to store the name of the video in the loaded XML document
VaR myarray = new array ();
// Total number of films
VaR flvtotal: number;
VaR myxml = New XML ();
Myxml. ignorewhite = true;
Myxml. Load ("list. xml ");
Myxml. onload = function (){
VaR E = myxml. firstchild. childnodes;
Flvtotal = E. length;
For (VAR I = 0; I <flvtotal; I ++ ){
Myarray. Push (E [I]. attributes ["title"]);
}
Init ();
_ Root ["flvcontainer" + flagnum]. addeventlistener ("complete", mylistener );
};
VaR mylistener = new object ();
Mylistener. Complete = function (eventobject ){
Playnext ();
};
Use NotePad to write the following content as the playlist and save it as list. xml:
<? XML version = "1.0" encoding = "UTF-8"?>
-<Flvlists>
<Item Title = "http://littleredflowers.com/shipin/yugao.flv"/>
<Item Title = "http://littleredflowers.com/shipin/huaxu-01.flv"/>
<Item Title = "http://littleredflowers.com/shipin/huaxu-02.flv"/>
<Item Title = "http://littleredflowers.com/shipin/huaxu-03.flv"/>
</Flvlists>
Download related source codeClick to download this file
Method 2
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 line of code creates a netstream object myflvstream. during creation
"Provided" connection "to inform it, that is, the myflvconnection object is passed to the netstream class constructor as a parameter.
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.