看过网上很多帖子都在问如何在FMS服务器端进行stream广播,在客户端进行侦听,发现可以这样实现。
main.asc:
AS代码
|
client.fla:
AS代码
- import flash.display.Sprite;
- import flash.events.NetStatusEvent;
- import flash.events.SecurityErrorEvent;
- import flash.media.Video;
- import flash.net.NetConnection;
- import flash.net.NetStream;
- import flash.events.Event;
- import flash.net.Responder;
- import flash.net.ObjectEncoding;
- var videoURL:String = “stream/test”;
- var connection:NetConnection;
- var stream:NetStream;
- connection = new NetConnection();
- connection.objectEncoding=ObjectEncoding.AMF0;
- connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
- connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
- connection.connect(“rtmp://localhost/serverPublih”);
- function netStatusHandler(event:NetStatusEvent):void {
- switch (event.info.code) {
- case “NetConnection.Connect.Success” :
- trace(“connect success!!!”);
- connectStream();
- break;
- case “NetStream.Play.StreamNotFound” :
- trace(“Stream not found: ” + videoURL);
- break;
- }
- }
- function securityErrorHandler(event:SecurityErrorEvent):void {
- trace(“securityErrorHandler: ” + event);
- }
- function connectStream():void {
- stream= new NetStream(connection);
- stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
- var video:Video = new Video();
- video.attachNetStream(stream);
- addChild(video);
- connection.call(“playStream”,new Responder(onResult));
- }
- function onResult(para:*):void {
- trace(“para:”+para);
- stream.play(“37studio”);
- stream.seek(para);
- return;
- }