public class Capture extends Object
Capture
can "capture" media files from the device e.g. record audio, video and snap photos.
Notice that files returned by this class are potentially temporary files and might be
deleted by the OS in the future.
The code below demonstrates the capturing of a photo thru this API:
The code below demonstrates capturing and playing back audio files using this API:
Constructor and Description |
---|
Capture() |
Modifier and Type | Method and Description |
---|---|
static String |
captureAudio()
Capture the audio, blocking version that holds the EDT; alternatively you can use the Media API.
|
static void |
captureAudio(ActionListener response)
This method tries to invoke the device native hardware to capture audio.
|
static String |
captureAudio(MediaRecorderBuilder recordingOptions)
Capture the audio, blocking version that holds the EDT; alternatively you can use the Media API.
|
static void |
captureAudio(MediaRecorderBuilder recorderOptions,
ActionListener response)
This method tries to invoke the device native hardware to capture audio.
|
static String |
capturePhoto()
Invokes the camera and takes a photo synchronously while blocking the EDT
|
static void |
capturePhoto(ActionListener response)
This method tries to invoke the device native camera to capture images.
|
static String |
capturePhoto(int width,
int height)
Invokes the camera and takes a photo synchronously while blocking the EDT, the sample below
demonstrates a simple usage and applying a mask to the result
|
static String |
captureVideo()
Same as captureVideo only a blocking version that holds the EDT
|
static void |
captureVideo(ActionListener response)
This method tries to invoke the device native camera to capture video.
|
static String |
captureVideo(VideoCaptureConstraints constraints)
Same as
captureVideo(com.codename1.capture.VideoCaptureConstraints, com.codename1.ui.events.ActionListener) only a
blocking version that holds the EDT. |
static void |
captureVideo(VideoCaptureConstraints constraints,
ActionListener response)
Captures video with some constraints, like width, height, and max length.
|
static boolean |
hasCamera()
Returns true if the device has camera false otherwise.
|
public static boolean hasCamera()
public static void capturePhoto(ActionListener response)
response
- a callback Object to retrieve the file pathRuntimeException
- if this feature failed or unsupported on the platformpublic static String capturePhoto()
public static String captureAudio()
public static String captureAudio(MediaRecorderBuilder recordingOptions)
public static String captureVideo()
public static String captureVideo(VideoCaptureConstraints constraints)
captureVideo(com.codename1.capture.VideoCaptureConstraints, com.codename1.ui.events.ActionListener)
only a
blocking version that holds the EDT.constraints
- public static String capturePhoto(int width, int height)
Invokes the camera and takes a photo synchronously while blocking the EDT, the sample below demonstrates a simple usage and applying a mask to the result
width
- the target width for the image if possible, some platforms don't support scaling. To maintain aspect ratio set to -1height
- the target height for the image if possible, some platforms don't support scaling. To maintain aspect ratio set to -1public static void captureAudio(ActionListener response)
response
- a callback Object to retrieve the file pathRuntimeException
- if this feature failed or unsupported on the platformpublic static void captureAudio(MediaRecorderBuilder recorderOptions, ActionListener response)
use this in the actionPerformed to retrieve the file path. String path = (String) evt.getSource();
response
- a callback Object to retrieve the file pathRuntimeException
- if this feature failed or unsupported on the platformpublic static void captureVideo(VideoCaptureConstraints constraints, ActionListener response)
VideoCaptureConstraints.isSupported()
and VideoCaptureConstraints.isSizeSupported()
to check whether constraints are supported on the current platform. If constraints are not supported, then, in the worst case, this will fall
back to just use captureVideo(com.codename1.ui.events.ActionListener)
, i.e. capture with no constraints.constraints
- The constraints to use for the video capture.response
- a callback Object to retrieve the file pathpublic static void captureVideo(ActionListener response)
response
- a callback Object to retrieve the file pathRuntimeException
- if this feature failed or unsupported on the platformcaptureVideo(com.codename1.capture.VideoCaptureConstraints, com.codename1.ui.events.ActionListener)