FMS3系列(四):在线视频录制、视频回放
2009-04-30 12:06:55 来源:WEB开发网在录制视频的时候视频命名是取的文本输入框的值作为视频名,OK,现在测试Flash(Ctrl+Enter),通过点击 按扭开始录制视频。通过查看FMS服务器的文件目录可以看到,刚刚测试录制的视频存放于FMS服务器应用下的streams/_definst_目录下。详见下图所示:
录制功能完成了,通过测试也可以成功的录制视频。最后我们通过程序来播放刚刚录制是视频。关于播放视频在上一篇文章《FMS3系列(三):基于FMS的流媒体播放程序》中已介绍怎么实现,这里就直接帖出代码不做解释。
以下为引用的内容:
1 private function onPlayHandler(evt:MouseEvent):void
2 {
3 nc=new NetConnection();
4 nc.addEventListener(NetStatusEvent.NET_STATUS,onPlayStatusHandler);
5 nc.connect("rtmp://localhost/PulishedStreams");
6 }
7
8 private function onPlayStatusHandler(evt:NetStatusEvent):void
9 {
10 if(evt.info.code=="NetConnection.Connect.Success")
11 {
12 ns=new NetStream(nc);
13 ns.addEventListener(NetStatusEvent.NET_STATUS,onPlayStatusHandler);
14 ns.client=new CustomClient();
15
16 video = new Video();
17 video.attachNetStream(ns);
18 ns.play(tbName.text,0);
19 addChild(video);
20 }
21 }
通过本文的基础上可以很方便的扩展出在线拍照等多种应用,有兴趣的朋友可以去试验下。下面是本文完整的示例代码。
以下为引用的内容:
1package
2{
3 import flash.net.*;
4 import flash.events.*;
5 import flash.media.*;
6 import flash.display.*;
7 import fl.controls.*;
8
9 public class PublishPlay extends Sprite
10 {
11 private var nc:NetConnection;
12 private var ns:NetStream;
13 private var video:Video;
14 private var cam:Camera;
15 private var mic:Microphone;
16
17 public function PublishPlay():void
18 {
19 lbName.text="请输入视频文件名:";
20 btnPublish.label="开始录制";
21 btnPublish.addEventListener(MouseEvent.CLICK,onPublishClick);
22 btnStop.label="停止录制";
23 btnStop.addEventListener(MouseEvent.CLICK,onStopHandler);
24 btnPlay.label="视频回放";
25 btnPlay.addEventListener(MouseEvent.CLICK,onPlayHandler);
26
27 video=new Video();
28 cam = Camera.getCamera();
29 mic = Microphone.getMicrophone();
30 if(cam==null)
31 {
32 trace("没检测到视频摄像头");
33 }
34 else
35 {
36 video.attachCamera(cam);
37 }
38 addChild(video);
39 }
40
41 private function onStatusHandler(evt:NetStatusEvent):void
42 {
43 trace(evt.info.code);
44 if(evt.info.code=="NetConnection.Connect.Success")
45 {
46 ns=new NetStream(nc);
47 ns.addEventListener(NetStatusEvent.NET_STATUS,onStatusHandler);
48 ns.client=new CustomClient();
49 }
50 }
51
52 private function onPublishClick(evt:MouseEvent):void
53 {
54 nc=new NetConnection();
55 nc.addEventListener(NetStatusEvent.NET_STATUS,onPublishStatusHandler);
56 nc.connect("rtmp://localhost/PulishedStreams");
57 }
58
59 private function onPublishStatusHandler(evt:NetStatusEvent):void
60 {
61 if(evt.info.code=="NetConnection.Connect.Success")
62 {
63 ns=new NetStream(nc);
64 ns.addEventListener(NetStatusEvent.NET_STATUS,onPublishStatusHandler);
65 ns.client=new CustomClient();
66 ns.attachCamera(cam);
67 ns.attachAudio(mic);
68 ns.publish(tbName.text,"record");
69 }
70 }
71
72 private function onStopHandler(evt:MouseEvent):void
73 {
74 nc.close();
75 }
76
77 private function onPlayHandler(evt:MouseEvent):void
78 {
79 nc=new NetConnection();
80 nc.addEventListener(NetStatusEvent.NET_STATUS,onPlayStatusHandler);
81 nc.connect("rtmp://localhost/PulishedStreams");
82 }
83
84 private function onPlayStatusHandler(evt:NetStatusEvent):void
85 {
86 if(evt.info.code=="NetConnection.Connect.Success")
87 {
88 ns=new NetStream(nc);
89 ns.addEventListener(NetStatusEvent.NET_STATUS,onPlayStatusHandler);
90 ns.client=new CustomClient();
91
92 video = new Video();
93 video.attachNetStream(ns);
94 ns.play(tbName.text,0);
95 addChild(video);
96 }
97 }
98 }
99}
系列文章:
FMS3系列(一):第一个FMS程序,连接到FMS服务器(Flash/Flex两种实现)
FMS3系列(二):创建可交互的FMS连接--I can say:Hello World
FMS3系列(三):创建基于FMS的流媒体播放程序,看山寨帮的山寨传奇
更多精彩
赞助商链接