Flash external loading FLV (1)

Source: Internet
Author: User

Package <br/> {<br/> Import flash. media. *; <br/> Import flash. events. *; <br/> Import flash.net. *; <br/> Import flash. display. sprite; <br/> Import fvideo; </P> <p> public class flvplayer extends eventdispatcher <br/>{< br/> private var video: flvideo; <br/> private var playhead: Number = 0; <br/> private var loaded: Boolean = false; <br/> private var loops: int; <br/> private var stream: netstream; <br/> private var autop Lay: Boolean = false; <br/> private var videourl: String = NULL; <br/> Public var contain: SPRITE = new sprite (); <br/> private var sound: soundtransform = new soundtransform (); <br/> Public Function flvplayer (loops: Int = 1, starttime: Number = 0) <br/>{< br/> super (); <br/> playhead = starttime; <br/> loops = loops; <br/> Init (); <br/>}< br/> private function Init (): void <br/>{< br/> Video = new flvideo (); <br/> var connection: Net Connection = new netconnection (); <br/> connection. connect (null); <br/> stream = new netstream (connection); <br/> trace (stream. soundtransform. volume); <br/>}< br/> Public Function load (URL: String = NULL, AutoPlay: Boolean = false, bufferseconds: Number = 1 ): void <br/> {<br/> If (video. url = NULL & percentloaded = 0) <br/>{< br/> video. url = URL; <br/> autoplay = autoplay; <br/> video. attachnetstream (Stream); <br/> contai N. addchild (video); // Add a container <br/> stream. buffertime = bufferseconds; // set the buffer time <br/> stream. addeventlistener (netstatusevent. net_status, netstatushandler); <br/> stream. addeventlistener (asyncerrorevent. async_error, netasyncerrorhandler); <br/>}< br/> // Add multiple videos for management <br/> Public Function add (URL: string ): void <br/>{</P> <p >}< br/> private function netstatushandler (Event: netstatusevent): void <br/>{< br/> switch (Event.info. code) <br/> {<br/> case "netconnection. connect. success ": <br/> break; <br/> case" netstream. play. streamnotfound ": <br/> throw new error (" error "); <br/> break; </P> <p> case" netstream. play. stop ": <br/> stream. seek (0); <br/> break; </P> <p >}< br/> private function netasyncerrorhandler (Event: asyncerrorevent ): void <br/>{</P> <p >}< br/>/* <br/> @ buffertime sets the buffer time <br/> @ bufferlength the data currently exists in the buffer zone in seconds Number. <Br/> @ <br/> */<br/> Public Function get bufferlength (): number <br/> {<br/> return stream. bufferlength; <br/>}< br/> public function set buffertime (Time: Number): void <br/>{< br/> stream. buffertime = time; <br/>}< br/> Public Function get buffertime (): number <br/>{< br/> return 0; <br/>}< br/> Public Function get fvideo (): Video <br/>{< br/> return video; <br/>}< br/> // set and return the video playback position (in time) <br/> Public functi On get position (): number <br/>{< br/> return stream. time; <br/>}< br/> public function set position (Time: Number): void <br/>{< br/> stream. seek (time ); <br/>}< br/>/* <br/> @ sets and returns the video sound size <br/> */<br/> Public Function get volume (): number <br/> {<br/> var volumes: Number = sound. volume; <br/> stream. soundtransform = sound; <br/> return volumes; <br/>}< br/> public function set volume (Volumes: Number): void <br/> {<B R/> sound. volume = volumes; <br/> stream. soundtransform = sound; <br/>}</P> <p> // obtain the total time of the returned video. <br/> Public Function get totaltime (): number <br/>{< br/> return 0; <br/>}< br/> // check whether the video is playing <br/> Public Function get playing (): boolean <br/>{< br/> return true; <br/>}< br/> // return the loading progress <br/> Public Function get percentloaded (): number <br/> {<br/> var percent: Number = stream. bytesloaded/stream. bytestotal; <br/> return ISNA N (percent )? 0: percent; <br/>}< br/>/* <br/> @ The following is the video playback control interface <br/>@< br/> @ <br/> */<br/> // play the video <br/> public function play (): void <br/>{< br/> If (video. URL! = NULL) <br/>{< br/> stream. play (video. URL); <br/>}< br/> // replay <br/> Public Function replay (): void <br/>{</P> <p >}< br/> // suspend <br/> Public Function pause (): void <br/>{< br/> stream. pause (); <br/>}< br/> // close <br/> public function close (): void <br/>{< br/> stream. close (); <br/>}< br/> // playback <br/> Public Function togglepause (): void <br/>{< br/> stream. togglepause (); <br/>}< br/> // clear the video <br/> Public Function clear (): void <br/>{< br/> video. clear (); <br/>}< br/> Public Function Resume (): void <br/>{< br/> stream. resume (); <br/>}< br/> // sets whether the video is smooth. <br/> public function set smoothing (FLAG: Boolean ): void <br/>{< br/> video. smoothing = flag; <br/>}< br/> // set the video height and width <br/> Public Function get videoheight (): int <br/> {<br/> return video. videoheight; <br/>}< br/> public function set videoheight (Height: INT): void <br/>{< br/> video. height = height; <br/>}< br/> Public Function get videowidth (): int <br/>{< br/> return video. videowidth; <br/>}< br/> public function set videowidth (width: INT): void <br/>{< br/> video. width = width; <br/>}< br/>}

First, encapsulate a class for external video loading, because this class can continue to improve. I have written the first version for the time being. If you are interested, you can increase your requirements and continue to improve it. I will modify it later. Continue to improve

 

Package <br/> {<br/> Import flash. media. video; <br/> Import flash. events. *; <br/> public class flvideo extends video <br/>{< br/> Public var URL: String = NULL; <br/> Public Function flvideo () <br/>{</P> <p >}< br/>}</P> <p>}

 

Expand video to add a connection. Used to record the video address.

 

The following is the test source code: You can set the sound

 Player = new flvplayer (); <br/> addchild (player. contain); <br/> player. load ("1.flv", true); <br/> player. play (); <br/> player. volume = 0.1; <br/> trace ("sound" + player. volume); <br/> player. videowidth = 550; <br/> player. videoheight = 350;

 

If you want to play the video, add player. Play.

You can set the flvplayer class attributes when setting the sound size. Some of the functions in the class have not been implemented yet.

 

Version 1.0 implements the External Loading Function

Set sound,

Video width and height

Progress, set the buffer time,

Basic functions such as video control

Obtains the current video time.

 

The multi-list playback function is not implemented, the multi-list playback function is added, and the total video time is obtained.

Later versions will use the air program for development. Hope to improve

 

 

 

 

 

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.