Flash网络摄像头权限

时间:2010-07-06 14:43:15

标签: actionscript-3 webcam wowza

我遇到闪存问题,我并不熟悉。我将此代码基于视频聊天示例中的wowza媒体服务器附带的代码,但与该示例不同,闪存不会提示我是否允许使用摄像机。

以下是我的动作:

import flash.events.MouseEvent;
import flash.events.NetStatusEvent;
import flash.media.Camera;
import flash.media.Microphone;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.system.Security;
import flash.system.SecurityPanel;
import flash.display.Sprite;
import flash.text.TextField;
import flash.events.StatusEvent;

public class QandA extends Sprite {
    Security.LOCAL_TRUSTED;

    private var nc:NetConnection = null;
    private var camera:Camera;
    private var microphone:Microphone;
    private var nsPublish:NetStream = null;                      
    private var nsPlay:NetStream = null;
    private var videoCamera:Video;
    public var prompt:TextField;

    public function QandA():void {
        stage.align = "TL";
        stage.scaleMode = "noScale";
        videoCamera = new Video(160,120);
        addChild(videoCamera);
        camera = Camera.getCamera();
        microphone = Microphone.getMicrophone();
        if (camera.muted) {
            trace("Camera Muted");
            Security.showSettings(SecurityPanel.CAMERA);
            camera.addEventListener(StatusEvent.STATUS, statusHandler);
        } else {
            startCamera();
        }

    }

    private function statusHandler(e:StatusEvent):void {
        if (e.code == "Camera.Unmuted") {
            trace("Camera Unmuted");
            startCamera();
            camera.removeEventListener(StatusEvent.STATUS, statusHandler);
        } else {
            trace("StatusEvent: " + e.code + " " + e.toString());
        }
    }

    private function startCamera():void {
        // here are all the quality and performance settings that we suggest
        camera.setMode(160, 120, 12, false);
        camera.setQuality(0, 75);
        camera.setKeyFrameInterval(24);
        microphone.rate = 11;
        microphone.setSilenceLevel(0);

        nc = new NetConnection();
        nc.connect("rtmp://localhost/live/");

        // get status information from the NetConnection object
        nc.addEventListener(NetStatusEvent.NET_STATUS, ncOnStatus); 
    }

    private function nsPublishOnStatus(infoObject:NetStatusEvent):void
    {
        trace("nsPublish: "+infoObject.info.code+" ("+infoObject.info.description+")");
    }

    private function ncOnStatus(infoObject:NetStatusEvent):void
    {
        trace("nc: "+infoObject.info.code+" ("+infoObject.info.description+")");
        nsPublish = new NetStream(nc);
        nsPublish.addEventListener(NetStatusEvent.NET_STATUS, nsPublishOnStatus);
        nsPublish.bufferTime = 0;
        nsPublish.publish("testing");
        // attach the camera and microphone to the server
        nsPublish.attachCamera(camera);
        nsPublish.attachAudio(microphone);
    }
}

我很自信这很简单;正如我在讨论如何发布到实时服务器时在无数网站上看到这段代码一样。

我将非常感谢任何帮助,我尝试在网络服务器上使用此代码来查看它是否只是本地安全设置,但事实并非如此。

在Flash CS5中调试应用程序时收到的日志:

尝试使用网址D启动并连接到播放器:\ development \ qanda \ qandaHost.swf
[SWF] D:\ development \ qanda \ qandaHost.swf - 解压缩后3583字节 相机静音
nc:NetConnection.Connect.Success(连接成功。)
nsPublish:NetStream.Publish.Start(发布测试。)

2 个答案:

答案 0 :(得分:2)

以下是错误的:

Security.showSettings(SecurityPanel.**CAMERA**);

你应该写:

Security.showSettings(SecurityPanel.**PRIVACY**);

答案 1 :(得分:1)

我没有将相机连接到视频,因此我看不到自己 - 即使视频实际上是流媒体。

private function startCamera():void {
    trace("Attempting to start camera");
    // here are all the quality and performance settings that we suggest
    camera.setMode(160, 120, 12, false);
    camera.setQuality(0, 75);
    camera.setKeyFrameInterval(24);
    videoCamera.attachCamera(camera);
    microphone.rate = 11;
    microphone.setSilenceLevel(0);
}