Search code examples
actionscript-3flashaudioaudio-streamingmicrophone

How to select audio sources from a list Flash + ActionScript3


From the Adobe docs " You can use the Microphone.names property or the Microphone.getMicrophone() method to check whether the user has a sound input device installed. ".

How would you take the names of the users audio devices and allow them to select the source they would like to use?

Currently the default audio is selected at the point of streaming with the following code:

if ( microphone != null)
{   
    // Tried to list microphones but failed!
    //sourceVideoLabel.text = microphone.names;

    microphone.rate = 16;
    microphone.codec = SoundCodec.SPEEX;
    microphone.setSilenceLevel(0, -1);
    microphone.setUseEchoSuppression(true);
}
else
{
    sourceVideoLabel.text +=  "No Microphone Found\n";
}

Solution

  • Microphone.names is a static property, meaning that you must access it from the class itself. You're trying to access it from an class instance, microphone. You should do this:

    sourceVideoLabel.text += Microphone.names;
    

    Note the capital M, meaning you're accessing the class not the instance.

    Microphone.name, on the other hand, is non-static, and is accessed through the instance microphone to get the currently selected microphone:

    someTextField.text = "The current microphone is " + microphone.name;
    

    (By the way, in case of confusion it might be best to avoid instance names that are too similar to the class name. Something like mic works just as well, is easily distinguishable, and it's quicker to type too.)