Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

change (and list) audio input device

Avatar

Former Community Member

hi there, is there a way to programatically change the microphone being used by the audioPublisher?

i mean the audioPublisher has the selectedMic property which according to your API is read-write

selectedMicproperty

selectedMic:Microphone  [read-write]

Returns the currently selected microphone.

Implementation

    public function get selectedMic():Microphone

    public function set selectedMic(value:Microphone):void

but the problem is how can i select a mic in flash (programatically), if i need to pass a Microphone object to the selectedMic property, then that means that i have to do somthing like Microphone.getIndex(something), but then again how can i know the index of each microphone?

Actually i have even tried changing the selected microphone in the flash settings but whenever i get audioPublisher.selectedMic.name, its always "USB Audio Device" so it really doesn't seem to change or i'm just not getting it or doesn't know how to get it.

i'm really relatively new to flash and it also seems that there is no real way to list and select the active mic, i mean you can list it down using the Microphone.names array list, but how can i get their corresponding index? is it just zero-based then just increment by one for each item in the microphone.names array?

6 Replies

Avatar

Former Community Member

it would really be useful if i can list down existing microphones using the names array and then get each microphone by using the MIcrophone.getMicrophone method, but then again the Microphone.getMicrohone method only accepts mic index. Is this for security reasons that flash doesn't allow mic selection?

Avatar

Employee

I am not really sure I understand your last question.

Microphone.names returns an array of names (in a fixed order, I think) so if put them in a listbox and then select an entry you can get the index and call Microphone.getMicrophone(index).

If you are worried that the user may disconnect one audio source between listing the names and picking one, you can check that the name of the selected Microphone is the same as the name you are expecting.

Avatar

Former Community Member

ok, i'll try out using the microphone.names list first and use an appropriate index for each starting from 0... and then see if i can really get to assign the selected mic for the audioPublisher...

Avatar

Former Community Member

this works great, i can actually set the MicrophoneManager's selectedMic property using that combo box, i was just thinking why flash's global settings mic dialog doesn't really do anything (or perhaps it was designed for something else, i don't know).

But then again, thank you for this answer, but just a couple of new questions....

1. audioPublisher's microphone property only changes each time you call audioPublisher.publish right? (that's what i see on my testing - and it gets its value from the MicrophoneManager.selectedMic proprty). I mean even if you change the MicrophoneManager.selectedMic property while you are publishing, it will not change the audioPublisher.microphone property, is this correct?

2. it is really by default that you will not be able to hear what you are publishing? using the audioSubscriber? i mean i just added "<rtc:AudioSubscriber id="audioSub" height="0" />" on my code and i'm able to hear other persons who are connected in the room, but is there any way that you may be able to subscribe to your own audio stream?

Avatar

Employee

1. Stopping and restarting and your AudioPublisher would help in selecting the new mic. But not in middle of publishing

2. We don’t by default subscribe to our own stream. I am assuming subscribing to your own stream would cause echo. Do you really want that ? . But we have checks to avoid playing your own audio stream. You might have to extend AudioSubscriber class to subscribe to your own audio stream.

Arun

Avatar

Level 3

this may come in handy:


            cbMicrophones = new ComboBox();
            cbMicrophones.dropdownWidth = 100;
            cbMicrophones.width = 100; 
            cbMicrophones.prompt = "Microphones";
            cbMicrophones.dataProvider = getMics();       
            addChild(cbMicrophones);


        protected function getMics():DataProvider
        {
            var aMics:Array = Microphone.names;
            var dp:DataProvider = new DataProvider();


            for (var i:uint = 0;i < aMics.length; i++) {
                dp.addItem( { label:aMics[i], data:i } );
            }
            return dp;
        }

.......
            this.audioPub.microphoneManager.selectedMic = Microphone.getMicrophone(cbMicrophones.selectedIndex);