开发者

How do I detect if a new microphone is available?

It appears that if one has a mic available, then one can add an event listener for the StatusEvent. However, this only tells you if the mic has been allowed or disallowed.

What I'd really like to do is detect if the static Microphone.names property changes. I would have expected this property to be bindable.

If I right click and select "settings" immediately after plugging in a mic, I can see that flash has updated their list of available microphones. However, there seems to be no way in code for me to receive the same update.

The docs say "Calling Microphone.names requires an extensive exami开发者_如何学Gonation of the hardware, and it may take several seconds to build the array." So I think polling this every few seconds is not a feasible option.


I'm not sure if you can set a change watcher on the 'names' array of Microphone that would actually work because the watcher will only get called if the reference to the array is updated every time (new array). So this is untested, but something to try:

var watcher:ChangeWatcher = ChangeWatcher.watch(Microphone, ['names'], onNameChange);

Just need to create the onNameChange handler to see if it's actually being called. If that doesn't work, then you'll need to do some kind of 'polling' of names every x amount of time.


I ran a little test script:

var ta:TextArea = new TextArea();
    ta.width = ta.height = 500;
    addChild(ta);
    var t:Timer = new Timer(5000);
    t.addEventListener(TimerEvent.TIMER, function(e:Event):void{
        var t0:uint = getTimer();

        var m:* = Microphone.getMicrophone();

        ta.text += "mic found: "+(m?true:false)+" "+(getTimer()-t0);

        t0 = getTimer();
        var o:* = Microphone.names;
        ta.text += "\t\ttime to get names: "+(getTimer()-t0)+"\n";

    });
    t.start();

The results were all times with fewer than 10ms (getMicrophone was 0-3ms, names was 2-9ms), which seems pretty fast to me. I don't know, perhaps it's my computer, but it doesn't seem to be too intensive. As getMicrophone is all I need, there are no official warnings about its use, and it's marginally faster, I'm going to poll getMicrophone every few seconds or so to deal with this.

If anyone here cares to run this script and give some feedback on your results, it may help me and others make a better choice.


No events exposed for this matter as you say. The property is not bindable because Microphone is a Flash player feature, not a Flex Microphone wrapper (as for today binding is Flex only).

I suggest you to poll for Microphone.getMicrophone() every few seconds and assert that is not null. This call is far less "examination intensive" than Microphone.names.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜