Avaya Client SDK

< Back to Package Overview

Working with Media Devices

This articles discusses basic concepts and features relating to working with devices. Media devices can be added or removed from the environment at any time, imposing requirements that must be understood and managed by your application.

The following articles are recommended to get you started:

Retrieve the list of media devices

You can retrieve all available media devices by using three collections: Microphones, Speakers and Cameras. First of all get the MediaServicesInstance object and access the AudioInterface.

MediaServicesInstance mediaServices = client.MediaServices;
AudioInterface audioInterface = mediaServices.getAudioInterface();

Iterate the Microphones property of the AudioInterface object to get the list of microphone devices.

if (audioInterface.Microphones.Count == 0)
{
    Console.WriteLine("There are no microphones available.");
}
else
{
    Console.WriteLine("Microphones:");
    foreach (MicrophoneDevice microphone in audioInterface.Microphones)
    {
        string defaults = "[";
        defaults += (microphone.isDefaultCommunicationsDevice)? "Comm ":"     ";
        defaults += (microphone.isDefaultConsoleDevice)?        "Cons ":"     ";
        defaults += (microphone.isDefaultMultimediaDevice)?     "Mult" :"    ";
        defaults += "] ";
        Console.WriteLine(defaults + microphone.Name);
    }
}

Iterate the Speakers property of the AudioInterface object to get the list of speaker devices.

if (audioInterface.Speakers.Count == 0)
{
    Console.WriteLine("There are no speakers available.");
}
else
{
    Console.WriteLine("Speakers:");
    foreach (SpeakerDevice speaker in audioInterface.Speakers)
    {
        string defaults = "[";
        defaults += (speaker.isDefaultCommunicationsDevice)? "Comm ":"     ";
        defaults += (speaker.isDefaultConsoleDevice)?        "Cons ":"     ";
        defaults += (speaker.isDefaultMultimediaDevice)?     "Mult" :"    ";
        defaults += "] ";
        Console.WriteLine(defaults + speaker.Name);
    }
}

To get the list of video devices, instantiate the CameraVideoSource object then iterate over the Cameras property.

CameraVideoSource videoSource = new CameraVideoSource();
if (videoSource.Cameras.Count == 0)
{
    Console.WriteLine("There are no cameras available.");
}
else
{
    Console.WriteLine("Cameras:");
    foreach (CameraDevice camera in videoSource.Cameras)
    {
        Console.WriteLine("[" + camera.getType().ToString() + "] " +
            camera.Name);
    }
}

Setting an audio microphone to be active

Use the selectMicrophone method of the AudioInterface object to set microphone to be active.

audioInterface.selectMicrophone(selectedMicrophone);

Setting an audio speaker to be active

Use the selectSpeaker method of the AudioInterface object to set speaker to be active.

audioInterface.selectSpeaker(selectedSpeaker);

Setting a video camera to be active

Start video capture from selected camera to set it to be active. Use the Start method of the CameraVideoSource object.

videoSource.Start(selectedCamera, 
                  new VideoCaptureFormat(700, 400, 0, 30), 
                  (result) =>
                  {
                      if (result == CameraVideoSourceResult.Success)
                      {
                          Console.WriteLine("CameraCaptureStart Success");
                      }
                      else
                      {
                          Console.WriteLine("Error :" + result.ToString());
                      }
                  });

Listening for device change events

All three collections (Microphones, Speakers and Cameras) are observable. You can create own method to handle device list changes.

private void OnMicrophonesCollectionChanged(object sender, 
    NotifyCollectionChangedEventArgs args)
{
    switch (args.Action)
    {
        case NotifyCollectionChangedAction.Add:
            Console.WriteLine("Microphones have been added:");
            foreach(MicrophoneDevice microphone in args.NewItems)
            {
                Console.WriteLine(microphone.Name);
            }
            break;
        case NotifyCollectionChangedAction.Remove:
            Console.WriteLine("Microphones have been removed:");
            foreach(MicrophoneDevice microphone in args.OldItems)
            {
                Console.WriteLine(microphone.Name);
            }
            break;
        case NotifyCollectionChangedAction.Reset:
            Console.WriteLine("All microphones have been removed.");
            break;
        case NotifyCollectionChangedAction.Move:
        case NotifyCollectionChangedAction.Replace:
            Console.WriteLine("Microphones have been moved or replaced.");
            break;
    };
}

Then add the event handler to the CollectionChanged event.

((INotifyCollectionChanged)audioInterface.Microphones).CollectionChanged +=
    OnMicrophonesCollectionChanged;
((INotifyCollectionChanged)audioInterface.Speakers).CollectionChanged +=
    OnSpeakersCollectionChanged;
((INotifyCollectionChanged)videoSource.Cameras).CollectionChanged +=
    OnCamerasCollectionChanged;