访问 div 中的相机

发布于 2024-10-09 02:38:49 字数 1662 浏览 3 评论 0原文

下面为什么相机没有出现在 div 中。我在这里做错了什么吗

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="swfobject.js"></script>
</head>
<body>
<div id="test" style="display:block;"></div>
<a href="#" onclick="document.getElementById('test').addBlock();">Call addBlock</a>
<script type="text/javascript">
  swfobject.embedSWF('test.swf', 'test', '300', '300', '9.0.124', 'expressInstall.swf');
</script>

  <?xml version="1.0" encoding="utf-8"?>
  <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="300" height="300" creationComplete="init()">
 <mx:Script>
    <![CDATA[
        import mx.controls.Alert;
                    import flash.display.InteractiveObject;
        import flash.display.Sprite;
        import flash.media.*;
        import flash.net.*;

        public static var cam:Camera =  Camera.getCamera();
        public static var video:Video = new Video(10, 20);
        private function init():void
        {
            ExternalInterface.addCallback('addBlock', addBlock);
        }

        private function addBlock():void
        {
            //Alert.show("addBlock called");
            if(cam != null)
            {   
                cam.setMode(640, 480, 30);
                video.attachCamera(cam);
                addChild(video);

            }
            else
            {

                trace("No Camera Detected");
                Alert.show("No Camera Detected");
            }




        }
    ]]>
</mx:Script>
  </mx:Application>

In the following why is that the camera does not show up in the div.Is that am i doing anything wrong here

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="swfobject.js"></script>
</head>
<body>
<div id="test" style="display:block;"></div>
<a href="#" onclick="document.getElementById('test').addBlock();">Call addBlock</a>
<script type="text/javascript">
  swfobject.embedSWF('test.swf', 'test', '300', '300', '9.0.124', 'expressInstall.swf');
</script>

  <?xml version="1.0" encoding="utf-8"?>
  <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="300" height="300" creationComplete="init()">
 <mx:Script>
    <![CDATA[
        import mx.controls.Alert;
                    import flash.display.InteractiveObject;
        import flash.display.Sprite;
        import flash.media.*;
        import flash.net.*;

        public static var cam:Camera =  Camera.getCamera();
        public static var video:Video = new Video(10, 20);
        private function init():void
        {
            ExternalInterface.addCallback('addBlock', addBlock);
        }

        private function addBlock():void
        {
            //Alert.show("addBlock called");
            if(cam != null)
            {   
                cam.setMode(640, 480, 30);
                video.attachCamera(cam);
                addChild(video);

            }
            else
            {

                trace("No Camera Detected");
                Alert.show("No Camera Detected");
            }




        }
    ]]>
</mx:Script>
  </mx:Application>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧情别恋 2024-10-16 02:38:49

首先我要做的是确保 Flash 确实被嵌入。如果 Javascript 工作正常,那么这里可能存在一些问题。首先,我并不肯定,但我认为您不希望将相机连接到视频对象,而是连接到视频显示器:

<mx:VideoDisplay x="784" y="276" width="0" height="0" id="video"/>

然后做:

video.addChild(cam);

第二件事是,如果您使用的是 Mac,则标准getCamera() 函数并非 100% 都有效。我建议您定义自己的获取相机函数,该函数应如下所示:

private function getCamera():Camera{
    var camera:Camera;
    var index:int = 0;
    for (var i:int = 0; i < Camera.names.length; i++) {
        trace(Camera.names[i]);
        if (Camera.names[i] == "USB Video Class Video") { // for macs camera
                index = i;
        }
    }
    camera = Camera.getCamera(String(index));
    if (camera == null) {
        return null;
    }
    else {
        return camera;
    }
}

基本上,某些 Mac 有一个默认相机,该相机位于一个奇怪的位置,标准 getCamera 调用不起作用。这个应该有帮助。祝你好运!

First what I would do is to make sure that the Flash is actually being embedded. If it is the case that the Javascript is working correctly then there are a few possible issues here. First I'm not positive but I would think that you wouldn't want to be attaching the camera to a video object, but instead to a video display:

<mx:VideoDisplay x="784" y="276" width="0" height="0" id="video"/>

And then do:

video.addChild(cam);

The second thing is that if you are using a Mac the standard getCamera() function doesn't work 100% of the time. What I would recommend you do is define your own get camera function which should look something like this:

private function getCamera():Camera{
    var camera:Camera;
    var index:int = 0;
    for (var i:int = 0; i < Camera.names.length; i++) {
        trace(Camera.names[i]);
        if (Camera.names[i] == "USB Video Class Video") { // for macs camera
                index = i;
        }
    }
    camera = Camera.getCamera(String(index));
    if (camera == null) {
        return null;
    }
    else {
        return camera;
    }
}

Basically some Macs have a default camera which is located in a weird place where the standard getCamera call doesn't work. This one should help. Good luck!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文