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.
- Author:
- Werner Randelshofer
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classstatic enum -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intId of the audio track.static final String"Encoding" for black mouse cursor.static final String"Encoding" for white mouse cursor.static final String"Encoding" for yellow mouse cursor.protected ScheduledThreadPoolExecutorTimer for mouse captures.protected FormatThe input video format for cursor capture.protected ScheduledFuture<?>protected ScreenRecorder.MouseGrabberprotected FileWhere to store the movie.protected longThe start time of the recording.protected longThe stop time of the recording.protected intId of the video track.Fields inherited from class org.monte.media.beans.AbstractStateModel
changeEvent, listenerList -
Constructor Summary
ConstructorsConstructorDescriptionCreates 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.ScreenRecorder(GraphicsConfiguration cfg, Format fileFormat, Format screenFormat, Format mouseFormat, Format audioFormat) Creates a screen recorder. -
Method Summary
Modifier and TypeMethodDescriptionvoidabort()Aborts the screen recorder.protected FilecreateMovieFile(Format fileFormat) Creates a file for recording the movie.protected MovieWriterfloatReturns the audio level of the left channel or of the mono channel.floatReturns the audio level of the right channel.Gets the audio mixer used for sound input.Returns a list of all files that the screen recorder created.longMaximal file size.longMaximal recording time in milliseconds.longgetState()Returns the state of the recorder.Returns the state of the recorder.voidsetAudioMixer(Mixer mixer) Sets the audio mixer for sound input.voidsetMaxFileSize(long maxFileSize) voidsetMaxRecordingTime(long maxRecordingTime) Maximal recording time in milliseconds.voidstart()Starts the screen recorder.protected voidStarts mouse capture.voidstop()Stops the screen recorder.protected voidStops mouse capturing.protected voidWaits until mouse capturing stopped.protected voidWrites a buffer into the movie.Methods inherited from class org.monte.media.beans.AbstractStateModel
addChangeListener, fireStateChanged, removeChangeListener
-
Field Details
-
ENCODING_BLACK_CURSOR
"Encoding" for black mouse cursor.- See Also:
-
ENCODING_WHITE_CURSOR
"Encoding" for white mouse cursor.- See Also:
-
ENCODING_YELLOW_CURSOR
"Encoding" for yellow mouse cursor.- See Also:
-
mouseFormat
The input video format for cursor capture. "black" or "white". -
recordingStartTime
protected long recordingStartTimeThe start time of the recording. -
recordingStopTime
protected volatile long recordingStopTimeThe stop time of the recording. -
mouseCaptureTimer
Timer for mouse captures. -
videoTrack
protected int videoTrackId of the video track. -
audioTrack
protected int audioTrackId of the audio track. -
mouseGrabber
-
mouseFuture
-
movieFolder
Where to store the movie.
-
-
Constructor Details
-
ScreenRecorder
Creates a screen recorder.- Parameters:
cfg- Graphics configuration of the capture screen.- Throws:
IOExceptionAWTException
-
ScreenRecorder
public ScreenRecorder(GraphicsConfiguration cfg, Format fileFormat, Format screenFormat, Format mouseFormat, Format audioFormat) throws IOException, AWTException Creates a screen recorder.- Parameters:
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. TheEncodingKeymust be ENCODING_BLACK_CURSOR or ENCODING_WHITE_CURSOR. TheSampleRateKeycan be independent from thescreenFormat. 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.- Throws:
IOExceptionAWTException
-
ScreenRecorder
public ScreenRecorder(GraphicsConfiguration cfg, Rectangle captureArea, Format fileFormat, Format screenFormat, Format mouseFormat, Format audioFormat) throws IOException, AWTException Creates a screen recorder.- Parameters:
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. TheEncodingKeymust be ENCODING_BLACK_CURSOR or ENCODING_WHITE_CURSOR. TheSampleRateKeycan be independent from thescreenFormat. 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.- Throws:
IOExceptionAWTException
-
ScreenRecorder
public ScreenRecorder(GraphicsConfiguration cfg, Rectangle captureArea, Format fileFormat, Format screenFormat, Format mouseFormat, Format audioFormat, File movieFolder) throws IOException, AWTException Creates a screen recorder.- Parameters:
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. TheEncodingKeymust be ENCODING_BLACK_CURSOR or ENCODING_WHITE_CURSOR. TheSampleRateKeycan be independent from thescreenFormat. 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 movie- Throws:
IOExceptionAWTException
-
-
Method Details
-
createMovieWriter
- Throws:
IOException
-
getCreatedMovieFiles
Returns a list of all files that the screen recorder created. -
createMovieFile
Creates a file for recording the movie.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.
- Parameters:
fileFormat-- Returns:
- the file
- Throws:
IOException
-
getState
Returns the state of the recorder. -
getStateMessage
Returns the state of the recorder. -
getStartTime
public long getStartTime() -
start
Starts the screen recorder.- Throws:
IOException
-
startMouseCapture
Starts mouse capture.- Throws:
IOException
-
stopMouseCapture
protected void stopMouseCapture()Stops mouse capturing. Use methodwaitUntilMouseCaptureStopped()to wait until the capturing stopped. -
waitUntilMouseCaptureStopped
Waits until mouse capturing stopped. Invoke this method only after you invokedstopMouseCapture().- Throws:
InterruptedException
-
getAudioLevelLeft
public float getAudioLevelLeft()Returns the audio level of the left channel or of the mono channel.- Returns:
- A value in the range [0.0,1.0] or AudioSystem.NOT_SPECIFIED.
-
getAudioLevelRight
public float getAudioLevelRight()Returns the audio level of the right channel.- Returns:
- A value in the range [0.0,1.0] or AudioSystem.NOT_SPECIFIED.
-
stop
Stops the screen recorder.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.
- Throws:
IOException
-
abort
Aborts the screen recorder.Aborting the screen recorder may take some time, but is generally faster than stopping the recorder. All recorded files are deleted.
- Throws:
IOException
-
write
Writes a buffer into the movie. Since the file system may not be immediately available at all times, we do this asynchronously.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.
- Parameters:
buf- A buffer with un-encoded media data. Ifbuf.track==videoTrack, then the buffer contains aBufferedImageinbuffer.dataand aPointinbuffer.headerwith the recorded mouse location. The header is null if the mouse is outside the capture area, or mouse recording has not been enabled.- Throws:
IOExceptionInterruptedException
-
getMaxRecordingTime
public long getMaxRecordingTime()Maximal recording time in milliseconds. If this time is exceeded, the recorder creates a new file. -
setMaxRecordingTime
public void setMaxRecordingTime(long maxRecordingTime) Maximal recording time in milliseconds. -
getMaxFileSize
public long getMaxFileSize()Maximal file size. If this size is exceeded, the recorder creates a new file. -
setMaxFileSize
public void setMaxFileSize(long maxFileSize) -
getAudioMixer
Gets the audio mixer used for sound input. Returns null, if the default mixer is used. -
setAudioMixer
Sets the audio mixer for sound input. Set to null for the default audio mixer.
-