T
- the image type of the frames in the videopublic class VideoDisplay<T extends Image<?,T>> extends Object implements Runnable
VideoDisplayListener
s can be added to be informed when the display is
about to be updated or has just been updated.
VideoDisplayStateListener
s can be added to be informed about when the
playback state of the display changes (e.g. when it entered play or pause
mode). VideoPositionListener
s can be added to be informed when the
video hits the start or end frame.
The video can be played, paused and stopped. Pause and stop have slightly
different semantics. After pause mode, the playback will continue from the
point of pause; whereas after stop mode, the playback will continue from the
start. Also, when in pause mode, frames are still sent to any listeners at
roughly the frame-rate of the video; compare this to stop mode where no video
events are fired. The default is that when the video comes to its end, the
display is automatically set to stop mode. The action at the end of the video
can be altered with setEndAction(EndAction)
.
The VideoDisplay constructor takes an DisplayUtilities.ImageComponent
which is used to
draw the video to. This allows video displays to be integrated into a Swing
UI. Use the createVideoDisplay(Video)
to have the video display
create an appropriate image component and a basic frame into which to display
the video. There is a createOffscreenVideoDisplay(Video)
method
which will not display the resulting component.
The player uses a separate object for controlling the speed of playback. The
TimeKeeper
class is used to generate timestamps which the video
display will do its best to synchronise with. A basic time keeper is
encapsulated in this class (VideoDisplay.BasicVideoTimeKeeper
) which is used for
video without audio. The timekeeper can be set using
setTimeKeeper(TimeKeeper)
. As video is read from the video stream,
each frame's timestamp is compared with the current time of the timekeeper.
If the frame should have been shown in the past the video display will
attempt to read video frames until the frame's timestamp is in the future.
Once its in the future it will wait until the frame's timestamp becomes
current (or in the past by a small amount). The frame is then displayed. Note
that in the case of live video, the display does not check to see if the
frame was in the past - it always assumes that Video.getNextFrame()
will return the latest frame to be displayed.
The VideoDisplay class can also accept an AudioStream
as input. If
this is supplied, an AudioPlayer
will be instantiated to playback the
audio and this audio player will be designated the TimeKeeper
for the
video playback. That means the audio will control the speed of playback for
the video. An example of playing back a video with sound might look like
this:
XuggleVideo xv = new XuggleVideo( videoFile );
XuggleAudio xa = new XuggleAudio( videoFile );
VideoDisplay vd = VideoDisplay.createVideoDisplay( xv, xa );
Modifier and Type | Class and Description |
---|---|
class |
VideoDisplay.BasicVideoTimeKeeper
A timekeeper for videos without audio - uses the system time to keep
track of where in a video a video should be.
|
static class |
VideoDisplay.EndAction
An enumerator for what to do when the video reaches the end.
|
static class |
VideoDisplay.Mode
Enumerator to represent the state of the player.
|
Constructor and Description |
---|
VideoDisplay(Video<T> v,
AudioStream a,
DisplayUtilities.ImageComponent screen)
Construct a video display with the given video and audio
|
VideoDisplay(Video<T> v,
DisplayUtilities.ImageComponent screen)
Construct a video display with the given video and frame.
|
Modifier and Type | Method and Description |
---|---|
void |
addVideoDisplayStateListener(VideoDisplayStateListener vdsl)
Add a listener for the state of this player.
|
void |
addVideoListener(VideoDisplayListener<T> dsl)
Add a listener that will get fired as every frame is displayed.
|
void |
addVideoPositionListener(VideoPositionListener vpl)
Add a video position listener to this display
|
void |
changeVideo(Video<T> newVideo)
Change the video that is being displayed by this video display.
|
void |
close()
Close the video display.
|
static <T extends Image<?,T>> |
createOffscreenVideoDisplay(Video<T> video)
Convenience function to create a VideoDisplay from a video in a new
window.
|
static VideoDisplay<FImage> |
createVideoDisplay(FImage[] images)
Convenience function to create a VideoDisplay from an array of images
|
static <T extends Image<?,T>> |
createVideoDisplay(Video<T> video)
Convenience function to create a VideoDisplay from a video in a new
window.
|
static <T extends Image<?,T>> |
createVideoDisplay(Video<T> video,
AudioStream audio)
Convenience function to create a VideoDisplay from a video in a new
window.
|
static <T extends Image<?,T>> |
createVideoDisplay(Video<T> video,
AudioStream audio,
JComponent comp)
Convenience function to create a VideoDisplay from a video in an existing
component.
|
static <T extends Image<?,T>> |
createVideoDisplay(Video<T> video,
AudioStream as,
JFrame screen)
Convenience function to create a VideoDisplay from a video in a new
window.
|
static <T extends Image<?,T>> |
createVideoDisplay(Video<T> video,
DisplayUtilities.ImageComponent ic)
Convenience function to create a VideoDisplay from a video in a new
window.
|
static <T extends Image<?,T>> |
createVideoDisplay(Video<T> video,
JComponent comp)
Convenience function to create a VideoDisplay from a video in an existing
component.
|
static <T extends Image<?,T>> |
createVideoDisplay(Video<T> video,
JFrame screen)
Convenience function to create a VideoDisplay from a video in a new
window.
|
void |
displayMode(boolean b)
Set whether to draw onscreen or not
|
protected void |
fireBeforeUpdate(T currentFrame)
Fire the event to the video listeners that a frame is about to be
displayed on the video.
|
protected void |
fireStateChanged()
Fire the state changed event
|
protected void |
fireVideoEndEvent()
Fire the event that says the video is at the end.
|
protected void |
fireVideoStartEvent()
Fire the event that says the video is at the start.
|
protected void |
fireVideoUpdate()
Fire the event to the video listeners that a frame has been put on the
display
|
double |
getDisplayFPS()
Returns the speed at which the display is being updated.
|
int |
getDroppedFrameCount()
Returns the number of frames that have been dropped while playing the
video.
|
protected VideoDisplay.Mode |
getMode()
Returns the current state of the video display.
|
double |
getPosition()
Returns the position of the play head in this video as a percentage of
the length of the video.
|
DisplayUtilities.ImageComponent |
getScreen()
Get the frame the video is being drawn to
|
Video<T> |
getVideo()
Get the video
|
boolean |
isCalculateFPS()
Returns whether the frames per second are being calculated at every
frame.
|
boolean |
isPaused()
Is the video paused?
|
boolean |
isStopped()
Returns whether the video is stopped or not.
|
protected void |
processEndAction(VideoDisplay.EndAction e)
Process the end of the video action.
|
void |
removeVideoDisplayStateListener(VideoDisplayStateListener vdsl)
Remove a listener from the state of this player
|
void |
removeVideoPositionListener(VideoPositionListener vpl)
Remove visible panty lines...
|
void |
resetDroppedFrameCount()
Reset the dropped frame count to zero.
|
void |
run() |
void |
seek(long toSeek)
Seek to a given timestamp in millis.
|
void |
setCalculateFPS(boolean calculateFPS)
Set whether the frames per second display rate will be calculated at
every frame.
|
void |
setEndAction(VideoDisplay.EndAction action)
Set the action to occur when the video reaches its end.
|
void |
setMode(VideoDisplay.Mode m)
Set whether this player is playing, paused or stopped.
|
void |
setPosition(double pc)
Set the position of the play head to the given percentage.
|
void |
setTimeKeeper(TimeKeeper<? extends Timecode> t)
Set the timekeeper to use for this video.
|
void |
togglePause()
Pause or resume the display.
|
public VideoDisplay(Video<T> v, DisplayUtilities.ImageComponent screen)
v
- the videoscreen
- the frame to draw into.public VideoDisplay(Video<T> v, AudioStream a, DisplayUtilities.ImageComponent screen)
v
- The videoa
- The audioscreen
- The frame to draw into.protected void processEndAction(VideoDisplay.EndAction e)
e
- The end action to processpublic void close()
public void setMode(VideoDisplay.Mode m)
m
- The new modeprotected VideoDisplay.Mode getMode()
VideoDisplay.Mode
protected void fireBeforeUpdate(T currentFrame)
currentFrame
- The frame that is about to be displayedprotected void fireVideoUpdate()
public DisplayUtilities.ImageComponent getScreen()
public void changeVideo(Video<T> newVideo)
newVideo
- The new video to display.public void addVideoListener(VideoDisplayListener<T> dsl)
dsl
- the listenerpublic void addVideoDisplayStateListener(VideoDisplayStateListener vdsl)
vdsl
- The listener to addpublic void removeVideoDisplayStateListener(VideoDisplayStateListener vdsl)
vdsl
- The listenerprotected void fireStateChanged()
public void addVideoPositionListener(VideoPositionListener vpl)
vpl
- The video position listenerpublic void removeVideoPositionListener(VideoPositionListener vpl)
vpl
- The video position listenerprotected void fireVideoStartEvent()
protected void fireVideoEndEvent()
public void togglePause()
public boolean isPaused()
public boolean isStopped()
public void setEndAction(VideoDisplay.EndAction action)
VideoDisplay.EndAction
enumeration.action
- The VideoDisplay.EndAction
action to occur.public static VideoDisplay<FImage> createVideoDisplay(FImage[] images)
images
- the imagespublic static <T extends Image<?,T>> VideoDisplay<T> createVideoDisplay(Video<T> video)
T
- the image type of the video framesvideo
- the videopublic static <T extends Image<?,T>> VideoDisplay<T> createVideoDisplay(Video<T> video, AudioStream audio)
T
- the image type of the video framesvideo
- the videoaudio
- the audio streampublic static <T extends Image<?,T>> VideoDisplay<T> createVideoDisplay(Video<T> video, JFrame screen)
T
- the image type of the video framesvideo
- The videoscreen
- The window to draw intopublic static <T extends Image<?,T>> VideoDisplay<T> createVideoDisplay(Video<T> video, AudioStream as, JFrame screen)
T
- the image type of the video framesvideo
- The videoas
- The audioscreen
- The window to draw intopublic static <T extends Image<?,T>> VideoDisplay<T> createVideoDisplay(Video<T> video, DisplayUtilities.ImageComponent ic)
T
- the image type of the video framesvideo
- The videoic
- The DisplayUtilities.ImageComponent
to draw intopublic static <T extends Image<?,T>> VideoDisplay<T> createOffscreenVideoDisplay(Video<T> video)
T
- the image type of the video framesvideo
- the videopublic static <T extends Image<?,T>> VideoDisplay<T> createVideoDisplay(Video<T> video, JComponent comp)
T
- the image type of the video framesvideo
- The videocomp
- The JComponent
to draw intopublic static <T extends Image<?,T>> VideoDisplay<T> createVideoDisplay(Video<T> video, AudioStream audio, JComponent comp)
T
- the image type of the video framesvideo
- The videoaudio
- The audiocomp
- The JComponent
to draw intopublic void displayMode(boolean b)
b
- if true then video is drawn to the screen, otherwise it is notpublic void seek(long toSeek)
toSeek
- timestamp to seek to in millis.public double getPosition()
public void setPosition(double pc)
pc
- The percentage to set the play head to.public double getDisplayFPS()
public void setTimeKeeper(TimeKeeper<? extends Timecode> t)
t
- The timekeeper.public int getDroppedFrameCount()
public void resetDroppedFrameCount()
public boolean isCalculateFPS()
getDisplayFPS()
will not
return a valid value.public void setCalculateFPS(boolean calculateFPS)
calculateFPS
- TRUE to calculate the FPS; FALSE otherwise.