简体   繁体   English

Flex Spark VideoObject为null

[英]Flex Spark VideoObject is null

I'm working with spark video components, however the spark videoObject is null, when using a dynamic video source object it still null. 我正在使用Spark视频组件,但是spark videoObject为null,当使用动态视频源对象时,它仍为null。 Cameras are being detected properly, however when using a variable it's null, when using the Camera object directly usb camera is detected and videoobject still null... any ideas??? 可以正确检测摄像机,但是使用变量时为null,直接使用Camera对象时,将检测到usb摄像机,而videoobject仍然为null ...任何想法?

Now when using Camera.names all "cameras" are null, when playing a video from apache virtualhosts it plays well, this is so so weird...! 现在,当使用Camera.names时,所有“ cameras”都为空,当从apache虚拟主机播放视频时,其播放效果很好,真是太不可思议了……!

As requested, updated code: 根据要求,更新了代码:

import mx.controls.Alert;
            import mx.events.FlexEvent;
            import spark.components.VideoPlayer;

            private var vidPlyr:VideoPlayer = null;

            protected function winAppCreated(event:FlexEvent):void {
                // Video Player
                vidPlyr = new VideoPlayer();
                vidPlyr.width = 320;
                vidPlyr.height = 240;

                // Video from apache virtualhost:
                vidPlyr.source = "http://flex.test.capimg/JormaKaukonenCracksInTheFinish.flv";
                addElement(vidPlyr);

                var cameraTV:Camera = Camera.getCamera(Camera.names[0]);
                var cameraUSB:Camera = Camera.getCamera(Camera.names[1]);

                if (cameraTV) {
                    vidPlyr.videoDisplay.videoObject.attachCamera(cameraTV);
                } else {
                    Alert.show("no TV card - " + Camera.names[0]);
                    // Alert shows: "no TV card - SAA7130 Analog TV Card" 
                }

                if (cameraUSB) {
                    vidPlyr.videoDisplay.videoObject.attachCamera(cameraUSB);
                } else {
                    Alert.show("no USB camera - " + Camera.names[1]);
                    // Alert shows: "no USB camera - USB2.0 Grabber"
                }
            }

This is a screenshot of running app. 这是正在运行的应用程序的屏幕截图。

在此处输入图片说明

I took a look at the VideoPlayer code, a lot of this class' properties have setters that look like this: 我看了一下VideoPlayer代码,该类的许多属性都有如下所示的setter:

public function set source(value:Object):void
{
    if (videoDisplay)
    {
        // do the real work
    }
    else
    {
        // store the value so we can use it later
     }
}

VideoDisplay is the a skin part of the video player class. VideoDisplay是视频播放器类的外观部分。 When you set the source, the skin must not have initialized the videoObject property. 设置源时,外观必须未初始化videoObject属性。 I would set the source, and then wait before trying to attach the camera. 我将设置信号源,然后等待尝试连接相机。

Flex has a callLater() method that may solve this problem. Flex具有可以解决此问题的callLater()方法。 callLater() will execute a function you specify on the next Flex update cycle: callLater()将在下一个Flex更新周期执行您指定的功能:

// after setting the source
callLater(attachCamera);


// define a new function 'attachCamera' to call later
private function attachCamera():void
{
    // if the videoObject property is not null
    if (vidPlyr.videoDisplay.videoOjbect != null)
    {
       // attach the camera here
    }
    else
    {
       trace("cannot attach the camera, videoObject is still null");
    }
}

[Edit] [编辑]

The API to get a camera is strange, the signature is: 获取相机的API很奇怪,签名为:

public static function getCamera(name:String = null):Camera

But that name argument is not the actual name of the camera. 但是,该name参数不是摄像机的实际名称。 It supposed to be a String representation of the camera's index in the Camera.names array. 它应该是Camera.names数组中摄像机索引的String表示形式。 Quoting the docs: 引用文档:

name:String (default = null) — Specifies which camera to get, as determined from the array returned by the names property. name:String(default = null)—指定要获取的摄像机,这是由names属性返回的数组确定的。 For most applications, get the default camera by omitting this parameter. 对于大多数应用程序,请省略此参数以获取默认相机。 To specify a value for this parameter, use the string representation of the zero-based index position within the Camera.names array. 要为此参数指定一个值,请使用Camera.names数组中从零开始的索引位置的字符串表示形式。 For example, to specify the third camera in the array, use Camera.getCamera("2"). 例如,要指定数组中的第三个摄像机,请使用Camera.getCamera(“ 2”)。

Try doing something more generic like this when you attach the camera with callLater(attachCamera) : 当您将相机与callLater(attachCamera)时,尝试做类似这样的通用操作:

private function attachCamera():void
{
    var cameras:Array = Camera.names;
    var length:int = cameras.length;
    var cameraObjects:Array = [];
    for (var i:int = 0; i < length; i++)
    {
        cameraObjects.push( Camera.getCamera( i.toString() );
    }

    // use your own logic to select a camera, if there's more than one
    if (cameraObjects.length > 0 && vidPlyr.videoDisplay.videoOjbect != null)
    {
        vidPlyr.videoDisplay.videoOjbect.attachCamera( cameraObjects[0] );
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM