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 classA class to save and load and save Video data. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected DoubleArrayprotected Stringprotected BufferedImageprotected DataBufferIntprotected ImageCoordSystemprotected Dimensionprotected intprotected BufferedImageprotected FilterStackprotected intprotected intprotected booleanprotected booleanprotected booleanprotected booleanprotected booleanprotected doubleprotected doubleprotected doubleprotected doubleprotected booleanprotected booleanprotected doubleprotected Imageprotected Dimensionprotected intprotected double[]startTimes in MS.protected booleanprotected booleanFields inherited from interface org.opensourcephysics.media.core.Trackable
PROPERTY_ADJUSTINGFields 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
ConstructorsModifierConstructorDescriptionprotectedProtected constructor creates an empty Video -
Method Summary
Modifier and TypeMethodDescriptionfinal voidback()Steps the video back one frame.voiddispose()Disposes of this video.voiddraw(DrawingPanel panel, Graphics g) Draws the video image on the panel.protected final voidfinalize()final InteractivefindInteractive(DrawingPanel panel, int xpix, int ypix) Returns this video if enabled.protected final voidFinds the min and max values of x and y.protected final StringgetAbsolutePath(String path) final doublegetAngle()Gets the angle in radians of the curent video frame measured ccw from the world x-axis.Gets the image coordinate system.final intGets the end frame number.doubleGets the end frame time in milliseconds.Gets the filter stack.final intGets the total number of video frames.final doublegetFrameDuration(int n) Gets the duration of the specified frame in milliseconds.final intGets the current video frame number.doublegetFrameTime(int i) Gets the start time of the specified frame in milliseconds.final doubleGets the current height of the video frame.getImage()Gets the current video image after applying enabled filters.final DimensiongetImageSize(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 doublegetRate()Gets the relative play rate.final BufferedImagefinal doubleGets the relative aspect of the current video frame.final intGets the start frame number.doubleGets the start frame time in milliseconds.final doublegetWidth()Gets the current width of the video frame.final doublegetX()Gets x position of upper left corner of the current video frame in world units.final doublegetXMax()Gets the maximum x needed to draw this object.final doublegetXMin()Gets the minimum x needed to draw this object.final doublegetY()Gets y position of upper left corner of the current video frame in world units.final doublegetYMax()Gets the maximum y needed to draw this object.final doublegetYMin()Gets the minimum y needed to draw this object.final voidgoToEnd()Sets the frame number to the end frame.final voidSets the frame number to the start frame.protected final voidInitialize this video.final voidInvalidate the video and its filter so that it can be refreshed and so that data can be rebuilt.final booleanGets whether this responds to mouse hits.final booleanGets the looping state of the video.final booleanReports whether information is available to set min/max values.final booleanGets the playing state of this video.final booleanGets the visibility of the video.protected final voidnotifyFrame(int n, boolean isAsync) protected final voidnotifySize(Dimension newDim) voidResponds to property change events.protected final voidRefreshes the BufferedImage based on current size.final voidreset()Stops the video and resets it to the start time.final voidsetAngle(double theta) Sets the angle in radians of all video frames measured ccw from the world x-axis.voidsetCoords(ImageCoordSystem newCoords) Sets the image coordinate system used to convert from imagespace to worldspace.final voidsetEnabled(boolean enabled) Sets whether this responds to mouse hits.final voidsetEndFrameNumber(int n) Sets the end frame number.voidsetEndTime(double millis) Sets the end frame to (nearly) a desired time in milliseconds.voidsetFilterStack(FilterStack stack) Sets the filter stack.final voidsetFrameAngle(int n, double theta) Sets the angle in radians of the specified video frame measured ccw from the world x-axis.protected voidsetFrameCount(int n) final voidsetFrameHeight(int n, double height) Sets the height of the specified video frame in world units.voidsetFrameNumber(int n) Sets the video frame number.final voidsetFrameRelativeAspect(int n, double relativeAspect) Sets the relative aspect of the specified video frame.final voidsetFrameWidth(int n, double width) Sets the width of the specified video frame in world units.final voidsetFrameX(int n, double x) Sets x position of upper left corner of the specified video frame in world units.final voidsetFrameXY(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 voidsetFrameY(int n, double y) Sets y position of upper left corner of the specified video frame in world units.final voidsetHeight(double height) Sets the height of all video frames in world units.final voidsetLooping(boolean loops) Sets the looping state of this video.voidsetNotify(boolean b) final voidsetPlaying(boolean playing) Deprecated.voidsetProperty(String name, Object value) Sets a user property of the video.voidsetRate(double rate) Sets the rate at which the media plays relative to its normal rate.final voidsetRelativeAspect(double relativeAspect) Sets the relative aspect of all video frames.final voidsetStartFrameNumber(int n) Sets the start frame number.voidsetStartTime(double millis) Deprecated.protected abstract voidfinal voidsetVisible(boolean visible) Shows or hides the video.final voidsetWidth(double width) Sets the width of all video frames in world units.final voidsetX(double x) Sets x position of upper left corner of all video frames in world units.final voidsetXY(double x, double y) Sets the x and y position of the UL corner of all video frames in world units.final voidsetY(double y) Sets y position of upper left corner of all video frames in world units.final voidstep()Steps the video forward one frame.protected voidMethods inherited from class org.opensourcephysics.display.OSPRuntime.Supported
addListeners, addPropertyChangeListener, addPropertyChangeListener, addPropertyChangeListenerSafely, dispose, firePropertyChange, firePropertyChange, removeListeners, removePropertyChangeListener, removePropertyChangeListenerMethods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.opensourcephysics.display.Interactive
isInteractiveMethods 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:VideoInvalidate the video and its filter so that it can be refreshed and so that data can be rebuilt.- Specified by:
invalidateVideoAndFilterin interfaceVideo
-
notifyFrame
protected final void notifyFrame(int n, boolean isAsync) -
getStartFrameNumber
public final int getStartFrameNumber()Gets the start frame number.- Specified by:
getStartFrameNumberin interfaceVideo- Returns:
- the start frame number
- See Also:
-
setStartFrameNumber
public final void setStartFrameNumber(int n) Sets the start frame number.- Specified by:
setStartFrameNumberin interfaceVideo- Parameters:
n- the desired start frame number- See Also:
-
getEndFrameNumber
public final int getEndFrameNumber()Gets the end frame number.- Specified by:
getEndFrameNumberin interfaceVideo- Returns:
- the end frame number
- See Also:
-
setEndFrameNumber
public final void setEndFrameNumber(int n) Sets the end frame number.- Specified by:
setEndFrameNumberin 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:
setPlayingin interfaceVideo- Parameters:
playing-truestarts the video, andfalsestops 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:
setLoopingin interfaceVideo- Parameters:
loops-trueif 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:
setVisiblein interfaceDrawableImage- Parameters:
visible-trueto show the video
-
isVisible
public final boolean isVisible()Gets the visibility of the video.- Specified by:
isVisiblein interfaceDrawableImage- Returns:
trueif the video is visible
-
getXMin
public final double getXMin()Gets the minimum x needed to draw this object.- Specified by:
getXMinin interfaceMeasurable- Returns:
- minimum x
-
getXMax
public final double getXMax()Gets the maximum x needed to draw this object.- Specified by:
getXMaxin interfaceMeasurable- Returns:
- maximum x
-
getYMin
public final double getYMin()Gets the minimum y needed to draw this object.- Specified by:
getYMinin interfaceMeasurable- Returns:
- minimum y
-
getYMax
public final double getYMax()Gets the maximum y needed to draw this object.- Specified by:
getYMaxin interfaceMeasurable- Returns:
- maximum y
-
isMeasured
public final boolean isMeasured()Reports whether information is available to set min/max values.- Specified by:
isMeasuredin interfaceMeasurable- Returns:
trueif min/max values are valid
-
getRawBufferedImage
-
findInteractive
Returns this video if enabled.- Specified by:
findInteractivein 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:
setEnabledin interfaceInteractive- Parameters:
enabled-trueif this responds to mouse hits.
-
isEnabled
public final boolean isEnabled()Gets whether this responds to mouse hits.- Specified by:
isEnabledin interfaceInteractive- Returns:
trueif 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:
setXin 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:
setYin 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:
getXin 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:
getYin 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:
setFrameXYin 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:
setXYin 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:
setFrameRelativeAspectin 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:
setRelativeAspectin interfaceInteractiveImage- Parameters:
relativeAspect- the desired relative aspect
-
getRelativeAspect
public final double getRelativeAspect()Gets the relative aspect of the current video frame.- Specified by:
getRelativeAspectin 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:
setFrameWidthin 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:
setWidthin 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:
getWidthin 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:
setFrameHeightin 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:
setHeightin 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:
getHeightin interfaceInteractiveImage- Returns:
- the height of the video image
-
getImageSize
Description copied from interface:VideoGets the image size as a Dimension- Specified by:
getImageSizein 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:
setFrameAnglein 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:
setAnglein 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:
getAnglein 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:
getFrameCountin interfaceVideo- Returns:
- the number of video frames
-
getFrameNumber
public final int getFrameNumber()Gets the current video frame number.- Specified by:
getFrameNumberin 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:
setFrameNumberin 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:
getFrameTimein 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:
getFrameDurationin 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:
getStartTimein 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:
setStartTimein interfaceVideo- Parameters:
millis- the desired start time in milliseconds
-
getEndTime
public double getEndTime()Gets the end frame time in milliseconds.- Specified by:
getEndTimein 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:
setEndTimein interfaceVideo- Parameters:
millis- the desired end time in milliseconds
-
setRate
public void setRate(double rate) Description copied from interface:VideoSets the rate at which the media plays relative to its normal rate. -
getImage
Gets the current video image after applying enabled filters.- Specified by:
getImagein 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:
setCoordsin interfaceInteractiveImage- Parameters:
newCoords- the image coordinate system
-
getCoords
Gets the image coordinate system.- Specified by:
getCoordsin interfaceInteractiveImage- Returns:
- the image coordinate system
-
setFilterStack
Sets the filter stack.- Specified by:
setFilterStackin interfaceDrawableImage- Parameters:
stack- the new filter stack
-
getFilterStack
Gets the filter stack.- Specified by:
getFilterStackin interfaceDrawableImage- Returns:
- the filter stack
-
setProperty
Sets a user property of the video.- Specified by:
setPropertyin 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:
getPropertyin 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:
getPropertyNamesin interfaceDrawableImage- Returns:
- a collection of property names
-
dispose
public void dispose()Disposes of this video.- Specified by:
disposein interfaceVideo- Overrides:
disposein classOSPRuntime.Supported
-
propertyChange
Responds to property change events.- Specified by:
propertyChangein interfacePropertyChangeListener- Parameters:
e- the property change event
-