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.