Class for detecting microphone camera status in the Flash Actionscript 2.0 System

Source: Internet
Author: User
1 /**
2 * @ author Harrison
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 // start Detection
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 // No mic available for the System
30 broadcastMessage ("onMicNotFound ");
31} else {
32 if (camArray. length <1 ){
33 // The system does not have a usable 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 // The use of mic and cam is forbidden by the user
55 owner. broadcastMessage ("onCamBlockedByUser ");
56}
57 };
58 if (user_mic.muted | user_cam.muted ){
59 // currently, mic and cam cannot be used.
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 is currently occupied by other video programs
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.