- All Superinterfaces:
javafx.event.EventTarget,MediaEngine
- All Known Implementing Classes:
FXMediaRecorder,WebMediaRecorder
This class provides the controls for recording media.
MediaRecorder does not contain any visual elements so must
be used in combination with the MediaView class to view the video
stream from the camera device. After the recording is complete, use then
the MediaSource class to retrieve the recorded media.
MediaRecorder provides the start(), pause(),
and stop() controls as recording functionalities.
Use enable() to request access to the camera device and enable
the recording controls.
All operations of a MediaRecorder are inherently asynchronous.
Use the setOnReady(EventHandler) to get notified when the
MediaRecorder is ready to record. Other event handlers like
setOnStart(EventHandler), setOnPaused(EventHandler),
setOnResume(EventHandler), setOnStopped(EventHandler) and
setOnDataAvailable(EventHandler) can be used to get notified of the
corresponding events.
- Author:
- Besmir Beqiri
- See Also:
-
Property Summary
PropertiesTypePropertyDescriptionjavafx.beans.property.ReadOnlyObjectProperty<javafx.util.Duration> The current duration of the recording since it started.javafx.beans.property.ReadOnlyObjectProperty<MediaRecorderException> Observable property set to aMediaRecorderExceptionif an error occurs.javafx.beans.property.ReadOnlyObjectProperty<MediaSource> The current media source for this recorder.javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaRecorderEvent>> Event handler invoked when this recorder delivers media data to the application for its use.javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaRecorderEvent>> Event handler invoked when an error occurs.javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaRecorderEvent>> Event handler invoked when the recorder has paused, and status is set toMediaRecorder.Status.PAUSED.javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaRecorderEvent>> Event handler invoked when the status changes toREADY.javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaRecorderEvent>> Event handler invoked when recording has resumed and the status changes toMediaRecorder.Status.RECORDINGafter previously was set toMediaRecorder.Status.PAUSED.javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaRecorderEvent>> Event handler invoked when the recording started.javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaRecorderEvent>> Event handler invoked when recording stopped and the status changes toMediaRecorder.Status.INACTIVE.javafx.beans.property.ReadOnlyObjectProperty<MediaRecorder.Status> Recorder status hold the internal state for this recorder. -
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic MediaRecordercreate(javafx.stage.Stage stage) Creates a media recorder.javafx.beans.property.ReadOnlyObjectProperty<javafx.util.Duration> The current duration of the recording since it started.voidenable()Enable camera stream from the device.javafx.beans.property.ReadOnlyObjectProperty<MediaRecorderException> Observable property set to aMediaRecorderExceptionif an error occurs.javafx.util.DurationGets the current duration for the recording since it started.getError()Retrieve the value of theerrorproperty ornullif there is no error.Retrieves the current media source.javafx.event.EventHandler<MediaRecorderEvent> Retrieves the event handler when the recording has started and media data is delivered to the application.javafx.event.EventHandler<MediaRecorderEvent> Retrieves the event handler for errors.javafx.event.EventHandler<MediaRecorderEvent> Retrieves the event handler when the recording has paused and status is set toMediaRecorder.Status.PAUSED.javafx.event.EventHandler<MediaRecorderEvent> Retrieves theMediaRecorder.Status.READYevent handler.javafx.event.EventHandler<MediaRecorderEvent> Retrieves the event handler when recording has resumed and status changes toMediaRecorder.Status.RECORDINGafter previously was set toMediaRecorder.Status.PAUSED.javafx.event.EventHandler<MediaRecorderEvent> Retrieves the event handler when the recording has started and status is set toMediaRecorder.Status.RECORDING.javafx.event.EventHandler<MediaRecorderEvent> Retrieves the event handler when recording is stopped and status changes toMediaRecorder.Status.INACTIVE.Retrieves the current recorder status.javafx.beans.property.ReadOnlyObjectProperty<MediaSource> The current media source for this recorder.javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaRecorderEvent>> Event handler invoked when this recorder delivers media data to the application for its use.javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaRecorderEvent>> Event handler invoked when an error occurs.javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaRecorderEvent>> Event handler invoked when the recorder has paused, and status is set toMediaRecorder.Status.PAUSED.javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaRecorderEvent>> Event handler invoked when the status changes toREADY.javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaRecorderEvent>> Event handler invoked when recording has resumed and the status changes toMediaRecorder.Status.RECORDINGafter previously was set toMediaRecorder.Status.PAUSED.javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaRecorderEvent>> Event handler invoked when the recording started.javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaRecorderEvent>> Event handler invoked when recording stopped and the status changes toMediaRecorder.Status.INACTIVE.voidpause()Pauses the recording of media.voidsetOnDataAvailable(javafx.event.EventHandler<MediaRecorderEvent> value) Sets the event handler when the recording has started and media data is delivered to the application.voidsetOnError(javafx.event.EventHandler<MediaRecorderEvent> value) Sets the event handler to be called when an error occurs.voidsetOnPaused(javafx.event.EventHandler<MediaRecorderEvent> value) Sets the event handler when the media recorder has paused and status is set toMediaRecorder.Status.PAUSED.voidsetOnReady(javafx.event.EventHandler<MediaRecorderEvent> value) Sets theMediaRecorder.Status.READYevent handler.voidsetOnResume(javafx.event.EventHandler<MediaRecorderEvent> value) Sets the event handler when recording has resumed and status changes toMediaRecorder.Status.RECORDINGafter previously was set toMediaRecorder.Status.PAUSED.voidsetOnStart(javafx.event.EventHandler<MediaRecorderEvent> value) Sets the event handler when the recording has started and status is set toMediaRecorder.Status.RECORDING.voidsetOnStopped(javafx.event.EventHandler<MediaRecorderEvent> value) Sets the event handler when recording is stopped and status changes toMediaRecorder.Status.INACTIVE.voidstart()Begins recording media or resumes recording of media after having been paused.javafx.beans.property.ReadOnlyObjectProperty<MediaRecorder.Status> Recorder status hold the internal state for this recorder.voidstop()Stops the recording of media.Methods inherited from interface javafx.event.EventTarget
buildEventDispatchChain
-
Property Details
-
mediaSource
javafx.beans.property.ReadOnlyObjectProperty<MediaSource> mediaSourcePropertyThe current media source for this recorder.- See Also:
-
status
javafx.beans.property.ReadOnlyObjectProperty<MediaRecorder.Status> statusPropertyRecorder status hold the internal state for this recorder.- See Also:
-
duration
javafx.beans.property.ReadOnlyObjectProperty<javafx.util.Duration> durationPropertyThe current duration of the recording since it started. The value will be reset toDuration.ZEROwhen the recording is stopped.- See Also:
-
onReady
javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaRecorderEvent>> onReadyPropertyEvent handler invoked when the status changes toREADY.- See Also:
-
onDataAvailable
javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaRecorderEvent>> onDataAvailablePropertyEvent handler invoked when this recorder delivers media data to the application for its use.- See Also:
-
onStart
javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaRecorderEvent>> onStartPropertyEvent handler invoked when the recording started.- See Also:
-
onPaused
javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaRecorderEvent>> onPausedPropertyEvent handler invoked when the recorder has paused, and status is set toMediaRecorder.Status.PAUSED.- See Also:
-
onResume
javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaRecorderEvent>> onResumePropertyEvent handler invoked when recording has resumed and the status changes toMediaRecorder.Status.RECORDINGafter previously was set toMediaRecorder.Status.PAUSED.- See Also:
-
onStopped
javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaRecorderEvent>> onStoppedPropertyEvent handler invoked when recording stopped and the status changes toMediaRecorder.Status.INACTIVE.- See Also:
-
onError
javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaRecorderEvent>> onErrorPropertyEvent handler invoked when an error occurs.- See Also:
-
error
javafx.beans.property.ReadOnlyObjectProperty<MediaRecorderException> errorPropertyObservable property set to aMediaRecorderExceptionif an error occurs.- See Also:
-
-
Method Details
-
create
Creates a media recorder. If the application is running in a browser via JPro server, then a web version ofMediaRecorderis returned. If the application is not running inside the browser than a desktop/mobile version of the media recorder is returned.- Parameters:
stage- the application stage- Returns:
- a
MediaRecorderobject.
-
getMediaSource
MediaSource getMediaSource()Retrieves the current media source.- Returns:
MediaSourceobject
-
mediaSourceProperty
javafx.beans.property.ReadOnlyObjectProperty<MediaSource> mediaSourceProperty()The current media source for this recorder.- Returns:
- the
mediaSourceproperty - See Also:
-
getStatus
MediaRecorder.Status getStatus()Retrieves the current recorder status.- Returns:
- the recorder status
-
statusProperty
javafx.beans.property.ReadOnlyObjectProperty<MediaRecorder.Status> statusProperty()Recorder status hold the internal state for this recorder.- Returns:
- the
statusproperty - See Also:
-
getDuration
javafx.util.Duration getDuration()Gets the current duration for the recording since it started. -
durationProperty
javafx.beans.property.ReadOnlyObjectProperty<javafx.util.Duration> durationProperty()The current duration of the recording since it started. The value will be reset toDuration.ZEROwhen the recording is stopped.- Returns:
- the duration of the media
- See Also:
-
getOnReady
javafx.event.EventHandler<MediaRecorderEvent> getOnReady()Retrieves theMediaRecorder.Status.READYevent handler.- Returns:
- the event handler or
null.
-
setOnReady
Sets theMediaRecorder.Status.READYevent handler.- Parameters:
value- the event handler ornull.
-
onReadyProperty
javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaRecorderEvent>> onReadyProperty()Event handler invoked when the status changes toREADY.- Returns:
- the
onReadyproperty - See Also:
-
getOnDataAvailable
javafx.event.EventHandler<MediaRecorderEvent> getOnDataAvailable()Retrieves the event handler when the recording has started and media data is delivered to the application.- Returns:
- the event handler or
null.
-
setOnDataAvailable
Sets the event handler when the recording has started and media data is delivered to the application.- Parameters:
value- the event handler ornull.
-
onDataAvailableProperty
javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaRecorderEvent>> onDataAvailableProperty()Event handler invoked when this recorder delivers media data to the application for its use.- Returns:
- the
onDataAvailableproperty - See Also:
-
getOnStart
javafx.event.EventHandler<MediaRecorderEvent> getOnStart()Retrieves the event handler when the recording has started and status is set toMediaRecorder.Status.RECORDING.- Returns:
- the event handler or
null.
-
setOnStart
Sets the event handler when the recording has started and status is set toMediaRecorder.Status.RECORDING.- Parameters:
value- the event handler ornull.
-
onStartProperty
javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaRecorderEvent>> onStartProperty()Event handler invoked when the recording started.- Returns:
- the
onStartproperty - See Also:
-
getOnPaused
javafx.event.EventHandler<MediaRecorderEvent> getOnPaused()Retrieves the event handler when the recording has paused and status is set toMediaRecorder.Status.PAUSED.- Returns:
- the event handler or
null.
-
setOnPaused
Sets the event handler when the media recorder has paused and status is set toMediaRecorder.Status.PAUSED.- Parameters:
value- the event handler ornull.
-
onPausedProperty
javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaRecorderEvent>> onPausedProperty()Event handler invoked when the recorder has paused, and status is set toMediaRecorder.Status.PAUSED.- Returns:
- the
onPausedproperty - See Also:
-
getOnResume
javafx.event.EventHandler<MediaRecorderEvent> getOnResume()Retrieves the event handler when recording has resumed and status changes toMediaRecorder.Status.RECORDINGafter previously was set toMediaRecorder.Status.PAUSED.- Returns:
- the event handler or
null.
-
setOnResume
Sets the event handler when recording has resumed and status changes toMediaRecorder.Status.RECORDINGafter previously was set toMediaRecorder.Status.PAUSED.- Parameters:
value- the event handler ornull.
-
onResumeProperty
javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaRecorderEvent>> onResumeProperty()Event handler invoked when recording has resumed and the status changes toMediaRecorder.Status.RECORDINGafter previously was set toMediaRecorder.Status.PAUSED.- Returns:
- the
onResumeproperty - See Also:
-
getOnStopped
javafx.event.EventHandler<MediaRecorderEvent> getOnStopped()Retrieves the event handler when recording is stopped and status changes toMediaRecorder.Status.INACTIVE.- Returns:
- the event handler or
null.
-
setOnStopped
Sets the event handler when recording is stopped and status changes toMediaRecorder.Status.INACTIVE.- Parameters:
value- the event handler ornull.
-
onStoppedProperty
javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaRecorderEvent>> onStoppedProperty()Event handler invoked when recording stopped and the status changes toMediaRecorder.Status.INACTIVE.- Returns:
- the
onStoppedproperty - See Also:
-
getOnError
javafx.event.EventHandler<MediaRecorderEvent> getOnError()Retrieves the event handler for errors.- Returns:
- the event handler.
-
setOnError
Sets the event handler to be called when an error occurs.- Parameters:
value- the event handler ornull.
-
onErrorProperty
javafx.beans.property.ObjectProperty<javafx.event.EventHandler<MediaRecorderEvent>> onErrorProperty()Event handler invoked when an error occurs.- Returns:
- the
onErrorproperty - See Also:
-
getError
MediaRecorderException getError()Retrieve the value of theerrorproperty ornullif there is no error.- Returns:
- a
MediaRecorderExceptionornull.
-
errorProperty
javafx.beans.property.ReadOnlyObjectProperty<MediaRecorderException> errorProperty()Observable property set to aMediaRecorderExceptionif an error occurs.- Returns:
- the
errorproperty - See Also:
-
enable
void enable()Enable camera stream from the device. If this process is successful, then use theMediaView.create(MediaRecorder)method to create the camera view and show it. -
start
void start()Begins recording media or resumes recording of media after having been paused. -
pause
void pause()Pauses the recording of media. -
stop
void stop()Stops the recording of media.
-