基于FMS的在线录制例子
在FMS安装目录下的appliaction目录下建立test1文件夹...
然后打开flash 8插入以下代码...
其中conn_status,rap_status,videoinfo为testarea...
play_bt,record_bt 为按钮...
videolist为list...
video_r,video_p为视频元件(建立方法为:按 ctrl+L,然后右击,新建视频,命名,拖到场景中,把实例改为前面的名称就可以了)...
剩下的...自己试吧...
然后打开flash 8插入以下代码...
1 function Record()
2 {
3 video_r._visible = true;
4 video_p._visible = false;
5 play_bt.enabled = false;
6 record_bt.label = "停 止";
7 rapStatus = "recording";
8 videoinfo.text = "文件信息:" + videoName + ".flv";
9 rap_status.text = "当前状态:正在录制";
10 netStream.publish(videoName, "record");
11 RecordInterval = setInterval(RecordTime, 1000);
12 }
13 function RecordStop()
14 {
15 rap_status.text = "当 前状态:录制完成";
16 record_bt.label = "录 制";
17 play_bt.enabled = true;
18 clearInterval(RecordInterval);
19 timeNum = 0;
20 netStream.close();
21 rapStatus = "recordstop";
22 videolist.addItem({label: videoName});
23 }
24 function RecordTime()
25 {
26 ++timeNum;
27 rap_status.text = "当前状态:录制中 - " + Math.floor(timeNum / 60) + "分" + timeNum % 60 + "秒";
28 }
29 function PlayVideo()
30 {
31 video_r._visible = false;
32 video_p._visible = true;
33 record_bt.enabled = false;
34 play_bt.label = "停 止";
35 var playvideo = videolist.selectedItem.label;
36 video_p.attachVideo(netStream);
37 rapStatus = "playing";
38 netStream.play(playvideo);
39 netStream.onStatus = function (PlayInfo)
40 {
41 if (PlayInfo.code == "NetStream.Play.Stop")
42 {
43 rapStatus = "playstop";
44 netStream.close();
45 rap_status.text = "当 前状态:播放完毕";
46 play_bt.label = "播 放";
47 record_bt.enabled = true;
48 }
49 };
50 }
51 function PlayStop()
52 {
53 video_r._visible = true;
54 video_p._visible = false;
55 video_r.attachVideo(my_cam);
56 record_bt.enabled = true;
57 play_bt.label = "播放";
58 rapStatus = "playstop";
59 netStream.close();
60 rap_status.text = "当 前状态:播放停止";
61 }
62 var ser_url = "rtmp://192.168.1.68/r_p";
63 var rec_date = new Date();
64 var videoName = String(rec_date.getFullYear()) + String(rec_date.getMonth() + 1) + String(rec_date.getDate()) + String(rec_date.getHours()) + String(rec_date.getMinutes()) + String(rec_date.getSeconds()) + String(rec_date.getMilliseconds());
65 var netConn = new NetConnection();
66 netConn.connect(ser_url);
67 var netStream = new NetStream(netConn);
68 var my_cam = Camera.get();
69 if(my_cam == null)
70 {
71 rap_status.text = "当 前状态:没有找到MAC";
72 }
73 else
74 {
75 video_r.attachVideo(my_cam);
76 my_cam.setQuality(0, 100);
77 my_cam.setKeyFrameInterval(15);
78 my_cam.setLoopback(true);
79 my_cam.setMode(320, 240, 30, true);
80 netStream.attachVideo(my_cam);
81 my_cam.onStatus = function(infoObj:Object)
82 {
83 if (my_cam.muted) {
84 // If user is denied access to their Camera, you can display an error message here. You can display the user's Camera/Privacy settings again using System.showSettings(0);
85 trace("User denied access to Camera");
86 System.showSettings(0);
87 }
88 }
89 var my_mic = Microphone.get();
90 if(my_mic == null)
91 {
92 rap_status.text = "当 前状态:没有找到MIC";
93 }
94 else
95 {
96 netStream.attachAudio(my_mic);
97 my_mic.onStatus = function(infoObj:Object)
98 {
99 if (my_mic.muted) {
100 // If user is denied access to their Camera, you can display an error message here. You can display the user's Camera/Privacy settings again using System.showSettings(0);
101 trace("User denied access to Camera");
102 System.showSettings(0);
103 }
104 }
105 }
106 }
107 var rapStatus = "free";
108 netConn.onStatus = function (info)
109 {
110 if (info.code == "NetConnection.Connect.Success")
111 {
112 conn_status.text = "连 接状态: 连接成功";
113 }
114 else
115 {
116 conn_status.text = "连 接状态: 连接错误";
117 }
118 };
119 var timeNum = 0;
120 record_bt.onRelease = function ()
121 {
122 if (rapStatus == "free" | rapStatus == "recordstop")
123 {
124 Record();
125 }
126 else if (rapStatus == "recording")
127 {
128 RecordStop();
129 }
130 };
131 play_bt.onRelease = function ()
132 {
133 if (rapStatus == "free" | rapStatus == "playstop" | rapStatus == "recordstop")
134 {
135 //trace(videolist.length);
136 if(videolist.length > 0)
137 {
138 PlayVideo();
139 }
140 else
141 {
142 rap_status.text = "当 前状态:没有视频";
143 }
144 }
145 else if (rapStatus == "playing")
146 {
147 PlayStop();
148 }
149 };
2 {
3 video_r._visible = true;
4 video_p._visible = false;
5 play_bt.enabled = false;
6 record_bt.label = "停 止";
7 rapStatus = "recording";
8 videoinfo.text = "文件信息:" + videoName + ".flv";
9 rap_status.text = "当前状态:正在录制";
10 netStream.publish(videoName, "record");
11 RecordInterval = setInterval(RecordTime, 1000);
12 }
13 function RecordStop()
14 {
15 rap_status.text = "当 前状态:录制完成";
16 record_bt.label = "录 制";
17 play_bt.enabled = true;
18 clearInterval(RecordInterval);
19 timeNum = 0;
20 netStream.close();
21 rapStatus = "recordstop";
22 videolist.addItem({label: videoName});
23 }
24 function RecordTime()
25 {
26 ++timeNum;
27 rap_status.text = "当前状态:录制中 - " + Math.floor(timeNum / 60) + "分" + timeNum % 60 + "秒";
28 }
29 function PlayVideo()
30 {
31 video_r._visible = false;
32 video_p._visible = true;
33 record_bt.enabled = false;
34 play_bt.label = "停 止";
35 var playvideo = videolist.selectedItem.label;
36 video_p.attachVideo(netStream);
37 rapStatus = "playing";
38 netStream.play(playvideo);
39 netStream.onStatus = function (PlayInfo)
40 {
41 if (PlayInfo.code == "NetStream.Play.Stop")
42 {
43 rapStatus = "playstop";
44 netStream.close();
45 rap_status.text = "当 前状态:播放完毕";
46 play_bt.label = "播 放";
47 record_bt.enabled = true;
48 }
49 };
50 }
51 function PlayStop()
52 {
53 video_r._visible = true;
54 video_p._visible = false;
55 video_r.attachVideo(my_cam);
56 record_bt.enabled = true;
57 play_bt.label = "播放";
58 rapStatus = "playstop";
59 netStream.close();
60 rap_status.text = "当 前状态:播放停止";
61 }
62 var ser_url = "rtmp://192.168.1.68/r_p";
63 var rec_date = new Date();
64 var videoName = String(rec_date.getFullYear()) + String(rec_date.getMonth() + 1) + String(rec_date.getDate()) + String(rec_date.getHours()) + String(rec_date.getMinutes()) + String(rec_date.getSeconds()) + String(rec_date.getMilliseconds());
65 var netConn = new NetConnection();
66 netConn.connect(ser_url);
67 var netStream = new NetStream(netConn);
68 var my_cam = Camera.get();
69 if(my_cam == null)
70 {
71 rap_status.text = "当 前状态:没有找到MAC";
72 }
73 else
74 {
75 video_r.attachVideo(my_cam);
76 my_cam.setQuality(0, 100);
77 my_cam.setKeyFrameInterval(15);
78 my_cam.setLoopback(true);
79 my_cam.setMode(320, 240, 30, true);
80 netStream.attachVideo(my_cam);
81 my_cam.onStatus = function(infoObj:Object)
82 {
83 if (my_cam.muted) {
84 // If user is denied access to their Camera, you can display an error message here. You can display the user's Camera/Privacy settings again using System.showSettings(0);
85 trace("User denied access to Camera");
86 System.showSettings(0);
87 }
88 }
89 var my_mic = Microphone.get();
90 if(my_mic == null)
91 {
92 rap_status.text = "当 前状态:没有找到MIC";
93 }
94 else
95 {
96 netStream.attachAudio(my_mic);
97 my_mic.onStatus = function(infoObj:Object)
98 {
99 if (my_mic.muted) {
100 // If user is denied access to their Camera, you can display an error message here. You can display the user's Camera/Privacy settings again using System.showSettings(0);
101 trace("User denied access to Camera");
102 System.showSettings(0);
103 }
104 }
105 }
106 }
107 var rapStatus = "free";
108 netConn.onStatus = function (info)
109 {
110 if (info.code == "NetConnection.Connect.Success")
111 {
112 conn_status.text = "连 接状态: 连接成功";
113 }
114 else
115 {
116 conn_status.text = "连 接状态: 连接错误";
117 }
118 };
119 var timeNum = 0;
120 record_bt.onRelease = function ()
121 {
122 if (rapStatus == "free" | rapStatus == "recordstop")
123 {
124 Record();
125 }
126 else if (rapStatus == "recording")
127 {
128 RecordStop();
129 }
130 };
131 play_bt.onRelease = function ()
132 {
133 if (rapStatus == "free" | rapStatus == "playstop" | rapStatus == "recordstop")
134 {
135 //trace(videolist.length);
136 if(videolist.length > 0)
137 {
138 PlayVideo();
139 }
140 else
141 {
142 rap_status.text = "当 前状态:没有视频";
143 }
144 }
145 else if (rapStatus == "playing")
146 {
147 PlayStop();
148 }
149 };
其中conn_status,rap_status,videoinfo为testarea...
play_bt,record_bt 为按钮...
videolist为list...
video_r,video_p为视频元件(建立方法为:按 ctrl+L,然后右击,新建视频,命名,拖到场景中,把实例改为前面的名称就可以了)...
剩下的...自己试吧...