Make a full featured FLV player _flash Tutorial

Source: Internet
Author: User
Tags setinterval time interval flv file
This article is selected from the "Flash MX Professional 2004 First Step" book
Author Chen Bing

To create a fully functional FLV player

This FLV player we will make consists of several parts:
A video object for displaying a video image,
Three buttons to play, pause, and stop the video, respectively,
and a dynamic text to display the progress of the buffer mount.

1. Create three button symbols, named "Play", "pause", "Stop", and drag each instance to the scene stage, respectively.

2. Create a video symbol, drag one instance of it to the scene stage, and give its instance name Myvideo.

3. Place a dynamic text in the scene stage, giving its instance name mytext.

4. Bundle the following script in frame 1th of the root timeline:

Copy Code code as follows:

Creates a Netconnection object.
Myflvconnection=new netconnection ();
Create a stream connection.
Myflvconnection.connect (NULL);
Creates a NetStream object.
Myflvconnection is assigned to the NetStream object.
Myflvstream=new NetStream (myflvconnection);
Myflvstream is bundled to the video object Myvideo:
Myvideo.attachvideo (Myflvstream);
Set the buffer time.
Myflvstream.setbuffertime (10);
To parse 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, at the call Connect () method, you must pass it a null value as an argument.

Next, I took advantage of Myflvstream=new NetStream (myflvconnection), which created a NetStream object myflvstream, which I needed to tell the "connection" provided for the stream at the time of creation. That is, the Myflvconnection object is passed as a parameter to the constructor of the NetStream class.
After that, I bundled the 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, to load the data in the buffer for how long it will be played before it starts playing.

5. Bundle the following script on the "Play" button instance:

Copy Code code as follows:

On (release) {
Mounts and plays the FLV file.
Myflvstream.play ("myflv.flv");

Define the Bufferload function for setinterval function calls to display the buffering progress.
function Bufferload () {
Displays the load progress of the buffer in dynamic text.
mytext.text= "Buffer Loaded" +int ((myflvstream.bytesloaded/myflvstream.bytestotal) *100) + "%";
}
Sets the time interval.
SetInterval (bufferload,20);
}
This line of code-myflvstream.play ("myflv.flv"), and is used to load and play the FLV file. If your FLV file is somewhere in an HTTP address or local filesystem, you can use a format such as http://or file://to prefix the path to specify the location of the FLV file.
This expression-myflvstream.bytesloaded/myflvstream.bytestotal is used to check the ratio of bytes loaded by the buffer to the total bytes to be loaded by the buffer. Bytesloaded and Bytestotal are two properties of the NetStream class.

6. Bundle the following script on the pause button instance:

Copy Code code as follows:

On (release) {
Pauses the FLV file.
Myflvstream.pause ();
}
7. Bundle the following script on the Stop button instance:

On (release) {
Stops the FLV file and deletes the downloaded FLV file at the same time.
Myflvstream.close ();
}
8. Complete the production. You should test this FLV player on your site.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.