[ActionSprit 3.0] FMS接收正在播放的视频中嵌入的描述性信息(onMetaData事件)

  1 package {
  2     import flash.display.MovieClip;
  3     import flash.net.NetConnection;
  4     import flash.events.NetStatusEvent;
  5     import flash.events.MouseEvent;
  6     import flash.events.AsyncErrorEvent;
  7     import flash.net.NetStream;
  8     import flash.media.Video;
  9     import flash.media.Camera;
 10     import flash.media.Microphone;
 11     import fl.controls.Button;
 12     import fl.controls.Label;
 13     import fl.controls.TextArea;
 14
 15
 16     public class Metadata extends MovieClip {
 17         private var nc:NetConnection;
 18         private var ns:NetStream;
 19         private var nsPlayer:NetStream;
 20         private var vid:Video;
 21         private var vidPlayer:Video;
 22         private var cam:Camera;
 23         private var mic:Microphone;
 24         private var clearBtn:Button;
 25         private var startPlaybackBtn:Button;
 26         private var outgoingLbl:Label;
 27         private var incomingLbl:Label;
 28         private var myMetadata:Object;
 29         private var outputWindow:TextArea;
 30
 31         public function Metadata(){
 32             setupUI();
 33             nc = new NetConnection();
 34             nc.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
 35             nc.connect("rtmp://localhost/publishlive");
 36         }
 37
 38         /*
 39          *  Clear the MetaData associated with the stream
 40          */
 41         private function clearHandler(event:MouseEvent):void {
 42             if (ns){
 43                 trace("Clearing MetaData");
 44                 ns.send("@clearDataFrame", "onMetaData");
 45             }
 46         }
 47
 48         private function startHandler(event:MouseEvent):void {
 49             displayPlaybackVideo();
 50         }
 51
 52         private function onNetStatus(event:NetStatusEvent):void {
 53             trace(event.target + ": " + event.info.code);
 54             switch (event.info.code)
 55             {
 56                 case "NetConnection.Connect.Success":
 57                     publishCamera();
 58                     displayPublishingVideo();
 59                     break;
 60             }
 61         }
 62
 63         private function asyncErrorHandler(event:AsyncErrorEvent):void {
 64             trace(event.text);
 65         }
 66
 67         private function sendMetadata():void {
 68             trace("sendMetaData() called")
 69             myMetadata = new Object();
 70             myMetadata.customProp = "This message is sent by @setDataFrame.";
 71             ns.send("@setDataFrame", "onMetaData", myMetadata);
 72         }
 73
 74         private function publishCamera():void {
 75             cam = Camera.getCamera();
 76             mic = Microphone.getMicrophone();
 77             ns = new NetStream(nc);
 78             ns.client = this;
 79             ns.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
 80             ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
 81             ns.attachCamera(cam);
 82             ns.attachAudio(mic);
 83             ns.publish("myCamera", "record");
 84             sendMetadata();
 85
 86         }
 87
 88         private function displayPublishingVideo():void {
 89             vid = new Video(cam.width, cam.height);
 90             vid.x = 10;
 91             vid.y = 10;
 92             vid.attachCamera(cam);
 93             addChild(vid);
 94         }
 95
 96         private function displayPlaybackVideo():void {
 97             nsPlayer = new NetStream(nc);
 98             nsPlayer.client = this;
 99             nsPlayer.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
100             nsPlayer.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
101             nsPlayer.play("myCamera", 1);
102             vidPlayer = new Video(cam.width, cam.height);
103             vidPlayer.x = cam.width + 100;
104             vidPlayer.y = 10;
105             vidPlayer.attachNetStream(nsPlayer);
106             addChild(vidPlayer);
107         }
108
109         private function setupUI():void {
110             outputWindow = new TextArea();
111             outputWindow.move(250, 175);
112             outputWindow.width = 250;
113             outputWindow.height = 150;
114
115             outgoingLbl = new Label();
116             incomingLbl = new Label();
117             outgoingLbl.width = 150;
118             incomingLbl.width = 150;
119             outgoingLbl.text = "Publishing Stream";
120             incomingLbl.text = "Playback Stream";
121             outgoingLbl.move(30, 150);
122             incomingLbl.move(300, 150);
123
124             startPlaybackBtn = new Button();
125             startPlaybackBtn.width = 150;
126             startPlaybackBtn.move(250, 345)
127             startPlaybackBtn.label = "View Live Event";
128             startPlaybackBtn.addEventListener(MouseEvent.CLICK, startHandler);
129
130             clearBtn = new Button();
131             clearBtn.width = 100;
132             clearBtn.move(135,345);
133             clearBtn.label = "Clear Metadata";
134             clearBtn.addEventListener(MouseEvent.CLICK, clearHandler);
135
136             addChild(clearBtn);
137             addChild(outgoingLbl);
138             addChild(incomingLbl);
139             addChild(startPlaybackBtn);
140             addChild(outputWindow);
141         }
142
143         public function onMetaData(info:Object):void {
144             var key:String;
145             for (key in info){
146                 outputWindow.appendText(key + ": " + info[key] + "\n");
147             }
148         }
149         public function onTimeCoordInfo(info:Object):void{
150             for (var key:String in info){
151                 trace(key + ": " + info[key] + "\n");
152             }
153         }
154     }
155 }
时间: 2024-11-01 18:05:51

[ActionSprit 3.0] FMS接收正在播放的视频中嵌入的描述性信息(onMetaData事件)的相关文章

[ActionSprit 3.0] FMS直播

音视频流的发布(服务器) 1 package 2 { 3 import flash.display.Sprite; 4 import flash.events.NetStatusEvent; 5 import flash.media.Camera; 6 import flash.media.Microphone; 7 import flash.net.NetConnection; 8 import flash.net.NetStream; 9 import flash.net.ObjectEnc

[ActionSprit 3.0] FMS服务器带宽检测

1 package { 2 3 import flash.display.Sprite; 4 import flash.net.NetConnection; 5 import flash.events.NetStatusEvent; 6 import flash.events.AsyncErrorEvent; 7 8 /** 9 * @author Frost.Yen 10 * @E-mail [email protected] 11 * @create 2015-7-16 上午10:02:15

[ActionSprit 3.0] FMS安装与测试

1.运行Flash Media Server4.5.exe,安装选项可全默认,序列号可不填:输入用户名和密码需记住,登录时要用. 2.安装完成,在安装目录C:\Program Files\Adobe\Flash Media Server 4.5\tools\下找到fms_adminConsole.htm或者fms_adminConsole.swf,这是管理文件,打开其中之一填入相应信息登录,Server Address 填本机ip,如192.168.3.106,Username和Password

[ActionSprit 3.0] FMS客户端与服务器端交互(传参)

客户端as: 1 import flash.net.NetConnection; 2 import flash.events.NetStatusEvent; 3 4 var nc:NetConnection = new NetConnection(); 5 nc.addEventListener(NetStatusEvent.NET_STATUS,onStatus); 6 nc.connect("rtmp://localhost/HelloWorld","小明");

[ActionSprit 3.0] FMS远程共享

1 package 2 { 3 import flash.display.Sprite; 4 import flash.events.NetStatusEvent; 5 import flash.events.SyncEvent; 6 import flash.net.NetConnection; 7 import flash.net.SharedObject; 8 import flash.text.TextField; 9 10 /** 11 * @author Frost.Yen 12 *

手机影音第十一天,显示视频缓冲,显示卡顿时的网速,播放系统视频时调用播放器的选择

代码已经托管到码云,有兴趣的小伙伴可以下载看看 https://git.oschina.net/joy_yuan/MobilePlayer 一.设置视频缓冲进度 显示视频播放进度的效果图如下:灰色的是缓冲的进度. 原理:只有播放网络视频时,才有缓冲这个说法,所以要先判断视频资源是否为网络资源 /**  * 判断是否是网络的资源  * @param uri  * @return  */ public boolean isNetUri(String uri) {     boolean reault

cocos2d-x 3.0 播放MP4视频

猴子原创,欢迎转载. 转载请注明: 转载自Cocos2D开发网–Cocos2Dev.com,谢谢. 原文地址: http://www.cocos2dev.com/?p=545 非常久曾经写的一个2dx播放MP4视频的教材.有网友反映已经不能用了,今天晚上写了个简单的2dx播放视频类.使用的是cocos2dx 3.0. 类说明:LHVideoPlayerImplCpp.h/mm // cocos2dx中使用的播放MP4接口LHVideoPlayerImpl.h/m // videoPlayer的o

vue2.0+vue-dplayer实现hls播放

vue2.0+vue-dplayer实现hls播放 开始 安装依赖 npm install vue-dplayer -S 1,编写组件HelloWorld.vue <template> <div class="hello"> <d-player ref="player" @play="play" :logo="logo" :lang="lang" :video="vi

SRS之播放推流视频

1. 综述 首先,推流直播的配置文件如下: # rtmp.conf listen 1935; max_connections 1000; daemon off; srs_log_tank console; vhost __defaultVhost__ { } 搭建的简陋直播步骤如下: 启动 srs:./obj/srs -c ./conf/rtmp.conf; 设置并开启 obs 推流,obs 的视频来源随便,可以直接是视频获取设备或本地文件,此外 obs 的设置如下图: 注:必须填 "流名称&q