Package org.opensourcephysics.media.core
Class VideoAdapter
java.lang.Object
org.opensourcephysics.display.OSPRuntime.Supported
org.opensourcephysics.media.core.VideoAdapter
- All Implemented Interfaces:
PropertyChangeListener
,EventListener
,Drawable
,Interactive
,Measurable
,DrawableImage
,InteractiveImage
,Trackable
,Video
- Direct Known Subclasses:
GifVideo
,ImageVideo
,MovieVideo
This provides basic implementations of all Video methods. Subclasses should
provide a raw image for display--see ImageVideo or GifVideo for an example.
All public methods implement Video
- Version:
- 1.0
- Author:
- Douglas Brown
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
A class to save and load and save Video data. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected DoubleArray
protected String
protected BufferedImage
protected DataBufferInt
protected ImageCoordSystem
protected Dimension
protected int
protected BufferedImage
protected FilterStack
protected int
protected int
protected boolean
protected boolean
protected boolean
protected boolean
protected boolean
protected double
protected double
protected double
protected double
protected boolean
protected boolean
protected double
protected Image
protected Dimension
protected int
protected double[]
startTimes in MS.protected boolean
protected boolean
Fields inherited from interface org.opensourcephysics.media.core.Trackable
PROPERTY_ADJUSTING
Fields inherited from interface org.opensourcephysics.media.core.Video
PROPERTY_VIDEO_COORDS, PROPERTY_VIDEO_ENDFRAME, PROPERTY_VIDEO_FILTERCHANGED, PROPERTY_VIDEO_FRAMENUMBER, PROPERTY_VIDEO_IMAGE, PROPERTY_VIDEO_LOOPING, PROPERTY_VIDEO_NEXTFRAME, PROPERTY_VIDEO_PLAYING, PROPERTY_VIDEO_RATE, PROPERTY_VIDEO_SIZE, PROPERTY_VIDEO_VIDEOVISIBLE
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Protected constructor creates an empty Video -
Method Summary
Modifier and TypeMethodDescriptionfinal void
back()
Steps the video back one frame.void
dispose()
Disposes of this video.void
draw
(DrawingPanel panel, Graphics g) Draws the video image on the panel.protected final void
finalize()
final Interactive
findInteractive
(DrawingPanel panel, int xpix, int ypix) Returns this video if enabled.protected final void
Finds the min and max values of x and y.protected final String
getAbsolutePath
(String path) final double
getAngle()
Gets the angle in radians of the curent video frame measured ccw from the world x-axis.Gets the image coordinate system.final int
Gets the end frame number.double
Gets the end frame time in milliseconds.Gets the filter stack.final int
Gets the total number of video frames.final double
getFrameDuration
(int n) Gets the duration of the specified frame in milliseconds.final int
Gets the current video frame number.double
getFrameTime
(int i) Gets the start time of the specified frame in milliseconds.final double
Gets the current height of the video frame.getImage()
Gets the current video image after applying enabled filters.final Dimension
getImageSize
(boolean withFilters) Gets the image size as a DimensiongetProperty
(String name) Gets a user property of the video.Gets a collection of user property names for the video.final double
getRate()
Gets the relative play rate.final BufferedImage
final double
Gets the relative aspect of the current video frame.final int
Gets the start frame number.double
Gets the start frame time in milliseconds.final double
getWidth()
Gets the current width of the video frame.final double
getX()
Gets x position of upper left corner of the current video frame in world units.final double
getXMax()
Gets the maximum x needed to draw this object.final double
getXMin()
Gets the minimum x needed to draw this object.final double
getY()
Gets y position of upper left corner of the current video frame in world units.final double
getYMax()
Gets the maximum y needed to draw this object.final double
getYMin()
Gets the minimum y needed to draw this object.final void
goToEnd()
Sets the frame number to the end frame.final void
Sets the frame number to the start frame.protected final void
Initialize this video.final void
Invalidate the video and its filter so that it can be refreshed and so that data can be rebuilt.final boolean
Gets whether this responds to mouse hits.final boolean
Gets the looping state of the video.final boolean
Reports whether information is available to set min/max values.final boolean
Gets the playing state of this video.final boolean
Gets the visibility of the video.protected final void
notifyFrame
(int n, boolean isAsync) protected final void
notifySize
(Dimension newDim) void
Responds to property change events.protected final void
Refreshes the BufferedImage based on current size.final void
reset()
Stops the video and resets it to the start time.final void
setAngle
(double theta) Sets the angle in radians of all video frames measured ccw from the world x-axis.void
setCoords
(ImageCoordSystem newCoords) Sets the image coordinate system used to convert from imagespace to worldspace.final void
setEnabled
(boolean enabled) Sets whether this responds to mouse hits.final void
setEndFrameNumber
(int n) Sets the end frame number.void
setEndTime
(double millis) Sets the end frame to (nearly) a desired time in milliseconds.void
setFilterStack
(FilterStack stack) Sets the filter stack.final void
setFrameAngle
(int n, double theta) Sets the angle in radians of the specified video frame measured ccw from the world x-axis.protected void
setFrameCount
(int n) final void
setFrameHeight
(int n, double height) Sets the height of the specified video frame in world units.void
setFrameNumber
(int n) Sets the video frame number.final void
setFrameRelativeAspect
(int n, double relativeAspect) Sets the relative aspect of the specified video frame.final void
setFrameWidth
(int n, double width) Sets the width of the specified video frame in world units.final void
setFrameX
(int n, double x) Sets x position of upper left corner of the specified video frame in world units.final void
setFrameXY
(int n, double x, double y) Sets the x and y position of the UL corner of the specified video frame in world units.final void
setFrameY
(int n, double y) Sets y position of upper left corner of the specified video frame in world units.final void
setHeight
(double height) Sets the height of all video frames in world units.final void
setLooping
(boolean loops) Sets the looping state of this video.void
setNotify
(boolean b) final void
setPlaying
(boolean playing) Deprecated.void
setProperty
(String name, Object value) Sets a user property of the video.void
setRate
(double rate) Sets the rate at which the media plays relative to its normal rate.final void
setRelativeAspect
(double relativeAspect) Sets the relative aspect of all video frames.final void
setStartFrameNumber
(int n) Sets the start frame number.void
setStartTime
(double millis) Deprecated.protected abstract void
final void
setVisible
(boolean visible) Shows or hides the video.final void
setWidth
(double width) Sets the width of all video frames in world units.final void
setX
(double x) Sets x position of upper left corner of all video frames in world units.final void
setXY
(double x, double y) Sets the x and y position of the UL corner of all video frames in world units.final void
setY
(double y) Sets y position of upper left corner of all video frames in world units.final void
step()
Steps the video forward one frame.protected void
Methods inherited from class org.opensourcephysics.display.OSPRuntime.Supported
addListeners, addPropertyChangeListener, addPropertyChangeListener, addPropertyChangeListenerSafely, dispose, firePropertyChange, firePropertyChange, removeListeners, removePropertyChangeListener, removePropertyChangeListener
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.opensourcephysics.display.Interactive
isInteractive
Methods inherited from interface org.opensourcephysics.media.core.Video
addListener, addPropertyChangeListener, addPropertyChangeListener, getAverageFrameDuration, getAverageFrameRate, getFrameCountDurationMS, getOutliers, getTypeName, isValid, play, removeListener, removePropertyChangeListener, removePropertyChangeListener, stop
-
Field Details
-
rawImage
-
size
-
displayedSize
-
bufferedImage
-
filteredImage
-
baseDir
-
frameCount
protected int frameCount -
frameNumber
protected int frameNumber -
startFrameNumber
protected int startFrameNumber -
endFrameNumber
protected int endFrameNumber -
rate
protected double rate -
playing
protected boolean playing -
looping
protected boolean looping -
minX
protected double minX -
maxX
protected double maxX -
minY
protected double minY -
maxY
protected double maxY -
mouseEnabled
protected boolean mouseEnabled -
visible
protected boolean visible -
isMeasured
protected boolean isMeasured -
isValidMeasure
protected boolean isValidMeasure -
widthDominates
protected boolean widthDominates -
isValidImage
protected boolean isValidImage -
isValidFilteredImage
protected boolean isValidFilteredImage -
coords
-
aspects
-
properties
-
filterStack
-
clearRaster
-
startTimesMS
protected double[] startTimesMSstartTimes in MS. Created from MediaInfo.analyzeData(JavaScript) or from Xuggle(Java); passed through XMLControl "video" in TRK/TRZ to other platforms used in: VideoAdapter.getEndTime(), .setEndTime(), .getFrameDuration() Video.getAverageFrameRate(), .getOutliers(), isValid() MovieVideo.getFrameNumberBefore(), .setFromControl(), .setStartTimes(), .finalizeLoading()
-
-
Constructor Details
-
VideoAdapter
protected VideoAdapter()Protected constructor creates an empty Video
-
-
Method Details
-
setNotify
public void setNotify(boolean b) -
draw
Draws the video image on the panel. -
invalidateVideoAndFilter
public final void invalidateVideoAndFilter()Description copied from interface:Video
Invalidate the video and its filter so that it can be refreshed and so that data can be rebuilt.- Specified by:
invalidateVideoAndFilter
in interfaceVideo
-
notifyFrame
protected final void notifyFrame(int n, boolean isAsync) -
getStartFrameNumber
public final int getStartFrameNumber()Gets the start frame number.- Specified by:
getStartFrameNumber
in interfaceVideo
- Returns:
- the start frame number
- See Also:
-
setStartFrameNumber
public final void setStartFrameNumber(int n) Sets the start frame number.- Specified by:
setStartFrameNumber
in interfaceVideo
- Parameters:
n
- the desired start frame number- See Also:
-
getEndFrameNumber
public final int getEndFrameNumber()Gets the end frame number.- Specified by:
getEndFrameNumber
in interfaceVideo
- Returns:
- the end frame number
- See Also:
-
setEndFrameNumber
public final void setEndFrameNumber(int n) Sets the end frame number.- Specified by:
setEndFrameNumber
in interfaceVideo
- Parameters:
n
- the desired end frame number,- See Also:
-
reset
public final void reset()Stops the video and resets it to the start time. -
goToStart
public final void goToStart()Sets the frame number to the start frame. -
goToEnd
public final void goToEnd()Sets the frame number to the end frame. -
setPlaying
Deprecated.Not used. Starts and stops the video.- Specified by:
setPlaying
in interfaceVideo
- Parameters:
playing
-true
starts the video, andfalse
stops it
-
isPlaying
public final boolean isPlaying()Gets the playing state of this video. -
setLooping
public final void setLooping(boolean loops) Sets the looping state of this video. If true, the video restarts when reaching the end.- Specified by:
setLooping
in interfaceVideo
- Parameters:
loops
-true
if the video loops
-
isLooping
public final boolean isLooping()Gets the looping state of the video. If true, the video restarts when reaching the end. -
getRate
public final double getRate()Gets the relative play rate. Relative play rate is the ratio of a video's play rate to its preferred ("normal") play rate. -
setVisible
public final void setVisible(boolean visible) Shows or hides the video.- Specified by:
setVisible
in interfaceDrawableImage
- Parameters:
visible
-true
to show the video
-
isVisible
public final boolean isVisible()Gets the visibility of the video.- Specified by:
isVisible
in interfaceDrawableImage
- Returns:
true
if the video is visible
-
getXMin
public final double getXMin()Gets the minimum x needed to draw this object.- Specified by:
getXMin
in interfaceMeasurable
- Returns:
- minimum x
-
getXMax
public final double getXMax()Gets the maximum x needed to draw this object.- Specified by:
getXMax
in interfaceMeasurable
- Returns:
- maximum x
-
getYMin
public final double getYMin()Gets the minimum y needed to draw this object.- Specified by:
getYMin
in interfaceMeasurable
- Returns:
- minimum y
-
getYMax
public final double getYMax()Gets the maximum y needed to draw this object.- Specified by:
getYMax
in interfaceMeasurable
- Returns:
- maximum y
-
isMeasured
public final boolean isMeasured()Reports whether information is available to set min/max values.- Specified by:
isMeasured
in interfaceMeasurable
- Returns:
true
if min/max values are valid
-
getRawBufferedImage
-
findInteractive
Returns this video if enabled.- Specified by:
findInteractive
in interfaceInteractive
- Parameters:
panel
- the drawing panelxpix
- the x coordinate in pixelsypix
- the y coordinate in pixels- Returns:
- this if enabled, otherwise null
-
setEnabled
public final void setEnabled(boolean enabled) Sets whether this responds to mouse hits.- Specified by:
setEnabled
in interfaceInteractive
- Parameters:
enabled
-true
if this responds to mouse hits.
-
isEnabled
public final boolean isEnabled()Gets whether this responds to mouse hits.- Specified by:
isEnabled
in interfaceInteractive
- Returns:
true
if this responds to mouse hits.
-
setFrameX
public final void setFrameX(int n, double x) Sets x position of upper left corner of the specified video frame in world units. -
setX
public final void setX(double x) Sets x position of upper left corner of all video frames in world units.- Specified by:
setX
in interfaceInteractive
- Parameters:
x
- the world x position
-
setFrameY
public final void setFrameY(int n, double y) Sets y position of upper left corner of the specified video frame in world units. -
setY
public final void setY(double y) Sets y position of upper left corner of all video frames in world units.- Specified by:
setY
in interfaceInteractive
- Parameters:
y
- the world y position
-
getX
public final double getX()Gets x position of upper left corner of the current video frame in world units.- Specified by:
getX
in interfaceInteractive
- Returns:
- the world x position
-
getY
public final double getY()Gets y position of upper left corner of the current video frame in world units.- Specified by:
getY
in interfaceInteractive
- Returns:
- the world y position
-
setFrameXY
public final void setFrameXY(int n, double x, double y) Sets the x and y position of the UL corner of the specified video frame in world units.- Specified by:
setFrameXY
in interfaceVideo
- Parameters:
n
- the video frame numberx
- the world x positiony
- the world y position
-
setXY
public final void setXY(double x, double y) Sets the x and y position of the UL corner of all video frames in world units.- Specified by:
setXY
in interfaceInteractive
- Parameters:
x
- the world x positiony
- the world y position
-
setFrameRelativeAspect
public final void setFrameRelativeAspect(int n, double relativeAspect) Sets the relative aspect of the specified video frame. Relative aspect is the ratio of the world aspect to the pixel aspect of the image. The pixel aspect is the ratio of image width to height in pixels, and world aspect is the ratio of world width to height in world units. For example, a 320 x 240 pixel movie has a pixel aspect of 1.33. If relative aspect is 2, then the world aspect will be 2.67. So if the video's width is 16 wu, its height will be 6 wu. Or if its height is 10 wu, its width will be 26.67 wu.- Specified by:
setFrameRelativeAspect
in interfaceVideo
- Parameters:
n
- the video frame numberrelativeAspect
- the desired relative aspect
-
setRelativeAspect
public final void setRelativeAspect(double relativeAspect) Sets the relative aspect of all video frames. Relative aspect is the ratio of the world aspect to the pixel aspect of the image. The pixel aspect is the ratio of image width to height in pixels, and world aspect is the ratio of world width to height in world units. For example, a 320 x 240 pixel movie has a pixel aspect of 1.33. If relative aspect is 2, then the world aspect will be 2.67. So if the video's width is 16 wu, its height will be 6 wu. Or if its height is 10 wu, its width will be 26.67 wu.- Specified by:
setRelativeAspect
in interfaceInteractiveImage
- Parameters:
relativeAspect
- the desired relative aspect
-
getRelativeAspect
public final double getRelativeAspect()Gets the relative aspect of the current video frame.- Specified by:
getRelativeAspect
in interfaceInteractiveImage
- Returns:
- the relative aspect of the current image.
- See Also:
-
setFrameWidth
public final void setFrameWidth(int n, double width) Sets the width of the specified video frame in world units. Also sets the height using the relative aspect.- Specified by:
setFrameWidth
in interfaceVideo
- Parameters:
n
- the video frame numberwidth
- the width in world units- See Also:
-
setWidth
public final void setWidth(double width) Sets the width of all video frames in world units. Also sets the heights using the relative aspect.- Specified by:
setWidth
in interfaceInteractiveImage
- Parameters:
width
- the width in world units- See Also:
-
getWidth
public final double getWidth()Gets the current width of the video frame.- Specified by:
getWidth
in interfaceInteractiveImage
- Returns:
- the width of the video image
-
setFrameHeight
public final void setFrameHeight(int n, double height) Sets the height of the specified video frame in world units. Also sets the width using the relative aspect.- Specified by:
setFrameHeight
in interfaceVideo
- Parameters:
n
- the video frame numberheight
- the height in world units- See Also:
-
setHeight
public final void setHeight(double height) Sets the height of all video frames in world units. Also sets the widths using the relative aspect.- Specified by:
setHeight
in interfaceInteractiveImage
- Parameters:
height
- the height in world units- See Also:
-
getHeight
public final double getHeight()Gets the current height of the video frame.- Specified by:
getHeight
in interfaceInteractiveImage
- Returns:
- the height of the video image
-
getImageSize
Description copied from interface:Video
Gets the image size as a Dimension- Specified by:
getImageSize
in interfaceVideo
- Parameters:
withFilters
- true to return size displayed after filters are applied
-
setFrameAngle
public final void setFrameAngle(int n, double theta) Sets the angle in radians of the specified video frame measured ccw from the world x-axis. This results in a rotation only.- Specified by:
setFrameAngle
in interfaceVideo
- Parameters:
n
- the video frame numbertheta
- the angle in radians
-
setAngle
public final void setAngle(double theta) Sets the angle in radians of all video frames measured ccw from the world x-axis. This results in a rotation only.- Specified by:
setAngle
in interfaceInteractiveImage
- Parameters:
theta
- the angle in radians
-
getAngle
public final double getAngle()Gets the angle in radians of the curent video frame measured ccw from the world x-axis.- Specified by:
getAngle
in interfaceInteractiveImage
- Returns:
- the angle in radians
-
step
public final void step()Steps the video forward one frame. -
back
public final void back()Steps the video back one frame. -
getFrameCount
public final int getFrameCount()Gets the total number of video frames.- Specified by:
getFrameCount
in interfaceVideo
- Returns:
- the number of video frames
-
getFrameNumber
public final int getFrameNumber()Gets the current video frame number.- Specified by:
getFrameNumber
in interfaceVideo
- Returns:
- the current frame number
-
finalize
protected final void finalize() -
initialize
protected final void initialize()Initialize this video. -
refreshBufferedImage
protected final void refreshBufferedImage()Refreshes the BufferedImage based on current size. Creates a new image if needed. -
findMinMaxValues
protected final void findMinMaxValues()Finds the min and max values of x and y. -
getAbsolutePath
-
notifySize
-
setFrameNumber
public void setFrameNumber(int n) Sets the video frame number.- Specified by:
setFrameNumber
in interfaceVideo
- Parameters:
n
- the desired frame number- See Also:
-
getFrameTime
public double getFrameTime(int i) Gets the start time of the specified frame in milliseconds.- Specified by:
getFrameTime
in interfaceVideo
- Parameters:
i
- the frame number- Returns:
- the start time of the frame in milliseconds, or -1 if not known
-
getFrameDuration
public final double getFrameDuration(int n) Gets the duration of the specified frame in milliseconds.- Specified by:
getFrameDuration
in interfaceVideo
- Parameters:
n
- the frame number- Returns:
- the duration of the frame in milliseconds
-
getStartTime
public double getStartTime()Gets the start frame time in milliseconds.- Specified by:
getStartTime
in interfaceVideo
- Returns:
- the start time in milliseconds, or -1 if not known
-
setStartTimes
protected abstract void setStartTimes() -
setStartTime
Deprecated.never called Sets the start time in milliseconds. NOTE: the actual start time is normally set to the beginning of a frame.- Specified by:
setStartTime
in interfaceVideo
- Parameters:
millis
- the desired start time in milliseconds
-
getEndTime
public double getEndTime()Gets the end frame time in milliseconds.- Specified by:
getEndTime
in interfaceVideo
- Returns:
- the end time in milliseconds, or -1 if not known
-
setEndTime
public void setEndTime(double millis) Sets the end frame to (nearly) a desired time in milliseconds.- Specified by:
setEndTime
in interfaceVideo
- Parameters:
millis
- the desired end time in milliseconds
-
setRate
public void setRate(double rate) Description copied from interface:Video
Sets the rate at which the media plays relative to its normal rate. -
getImage
Gets the current video image after applying enabled filters.- Specified by:
getImage
in interfaceDrawableImage
- Returns:
- the current video image with filters applied
-
updateBufferedImage
protected void updateBufferedImage() -
setFrameCount
protected void setFrameCount(int n) -
setCoords
Sets the image coordinate system used to convert from imagespace to worldspace.- Specified by:
setCoords
in interfaceInteractiveImage
- Parameters:
newCoords
- the image coordinate system
-
getCoords
Gets the image coordinate system.- Specified by:
getCoords
in interfaceInteractiveImage
- Returns:
- the image coordinate system
-
setFilterStack
Sets the filter stack.- Specified by:
setFilterStack
in interfaceDrawableImage
- Parameters:
stack
- the new filter stack
-
getFilterStack
Gets the filter stack.- Specified by:
getFilterStack
in interfaceDrawableImage
- Returns:
- the filter stack
-
setProperty
Sets a user property of the video.- Specified by:
setProperty
in interfaceDrawableImage
- Parameters:
name
- the name of the propertyvalue
- the value of the property
-
getProperty
Gets a user property of the video. May return null.- Specified by:
getProperty
in interfaceDrawableImage
- Parameters:
name
- the name of the property- Returns:
- the value of the property
-
getPropertyNames
Gets a collection of user property names for the video.- Specified by:
getPropertyNames
in interfaceDrawableImage
- Returns:
- a collection of property names
-
dispose
public void dispose()Disposes of this video.- Specified by:
dispose
in interfaceVideo
- Overrides:
dispose
in classOSPRuntime.Supported
-
propertyChange
Responds to property change events.- Specified by:
propertyChange
in interfacePropertyChangeListener
- Parameters:
e
- the property change event
-