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) {
body.registerListener(this, MediaDevicesEvent.class);
body.registerListener(this, MediaDevicesErrorEvent.class);
// Enumerate available devices
MediaDevicesApi.enumerateDevices(body);
}
@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(Element element) Enumerates available media devices using the current page context.static voidenumerateDevices(HtmlPage page, Element element) Enumerates available media devices.static voidgetUserMedia(Element element, boolean audio, boolean video) Requests access to user media (camera and/or microphone) using the current page context.static voidgetUserMedia(HtmlPage page, Element element, boolean audio, boolean video) Requests access to user media (camera and/or microphone).static voidrequestCameraAccess(Element element) Requests access to the camera only using the current page context.static voidrequestCameraAccess(HtmlPage page, Element element) Requests access to the camera only.static voidrequestFullAccess(Element element) Requests access to both camera and microphone using the current page context.static voidrequestFullAccess(HtmlPage page, Element element) Requests access to both camera and microphone.static voidrequestMicrophoneAccess(Element element) Requests access to the microphone only using the current page context.static voidrequestMicrophoneAccess(HtmlPage page, Element element) Requests access to the microphone only.
-
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:
element- The element 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.element- The element 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:
element- The element that will receive media events.audio- True to request audio access.video- True to request video access.
-
getUserMedia
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.element- The element 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:
element- The element that will receive media events.
-
requestCameraAccess
Requests access to the camera only.- Parameters:
page- The page context.element- The element that will receive media events.
-
requestMicrophoneAccess
Requests access to the microphone only using the current page context.- Parameters:
element- The element that will receive media events.
-
requestMicrophoneAccess
Requests access to the microphone only.- Parameters:
page- The page context.element- The element that will receive media events.
-
requestFullAccess
Requests access to both camera and microphone using the current page context.- Parameters:
element- The element that will receive media events.
-
requestFullAccess
Requests access to both camera and microphone.- Parameters:
page- The page context.element- The element that will receive media events.
-