繁体   English   中英

您可以在Flash实例之间传递Camera和Microphone对象吗?

[英]Can you pass Camera and Microphone objects between Flash instances?

我正在开发一个HTML5应用程序,该应用程序需要与Flash交互才能访问本地媒体(例如,网络摄像头和麦克风),并在远程浏览器之间传输音频视频。 但是在此应用中,我需要将本地网络摄像头显示置于屏幕的一部分上,并由远程网络摄像头显示中的各种HTML元素分隔开。 我非常确定这意味着我需要运行Flash应用程序的多个实例。 但我认为您一次只能抓取一个网络摄像头实例,这意味着我需要能够在Flash实例之间共享这些网络摄像头和麦克风对象:一个显示本地网络摄像头,另一个显示并与之通信。远程网络摄像头。 有可能这样做吗? 例如,是否可以通过ExternalInterface将我的Camera和Microphone实例传递给JavaScript,然后再将它们传递回我的Flash对象的单独实例中?

换句话说,我正在考虑拥有一个看起来像这样的ActionScript类(当然,已经大大简化了):

public class MediaController
{

    public function MediaController()
    {
        ExternalInterface.addCallback('getUserMedia', this.getUserMedia);
        ExternalInterface.addCallback('getCamera', this.getCamera);
        ExternalInterface.addCallback('setCamera', this.setCamera);
        ExternalInterface.addCallback('getMicrophone', this.getMicrophone);
        ExternalInterface.addCallback('setMicrophone', this.setMicrophone);
    }

    private var _mic:Microphone;
    private var _cam:Camera;

    public function getUserMedia()
    {
      _mic = Microphone.getMicrophone();
        _cam = Camera.getCamera();
    }

    public function getCamera():Camera
    {
        return this._cam;
    }

    public function setCamera(cam:Camera):void
    {
        this._cam = cam;
    }

    public function getMicrophone():Microphone
    {
        return this._mic;
    }

    public function setMicrophone(mic:Microphone):void
    {
        this._mic = mic;
    }
}

我会像这样在JavaScript中检索它们:

var localUser = $('#localUser')[0];
localUser.getUserMedia();
var mic = localUser.getMicrophone();
var cam = localUser.getCamera();

然后将它们传递回实际与远程用户进行通信的实例,如下所示:

var remoteUser = $('#remoteUser')[0];
remoteUser.setMicrophone(mic);
remoteUser.setCamera(cam);

这样做有任何已知的陷阱吗? 有没有更好的方法来解决这个问题? (在您问之前,是的,在没有其他建议的情况下,我正计划对此进行编码,并且我将让所有人知道我所找到的内容-只想知道在获得之前是否存在任何已知的陷阱或替代方案开始。:-)

您无法通过ExternalInterface将诸如CameraMicrophone类的对象传递给Javascript。 当您使用ExternalInterface与Javascript进行通信时,您传递的所有数据都会被编组为XML格式。 因此,在那时,摄像机/麦克风不再是“闪光Camera和“ Microphone对象。

您可能会发现,在某些浏览器/操作系统中,尝试同时从两个单独的SWF中访问同一台摄像机是可行的。 但是,在其他情况下,它会失败。 我已经在访问摄像机的两个完全不相关的网站上看到了这种现象。

SWF可以使用LocalConnection类相互通信,尽管我从未尝试过使用相机或麦克风进行类似的操作。

就其价值而言,这就是我最终采用的方法(或多或少),并且有效。 很复杂,而且有点脆弱,但是可以用:

// A typical 1:1 communication will involve four instances of the FlashMediaObject class:
// Instance1 (Initiator Sender): Displays local video, streams local video out to Instance4
// Instance2 (Initiator Receiver): Receives and displays video from Instance3
// Instance3 (Responder Sender): Displays local video, streams local video out to Instance2
// Instance4 (Responder Receiver): Receives and displays video from Instance1

// The workflow needs to go something like this:
// (1) Both: Room.onSessionAdded():     
//          SignalR makes both the JS clients for both the Initiator and the Responder aware of each other (i.e., their SessionId's).
// (2) Initiator: writeLocalMediaElement() -> fmo1.Connect():
//          Instance1 connects to Adobe's rtmfp service, gets its nearId, and passes it up to JS.
// (3) Responder: writeLocalMediaElement() -> fmo3.connect():
//          Instance3 connects to Adobe's rtmfp service, gets its peerId, and passes it up to JS.
// (4) Responder: prepareForCall() -> fmo4.connect():           
//          Instance4 connects to Adobe's rtmfp service, gets its peerId, and passes it up to JS.
// (5) Initiator: call() -> prepareForCall() -> fmo2.Connect():
//          Instance2 connects to Adbobe's rtmfp service, gets its nearId, and passes it up to JS.
// (6) Initiator: call() -> server.flashOffer():
//          The Initiator's JS controller contacts the Responder's JS (via SignalR), and passes it the two rtmfp ID's.
// (7) Responder: handleFlashOffer() -> fmo3.call():            
//          The Responder's JS controller passes the peerId for Instance2 (Initiator Receiver) to Instance3 (Responder Sender).
//          Instance3 begins publishing its video to Instance 2.
// (8) Responder: handleFlashOffer() -> fmo4.prepareForCall():
//          The Responder's JS controller passes the peerId for Instance1 (Initiator Sender) to Instance4 (Responder Receiver)
//          Instance4 prepares to receive a call from Instance1.
// (10) Responder: handleFlashOffer() -> server.flashAnswer():  
//          The Responder's JS controller contacts the Initiator's JS (via SignalR), and passes it the two peer ID's.
// (11) Initiator: handleFlashAnswer() -> fmo1.call():
//          The Initiator's JS controller passes the peerId for Instance4 (Responder Receiver) to Instance1 (Initiator Sender).
//          Instance1 connects to Instance4 and begins streaming video.
// (12) Initiator: handleFlashAnswer() -> fmo2.prepareForCall()
//          The Responder's JS controller passes the peerID for Instance3 (Responder Sender) to Instance2
//          Instance2 prepares to receive video from Instance3
// (9) Initiator: fmo2.onCall():
//          Instance2 begins playing video from Instance3.
// (13) Responder: fmo4.onCall():
//          Instance4 begins playing video from Instance1

暂无
暂无

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

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