您的位置:首页 > 其它

Flash Actionscript 2.0 在 FMS 中检测麦克风 摄像头状态的类

2007-03-26 14:32 465 查看
1 /**
2 * @author rison
3 * @data 2006-05-20
4 * @version 1.1
5 * @usage setting for camera and mic in FMS application
6 */
7 class SettingCheck {
8 private var video:Video;
9 private var user_cam:Camera;
10 public var addListener:Function;
11 public var removeListener:Function;
12 private var broadcastMessage:Function;
13 private static var broadcastInit:Object = AsBroadcaster.initialize
14
15 (SettingCheck.prototype);
16 public function SettingCheck(target_video:Video) {
17 video = target_video;
18 user_cam = Camera.get();
19 }
20 public function startCheck():Void {
21 //开始检测
22 broadcastMessage("onStarted");
23 checkMic();
24 }
25 private function checkMic():Void {
26 var micArray:Array = Microphone.names;
27 var camArray:Array = Camera.names;
28 if (micArray.length<1) {
29 //系统没有可以使用的mic
30 broadcastMessage("onMicNotFound");
31 } else {
32 if (camArray.length<1) {
33 //系统没有可以使用的cam
34 broadcastMessage("onCamNotFound");
35 } else {
36 checkAllowable();
37 }
38 }
39 }
40 private function checkAllowable():Void {
41 var owner:Object = this;
42 var user_mic:Microphone = Microphone.get();
43 var test_nc:NetConnection = new NetConnection();
44 test_nc.connect(null);
45 var test_ns:NetStream = new NetStream(test_nc);
46 test_ns.attachAudio(user_mic);
47 user_mic.onStatus = function(infoObj) {
48 trace(infoObj.code);
49 if (infoObj.code == "Microphone.Unmuted") {
50 test_ns.attachAudio(null);
51 test_ns.close();
52 owner.checkCamBusy();
53 } else {
54 //mic 与 cam的使用被用户主动禁止
55 owner.broadcastMessage("onCamBlockedByUser");
56 }
57 };
58 if (user_mic.muted || user_cam.muted) {
59 //系统目前不允许使用mic 与 cam
60 broadcastMessage("onCamBlocked");
61 } else {
62 test_ns.attachAudio(null);
63 test_ns.close();
64 checkCamBusy();
65 }
66 }
67 private function checkCamBusy():Void {
68 //cam目前被其他视频程序占用
69 broadcastMessage("onCheckCamBusy");
70 video.attachVideo(user_cam);
71 var owner:Object = this;
72 var chkTime:Number = 0;
73 var intervalID:Number;
74 function callback() {
75 trace(owner.user_cam.currentFps);
76 if (owner.user_cam.currentFps>0) {
77 owner.broadcastMessage("onFinished");
78 clearInterval(intervalID);
79 } else {
80 chkTime++;
81 if (chkTime>30) {
82 owner.broadcastMessage("onCamBusy");
83 clearInterval(intervalID);
84 }
85 }
86 }
87 intervalID = setInterval(callback, 50);
88 }
89 }
90
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: