Class MediaDevicesApi

java.lang.Object
com.oorian.html.js.JavaScriptApi
com.oorian.html.js.mediadevices.MediaDevicesApi

public class MediaDevicesApi extends JavaScriptApi
Provides access to media devices (cameras, microphones) from server-side Java code.

This API wraps the browser's MediaDevices API, allowing you to enumerate available media devices and request access to camera and microphone.

Usage:


 public class MyPage extends HtmlPage implements MediaDevicesListener
 {
     @Override
     protected void createBody(Body body)
     {
         // Enumerate available devices
         MediaDevicesApi.enumerateDevices(this);
     }

     @Override
     public void onEvent(MediaDevicesEvent event)
     {
         for (MediaDevice device : event.getDevices())
         {
             System.out.println(device.getKind() + ": " + device.getLabel());
         }
     }

     @Override
     public void onEvent(MediaDevicesErrorEvent event)
     {
         showMessage("Error: " + event.getMessage());
     }
 }
 
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • MediaDevicesApi

      public MediaDevicesApi()
  • Method Details

    • enumerateDevices

      public static void enumerateDevices(MediaDevicesListener listener)
      Enumerates available media devices using the current page context.

      Returns a list of available cameras, microphones, and audio output devices. Note that device labels may be empty until the user grants permission.

      Parameters:
      listener - The listener that will receive the device list event.
    • enumerateDevices

      public static void enumerateDevices(HtmlPage page, MediaDevicesListener listener)
      Enumerates available media devices.

      Returns a list of available cameras, microphones, and audio output devices. Note that device labels may be empty until the user grants permission.

      Parameters:
      page - The page context.
      listener - The listener that will receive the device list event.
    • getUserMedia

      public static void getUserMedia(MediaDevicesListener listener, boolean audio, boolean video)
      Requests access to user media (camera and/or microphone) using the current page context.

      This will prompt the user to grant permission. After permission is granted, a MediaDevicesEvent will be fired with the updated device list including labels.

      Parameters:
      listener - The listener that will receive media events.
      audio - True to request audio access.
      video - True to request video access.
    • getUserMedia

      public static void getUserMedia(HtmlPage page, MediaDevicesListener listener, boolean audio, boolean video)
      Requests access to user media (camera and/or microphone).

      This will prompt the user to grant permission. After permission is granted, a MediaDevicesEvent will be fired with the updated device list including labels.

      Parameters:
      page - The page context.
      listener - The listener that will receive media events.
      audio - True to request audio access.
      video - True to request video access.
    • requestCameraAccess

      public static void requestCameraAccess(MediaDevicesListener listener)
      Requests access to the camera only using the current page context.
      Parameters:
      listener - The listener that will receive media events.
    • requestCameraAccess

      public static void requestCameraAccess(HtmlPage page, MediaDevicesListener listener)
      Requests access to the camera only.
      Parameters:
      page - The page context.
      listener - The listener that will receive media events.
    • requestMicrophoneAccess

      public static void requestMicrophoneAccess(MediaDevicesListener listener)
      Requests access to the microphone only using the current page context.
      Parameters:
      listener - The listener that will receive media events.
    • requestMicrophoneAccess

      public static void requestMicrophoneAccess(HtmlPage page, MediaDevicesListener listener)
      Requests access to the microphone only.
      Parameters:
      page - The page context.
      listener - The listener that will receive media events.
    • requestFullAccess

      public static void requestFullAccess(MediaDevicesListener listener)
      Requests access to both camera and microphone using the current page context.
      Parameters:
      listener - The listener that will receive media events.
    • requestFullAccess

      public static void requestFullAccess(HtmlPage page, MediaDevicesListener listener)
      Requests access to both camera and microphone.
      Parameters:
      page - The page context.
      listener - The listener that will receive media events.