public class ScreenRecorder extends AbstractStateModel
Captures the screen, the mouse cursor and audio.
This class records mouse clicks occurring on other Java Windows running in the same JVM. Mouse clicks occurring in other JVM's and other processes are not recorded. This ability is useful for performing in-JVM recordings of an application that is being tested.
This recorder uses four threads. Three capture threads for screen, mouse cursor and audio, and one output thread for the movie writer.
FIXME - This class is a horrible mess.
| Modifier and Type | Class and Description |
|---|---|
protected static class |
ScreenRecorder.MouseGrabber |
static class |
ScreenRecorder.State |
| Modifier and Type | Field and Description |
|---|---|
protected int |
audioTrack
Id of the audio track.
|
static String |
ENCODING_BLACK_CURSOR
"Encoding" for black mouse cursor.
|
static String |
ENCODING_WHITE_CURSOR
"Encoding" for white mouse cursor.
|
static String |
ENCODING_YELLOW_CURSOR
"Encoding" for yellow mouse cursor.
|
protected ScheduledThreadPoolExecutor |
mouseCaptureTimer
Timer for mouse captures.
|
protected Format |
mouseFormat
The input video format for cursor capture.
|
protected ScheduledFuture |
mouseFuture |
protected ScreenRecorder.MouseGrabber |
mouseGrabber |
protected File |
movieFolder
Where to store the movie.
|
protected long |
recordingStartTime
The start time of the recording.
|
protected long |
recordingStopTime
The stop time of the recording.
|
protected int |
videoTrack
Id of the video track.
|
changeEvent, listenerList| Constructor and Description |
|---|
ScreenRecorder(GraphicsConfiguration cfg)
Creates a screen recorder.
|
ScreenRecorder(GraphicsConfiguration cfg,
Format fileFormat,
Format screenFormat,
Format mouseFormat,
Format audioFormat)
Creates a screen recorder.
|
ScreenRecorder(GraphicsConfiguration cfg,
Rectangle captureArea,
Format fileFormat,
Format screenFormat,
Format mouseFormat,
Format audioFormat)
Creates a screen recorder.
|
ScreenRecorder(GraphicsConfiguration cfg,
Rectangle captureArea,
Format fileFormat,
Format screenFormat,
Format mouseFormat,
Format audioFormat,
File movieFolder)
Creates a screen recorder.
|
| Modifier and Type | Method and Description |
|---|---|
protected File |
createMovieFile(Format fileFormat)
Creates a file for recording the movie.
|
protected MovieWriter |
createMovieWriter() |
float |
getAudioLevelLeft()
Returns the audio level of the left channel or of the mono channel.
|
float |
getAudioLevelRight()
Returns the audio level of the right channel.
|
Mixer |
getAudioMixer()
Gets the audio mixer used for sound input.
|
List<File> |
getCreatedMovieFiles()
Returns a list of all files that the screen recorder created.
|
long |
getMaxFileSize()
Maximal file size.
|
long |
getMaxRecordingTime()
Maximal recording time in milliseconds.
|
long |
getStartTime() |
ScreenRecorder.State |
getState()
Returns the state of the recorder.
|
String |
getStateMessage()
Returns the state of the recorder.
|
void |
setAudioMixer(Mixer mixer)
Sets the audio mixer for sound input.
|
void |
setMaxFileSize(long maxFileSize) |
void |
setMaxRecordingTime(long maxRecordingTime)
Maximal recording time in milliseconds.
|
void |
start()
Starts the screen recorder.
|
protected void |
startMouseCapture()
Starts mouse capture.
|
void |
stop()
Stops the screen recorder.
|
protected void |
stopMouseCapture()
Stops mouse capturing.
|
protected void |
waitUntilMouseCaptureStopped()
Waits until mouse capturing stopped.
|
protected void |
write(Buffer buf)
Writes a buffer into the movie.
|
addChangeListener, fireStateChanged, removeChangeListenerpublic static final String ENCODING_BLACK_CURSOR
public static final String ENCODING_WHITE_CURSOR
public static final String ENCODING_YELLOW_CURSOR
protected Format mouseFormat
protected long recordingStartTime
protected volatile long recordingStopTime
protected ScheduledThreadPoolExecutor mouseCaptureTimer
protected int videoTrack
protected int audioTrack
protected ScreenRecorder.MouseGrabber mouseGrabber
protected ScheduledFuture mouseFuture
protected File movieFolder
public ScreenRecorder(GraphicsConfiguration cfg) throws IOException, AWTException
cfg - Graphics configuration of the capture screen.IOExceptionAWTExceptionpublic ScreenRecorder(GraphicsConfiguration cfg, Format fileFormat, Format screenFormat, Format mouseFormat, Format audioFormat) throws IOException, AWTException
cfg - Graphics configuration of the capture screen.fileFormat - The file format "AVI" or "QuickTime".screenFormat - The video format for screen capture.mouseFormat - The video format for mouse capture. The
EncodingKey must be ENCODING_BLACK_CURSOR or
ENCODING_WHITE_CURSOR. The SampleRateKey can be independent from
the screenFormat. Specify null if you don't want to capture the
mouse cursor.audioFormat - The audio format for audio capture. Specify null if
you don't want audio capture.IOExceptionAWTExceptionpublic ScreenRecorder(GraphicsConfiguration cfg, Rectangle captureArea, Format fileFormat, Format screenFormat, Format mouseFormat, Format audioFormat) throws IOException, AWTException
cfg - Graphics configuration of the capture screen.captureArea - Defines the area of the screen that shall be captured.fileFormat - The file format "AVI" or "QuickTime".screenFormat - The video format for screen capture.mouseFormat - The video format for mouse capture. The
EncodingKey must be ENCODING_BLACK_CURSOR or
ENCODING_WHITE_CURSOR. The SampleRateKey can be independent from
the screenFormat. Specify null if you don't want to capture the
mouse cursor.audioFormat - The audio format for audio capture. Specify null if
you don't want audio capture.IOExceptionAWTExceptionpublic ScreenRecorder(GraphicsConfiguration cfg, Rectangle captureArea, Format fileFormat, Format screenFormat, Format mouseFormat, Format audioFormat, File movieFolder) throws IOException, AWTException
cfg - Graphics configuration of the capture screen.captureArea - Defines the area of the screen that shall be captured.fileFormat - The file format "AVI" or "QuickTime".screenFormat - The video format for screen capture.mouseFormat - The video format for mouse capture. The
EncodingKey must be ENCODING_BLACK_CURSOR or
ENCODING_WHITE_CURSOR. The SampleRateKey can be independent from
the screenFormat. Specify null if you don't want to capture the
mouse cursor.audioFormat - The audio format for audio capture. Specify null if
you don't want audio capture.movieFolder - Where to store the movieIOExceptionAWTExceptionprotected MovieWriter createMovieWriter() throws IOException
IOExceptionpublic List<File> getCreatedMovieFiles()
protected File createMovieFile(Format fileFormat) throws IOException
This implementation creates a file in the users "Video" folder on Windows, or in the users "Movies" folders on Mac OS X.
You can override this method, if you would like to create a movie file at a different location.
fileFormat - IOExceptionpublic ScreenRecorder.State getState()
public String getStateMessage()
public long getStartTime()
public void start()
throws IOException
IOExceptionprotected void startMouseCapture()
throws IOException
IOExceptionprotected void stopMouseCapture()
waitUntilMouseCaptureStopped()
to wait until the capturing stopped.protected void waitUntilMouseCaptureStopped()
throws InterruptedException
stopMouseCapture().InterruptedExceptionpublic float getAudioLevelLeft()
public float getAudioLevelRight()
public void stop()
throws IOException
Stopping the screen recorder may take several seconds, because audio capture uses a large capture buffer. Also, the MovieWriter has to finish up a movie file which may take some time depending on the amount of meta-data that needs to be written.
IOExceptionprotected void write(Buffer buf) throws IOException, InterruptedException
The buffer is copied and passed to the writer queue, which is consumed by the writer thread. See method startWriter().
AVI does not support a variable frame rate for the video track. Since we can not capture frames at a fixed frame rate we have to resend the same captured screen multiple times to the writer.
This method is called asynchronously from different threads.
You can override this method if you wish to process the media data.
buf - A buffer with un-encoded media data. If
buf.track==videoTrack, then the buffer contains a
BufferedImage in buffer.data and a Point in
buffer.header with the recorded mouse location. The header is
null if the mouse is outside the capture area, or mouse recording has not
been enabled.IOExceptionInterruptedExceptionpublic long getMaxRecordingTime()
public void setMaxRecordingTime(long maxRecordingTime)
public long getMaxFileSize()
public void setMaxFileSize(long maxFileSize)
public Mixer getAudioMixer()
public void setAudioMixer(Mixer mixer)
Copyright © 2014. All Rights Reserved.