Many people may not be able to find a simple and complete flvplayer. I have not been able to find it for a long time at the beginning. Then I asked my friends to help me create an interface and add it myself. Code After that, I think it is okay. I am not dedicated here. I will share the source code with you for your reference.
To create a flvplayer, first you need to understand the working directory of fms2. Its working directory is under the application directory of the installation directory. You need to create a new directory as your work directory.
For example, if I create a new gdrc, and then create a new streams directory in gdrc (this directory name cannot be changed), all subdirectories under the streams will be your application.
. The default value is _ definst _. for better management, I have created the FLV file for video placement and audio for audio placement. In this way, my directory structure is:
Applications/gdrc/streams/video, applications/gdrc/streams/audio,
Applications/gdrc/streams/_ definst _. All FLV files for format conversion mentioned in the previous article are stored in
Applications/streams/video directory.
Then, let's take a look at my flvplayer. I developed it with Flash 8 and only need a few simple components, the video component, play button, pause button, stop button, and timeline plus the following code is a flvplayer. In the first region, write the following code:
stop ();
var play_status = false; // video playback flag, true-playing; false-not playing
var connect_url = "rtmp: // 172.16.1.2/gdrc/video "; // connection mode rtmp, note that the connection/gdrc/video corresponds to the above-mentioned FLV directory applications/gdrc/streams/video.
var FLV = stream; // dynamic FLV. The external domain name is better than play.swf? Stream = A indicates playing. FLV, parameter not required. FLV extension name
var NC: netconnection = new netconnection ();
var ns: netstream;
NC. connect (connect_url);
var streamlength; // FLV file length
bt_pause. _ visible = false; // the pause button is invisible.
var startbf = 2; // The Start Buffer seconds.
var mainbf = 6; // buffer seconds when null
// Initialization
Initstreams = function (){
NS = new netstream (NC );
NS. setbuffertime (startbf );
Video. attachvideo (NS); // attaches the ns to the video component.
NS. onstatus = onstatus; // Dynamic Buffer
};
// Dynamic Buffer, 3 seconds when the buffer is full, and 10 seconds when the buffer is empty
Function onstatus (infoobject: Object ){
Trace (infoobject ["code"]);
If (infoobject ["code"] = "netstream. Buffer. Full "){
NS. setbuffertime (startbf );
}
If (infoobject ["code"] = "netstream. Buffer. Empty "){
NS. setbuffertime (mainbf );
}
}
// Test the connection
NC. onstatus = function (Info ){
Trace (info. Code );
Switch (info. Code ){
Case "netconnection. Connect. Success": initstreams (); break;
}
}
// Buffer
Function checkbuffertime (NS: netstream): void {
VaR bufferpct: Number = math. Min (math. Round (NS. bufferlength/ns. buffertime * 100), 100 );
If (isnan (bufferpct )){
Bufferpct = 0;
}
Buffer_txt = "buffer:" + bufferpct + "% ";;
};
// Obtain the file length. To obtain the length, you must support the server. Compile main. asc on the fms2 server.
Function filelength (){
This. onresult = function (retval ){
Streamlength = retval;
};
};
// Play
Doplay = function (){
If (play_status = false ){
Bar. Ball. _ x = 0;
Play_status = true;
NS. Play (FLV );
// Playback progress bar
Bar. onenterframe = function (){
NC. Call ("getfilelength", new filelength (), FLV );
VaR nowplaypercent = math. Round (NS. Time/streamlength * 100 );
If (isnan (nowplaypercent )){
Bar. Ball. _ x = 0;
}
Else {
Bar. Ball. _ x = nowplaypercent * 490/100;
}
If (nowplaypercent = 99 ){
Play_status = false;
Bar. Ball. _ x = 0;
Bt_play. _ visible = true;
Bt_pause. _ visible = false;
// Ns. Close ();
Delete this. onenterframe;
}
};
// Buffer prompt
VaR buffer_interval: Number = setinterval (checkbuffertime, 100, NS );
}
Else {
NS. Pause ();
}
};
// Pause
Dopause = function (){
NS. Pause ();
};
// Stop
Dostop = function (){
Play_status = false;
Bar. Ball. _ x = 0;
// Ns. Seek (0 );
// Ns. Pause (true );
NS. Close ();
};
// Start playing
Playnow. onrelease = function (){
Bt_play. _ visible = false;
Bt_pause. _ visible = true;
Doplay ();
};
// Play button
Bt_play.onrelease = function (){
Bt_play. _ visible = false;
Bt_pause. _ visible = true;
Doplay ();
};
// Pause button
Bt_pause.onrelease = function (){
Bt_play. _ visible = true;
Bt_pause. _ visible = false;
Dopause ();
};
// Stop button
Bt_stop.onrelease = function (){
Bt_play. _ visible = true;
Bt_pause. _ visible = false;
Dostop ();
};
Main. ASC, which is placed in the applications/gdrc directory of the fms2 installation directory
Load ("components. ASC ");
Application. onappstart = function (){};
Application. onconnect = function (client ){
Application. acceptconnection (client );
Client. getfilelength = function (filename ){
VaR tlen = stream. Length (filename );
Return tlen;
};
};