Flex无法访问摄像头
在弹出“AdobeFlashPlayer设置”对话框后,无论选择“允许”还是“拒绝”,StatusEvent事件的code值都为“Camera.Muted”。有人说在调用...
在弹出“Adobe Flash Player 设置”对话框后,无论选择“允许”还是“拒绝”,StatusEvent事件的code值都为“Camera.Muted”。
有人说在调用“attachCamera”方法时会弹出“Adobe Flash Player 设置”对话框。但我的不会弹出,只有调用了“Security.showSettings(SecurityPanel.PRIVACY);”后才弹出此框。
请高手多指点。
以下是部分代码:
private function initCameraAndMic():void
{
_camera = Camera.getCamera();
if(_camera != null)
{
_camera.addEventListener(StatusEvent.STATUS,__onStatusHandler);
_camera.setMode(320,420,30);
//t_flv_video.attachCamera(_camera);
_localVideo = new Video();
_localVideo.width = 320;
_localVideo.height = 240;
_localVideo.attachCamera(_camera);
t_flv_video.addChild(_localVideo);
}
_mic = Microphone.getMicrophone();
if(_mic != null)
{
_mic.setSilenceLevel(0,-1); _mic.gain = 80; }
}
private function beginOrShowRecVideo():void
{
_netConnection = new NetConnection();
_netConnection.addEventListener(NetStatusEvent.NET_STATUS,__onNetStatusHandler);
_netConnection.addEventListener(SecurityErrorEvent.SECURITY_ERROR,__onSecurityErrorHandler);
_netConnection.connect(_videoServerURL);
}
private function beginRecConnectStream():void
{
if(_localVideo != null)
{
_localVideo.clear();
t_flv_video.removeChild(_localVideo);
_localVideo = new Video();
_localVideo.width = 320;
_localVideo.height = 240;
_localVideo.attachCamera(_camera);
t_flv_video.addChild(_localVideo);
}
_outStream = new NetStream(_netConnection);
_outStream.attachCamera(_camera);
_outStream.attachAudio(_mic);
_outStream.publish("testVideo","record");
}
private function recVideo(event:MouseEvent):void
{
Security.showSettings(SecurityPanel.PRIVACY);
//System.showSettings(SecurityPanel.CAMERA);
if(!isrecing) //开始录制
{
isrecing = true;
t_btn_rec.label = "停止录制";
t_btn_play.enabled = false;
t_btn_save.enabled = false;
t_lbl_rec.visible = true;
beginOrShowRecVideo();
}
else //停止录制
{
isrecing = false;
t_btn_rec.label = "开始录制";
t_btn_play.enabled = true;
t_btn_save.enabled = true;
t_lbl_rec.visible = false;
_outStream.close();
}
}
private function __onStatusHandler(event:StatusEvent):void
{
Alert.show("------------"+event.code);
if(!_camera.muted)
{
t_btn_rec.enabled = true;
}
else
{
Alert.show("错误:无法链接到活动摄像头!");
}
//_camera.removeEventListener(StatusEvent.STATUS,__onStatusHandler);
}
private function __onNetStatusHandler(event:NetStatusEvent):void
{
switch (event.info.code)
{
case "NetConnection.Connect.Success":
if(isrecing)
{
beginRecConnectStream();
}
else
{
showRecConnectStream();
}
break;
case "NetConnection.Connect.Failed":
trace("连接失败!");
break;
case "NetStream.Play.StreamNotFound":
trace("Stream not found: " + event);
break;
}
}
<mx:Button x="210" y="320" label="开始录制" click="recVideo(event)" fontSize="12" id="t_btn_rec"/> 展开
有人说在调用“attachCamera”方法时会弹出“Adobe Flash Player 设置”对话框。但我的不会弹出,只有调用了“Security.showSettings(SecurityPanel.PRIVACY);”后才弹出此框。
请高手多指点。
以下是部分代码:
private function initCameraAndMic():void
{
_camera = Camera.getCamera();
if(_camera != null)
{
_camera.addEventListener(StatusEvent.STATUS,__onStatusHandler);
_camera.setMode(320,420,30);
//t_flv_video.attachCamera(_camera);
_localVideo = new Video();
_localVideo.width = 320;
_localVideo.height = 240;
_localVideo.attachCamera(_camera);
t_flv_video.addChild(_localVideo);
}
_mic = Microphone.getMicrophone();
if(_mic != null)
{
_mic.setSilenceLevel(0,-1); _mic.gain = 80; }
}
private function beginOrShowRecVideo():void
{
_netConnection = new NetConnection();
_netConnection.addEventListener(NetStatusEvent.NET_STATUS,__onNetStatusHandler);
_netConnection.addEventListener(SecurityErrorEvent.SECURITY_ERROR,__onSecurityErrorHandler);
_netConnection.connect(_videoServerURL);
}
private function beginRecConnectStream():void
{
if(_localVideo != null)
{
_localVideo.clear();
t_flv_video.removeChild(_localVideo);
_localVideo = new Video();
_localVideo.width = 320;
_localVideo.height = 240;
_localVideo.attachCamera(_camera);
t_flv_video.addChild(_localVideo);
}
_outStream = new NetStream(_netConnection);
_outStream.attachCamera(_camera);
_outStream.attachAudio(_mic);
_outStream.publish("testVideo","record");
}
private function recVideo(event:MouseEvent):void
{
Security.showSettings(SecurityPanel.PRIVACY);
//System.showSettings(SecurityPanel.CAMERA);
if(!isrecing) //开始录制
{
isrecing = true;
t_btn_rec.label = "停止录制";
t_btn_play.enabled = false;
t_btn_save.enabled = false;
t_lbl_rec.visible = true;
beginOrShowRecVideo();
}
else //停止录制
{
isrecing = false;
t_btn_rec.label = "开始录制";
t_btn_play.enabled = true;
t_btn_save.enabled = true;
t_lbl_rec.visible = false;
_outStream.close();
}
}
private function __onStatusHandler(event:StatusEvent):void
{
Alert.show("------------"+event.code);
if(!_camera.muted)
{
t_btn_rec.enabled = true;
}
else
{
Alert.show("错误:无法链接到活动摄像头!");
}
//_camera.removeEventListener(StatusEvent.STATUS,__onStatusHandler);
}
private function __onNetStatusHandler(event:NetStatusEvent):void
{
switch (event.info.code)
{
case "NetConnection.Connect.Success":
if(isrecing)
{
beginRecConnectStream();
}
else
{
showRecConnectStream();
}
break;
case "NetConnection.Connect.Failed":
trace("连接失败!");
break;
case "NetStream.Play.StreamNotFound":
trace("Stream not found: " + event);
break;
}
}
<mx:Button x="210" y="320" label="开始录制" click="recVideo(event)" fontSize="12" id="t_btn_rec"/> 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询