Flex 4 + red5 streaming media use 2 -- videoplayer control application of flex4

Source: Internet
Author: User

In the following example, I will use red5 as the Streaming Media Server and use the xml configuration file reading technology, mongodobject parameter passing and event passing mechanisms (note: the event itself can store and PASS Parameters ).

Read the configuration file, including the streaming media service connection address and the name of the initialized video.

<? XML version = "1.0" ?>
< Videoconfig >
< Item >
< Rtmpurl > Rtmp: // localhost/oflademo/ </ Rtmpurl >
< Filmname > Ironman. FLV </ Filmname >
</ Item >
</ Videoconfig >

Simple event-class videoevent, which is mainly used to send events and listen to events.

 

Event Type
Package
{
Import Flash. Events. eventdispatcher;
Public   Class Videoevent Extends Eventdispatcher
{
// Static constants, defining event types
Public   Static   Const Vidoplay: String = " Videoplay " ;
// Static instance
Private   Static VaR _ instance: videoevent;
Public   Static Function getinstance (): videoevent
{
If (_ Instance = Null )
_ Instance = New Videoevent ();
Return _ Instance;
}
}
}

Use the main mxml application of the videoplayer ControlProgramCode. First, read the data in the configuration file and initialize the videoplayer control.

 

Videoplayer Control Application
<? XML version = "1.0" encoding = "UTF-8" ?>
< S: Application Xmlns: FX = "Http://ns.adobe.com/mxml/2009"  
Xmlns: S = "Library: // ns.adobe.com/flex/spark"  
Xmlns: MX = "Library: // ns.adobe.com/flex/halo" Width = "500" Height = "500"

Applicationcomplete = "Init ()"
>
< FX: Declarations >
<! -- Place non-visual elements (e.g., services, value objects) here -->
< MX: httpservice ID = "Myservice" URL = "Videoconfig. xml" Result = "Resulthandler (event )" />
</ FX: Declarations >

< FX: script >
<! [CDATA [
Import MX. rpc. Events. resultevent;
Import MX. Controls. Alert;

// Define the video playback event listener object
Public var instance: videoevent = videoevent. getinstance ();

Private var filmsource: String = ""; // Ironman. FLV

Private function Init (): void
{
// Send a request to read the configuration
Myservice. Send ();
// Define a video playback event listener
Instance. addeventlistener ("videoplay", playvideohandler );

}
// Process a video listener
Private function playvideohandler (Event: Event): void
{
VaR myvideo: Export dobject;
// Place the playback header at the beginning of the video
Myvideo = export dobject. getlocal ("videocookie ");
VaR vname: String = myvideo. Data. vname;
// Play the selected video
Film. Source = filmsource + vname;
}
Private function changesource (): void
{
VaR myvideo: Export dobject;
// Place the playback header at the beginning of the video
Myvideo = export dobject. getlocal ("videocookie ");
// Store the video file name in the shared file
Myvideo. Data. vname = "darkknight. FLV ";
// You must store the vcode in the shared object before distributing the event.
Instance. dispatchevent (new event ("videoplay "));
}

// Read the configuration file
Private function resulthandler (Event: resultevent): void
{
// Obtain the streaming media server address
Filmsource = event. Result. videoconfig. item. rtmpurl;
// Obtain the streaming media file name
VaR filmname: String = event. Result. videoconfig. item. filmname;
// Obtain the complete streaming media path
Film. Source = filmsource + filmname;
}
]>
</ FX: script >

< S: videoplayer Width = "396" Height = "294" ID = "Film" />  
< S: button Label = "Change the playback source" Buttondown = "Changesource ()" X = "8" Y = "301" />
</ S: Application >

 

** Note: to use this instance, you must install red5 and start the service.

 

Related Article

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.