Class MediaDevicesApi
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidenumerateDevices(HtmlPage page, MediaDevicesListener listener) Enumerates available media devices.static voidenumerateDevices(MediaDevicesListener listener) Enumerates available media devices using the current page context.static voidgetUserMedia(HtmlPage page, MediaDevicesListener listener, boolean audio, boolean video) Requests access to user media (camera and/or microphone).static voidgetUserMedia(MediaDevicesListener listener, boolean audio, boolean video) Requests access to user media (camera and/or microphone) using the current page context.static voidrequestCameraAccess(HtmlPage page, MediaDevicesListener listener) Requests access to the camera only.static voidrequestCameraAccess(MediaDevicesListener listener) Requests access to the camera only using the current page context.static voidrequestFullAccess(HtmlPage page, MediaDevicesListener listener) Requests access to both camera and microphone.static voidrequestFullAccess(MediaDevicesListener listener) Requests access to both camera and microphone using the current page context.static voidrequestMicrophoneAccess(HtmlPage page, MediaDevicesListener listener) Requests access to the microphone only.static voidrequestMicrophoneAccess(MediaDevicesListener listener) Requests access to the microphone only using the current page context.
-
Constructor Details
-
MediaDevicesApi
public MediaDevicesApi()
-
-
Method Details
-
enumerateDevices
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
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
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
Requests access to the camera only using the current page context.- Parameters:
listener- The listener that will receive media events.
-
requestCameraAccess
Requests access to the camera only.- Parameters:
page- The page context.listener- The listener that will receive media events.
-
requestMicrophoneAccess
Requests access to the microphone only using the current page context.- Parameters:
listener- The listener that will receive media events.
-
requestMicrophoneAccess
Requests access to the microphone only.- Parameters:
page- The page context.listener- The listener that will receive media events.
-
requestFullAccess
Requests access to both camera and microphone using the current page context.- Parameters:
listener- The listener that will receive media events.
-
requestFullAccess
Requests access to both camera and microphone.- Parameters:
page- The page context.listener- The listener that will receive media events.
-