Play FLV videos in Flash

Source: Internet
Author: User
Tags flv file

Using actionscript3.0 scripts to play FLV videos requires collaboration of a series of classes:
You need a netstream object to load videos and control video playback;
However, the netstream class only processes flow data and does not process data display. Therefore, a video object needs to use netstream data to display videos on the screen.
The netstream constructor requires a netconnection object as the parameter. This object determines the source of video data. If Flash video comes from a Flash Communication Server or Flash Media Server, the netconnection object is directed to the corresponding server. However, if it is downloading and playing, you can use a null connection string.

Create a connection object:

VaR videoconnection: netconnection = new netconnection ();
Videoconnection. Connect (null );

Create a data stream management object:

VaR videostream: netstream = new netstream (videoconnection );

Create a video object and display:

VaR video: Video = new video ();
Addchild (video );

Associated data stream:

video.attachNetStream(videoStream);

Start playing:

Videostream. Play ("example. FLV ");

Adjust the volume:

Use the soundtransform attribute of the netstream object to adjust the volume;

Playback time:

Use the time attribute of the netstream object to obtain the time when the video has been played. the time elapsed since the start of playback, in seconds, is read-only and cannot be modified.

Video read duration:

Netstream does not provide the direct Duration Attribute, but the duration data segment in the FLV file provides the duration information. The onmetadata () method is automatically called when the netstream object loads the FLV file, and the information in the FLV file is generally read in the onmetadata method. The following code uses the trace statement to output the duration information in the debugging window.

Control the playback point:

The seek () method of the netstream object is used to locate the video playing position based on the provided parameters. However, the parameters set during real-time download cannot exceed the buffer length.

Zoom video:

The videowidth and videoheight attributes of the video object are read-only and the display size of the current video is returned. to modify the video object size, you can change the width and height attributes of the video object.

Set buffering:

You can use the buffertime attribute of the netstream object to set the length of the video to be buffered before playing the video. That is, you must buffer enough buffertime data before playing the video. If this parameter is not set, the default value is 0.1 s. Bufferlength is a read-only attribute of netstream. It returns the buffered data length. Therefore, bufferlenght/buffertime is used to display the buffered ratio. The bytesloaded and bytestotal attributes of the netstream object display the total length of downloaded video files.

Add filter effect:

Use the filters attribute of the video object to set the video display effect.

Pause:

Use the pause () function of the netstream object to pause playback.

Stop:

Use the close () function of the netstream object to stop playing the video. By default, the cache is clear. If you want to play the video again, you need to download it again, however, if data is cached in the browser, the content cached in the browser may be played. You can use the following method to download and play the content again:

Videostream. Play ("video. FLV? Uniqueindex = "+ (new date (). gettime ());

Clear display:

When you close a netstream object, the video object does not automatically clear the screen and keeps the last frame of the image. Only when you delete the video object or call the clear () method to clear the screen.

var client:Object = new Object(  );client.onMetaData = function(metadata:Object):void {    trace(metadata.duration);};videoStream.client = client;

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.