In the process of FMS programming, we often perform camera detection before using a camera to detect whether a camera or camera is available.
Generally, we use this method to check whether the camera is busy: VaR Temp_cam = Camera. Get();
If (Temp_cam = - 1 ){
Trace('Video Device Busy ');
}
But I do not know why, such a detection method is always unable to pass during my testing, I intend to make anotherProgramUse the camera and then run this sectionCode. The results show that the camera is still available, not as I imagined "the video device is busy ".
Later, I found another detection method, which is effective. The method is to attachvideo A user_cam (CAMERA object) to a video_vid (video object, then judge whether user_cam.currentfps is greater than 0. If the camera is occupied, user_cam.currentfps is definitely not greater than 0, but equal to 0. The Code is as follows:
Function Checkcambusy (user_cam:Camera):Void{
VaR Chktime:Number = 0 ;
VaR Intervalid:Number;
Function Callback (){
Trace(User_cam.Currentfps);
If (User_cam.Currentfps > 0 ){
// Available video devices
Clearinterval(Intervalid );
} Else {
Chktime ++ ;
If (Chktime > 30 ){
// Video Device Busy
_ Root. Video_vid.Clear ();
Clearinterval(Intervalid );
}
}
}
Intervalid = Setinterval(Callback, 50 );
}< P>
var user_cam = camera. get ();
_ root. video_vid. attachvideo (user_cam);
checkcambusy (user_cam );