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

public abstract class VideoAdapter extends OSPRuntime.Supported implements Video
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
  • Field Details

    • rawImage

      protected Image rawImage
    • size

      protected Dimension size
    • displayedSize

      protected Dimension displayedSize
    • bufferedImage

      protected BufferedImage bufferedImage
    • filteredImage

      protected BufferedImage filteredImage
    • baseDir

      protected String 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

      protected ImageCoordSystem coords
    • aspects

      protected DoubleArray aspects
    • properties

      protected HashMap<String,Object> properties
    • filterStack

      protected FilterStack filterStack
    • clearRaster

      protected DataBufferInt clearRaster
    • startTimesMS

      protected double[] startTimesMS
      startTimes 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

      public void draw(DrawingPanel panel, Graphics g)
      Draws the video image on the panel.
      Specified by:
      draw in interface Drawable
      Parameters:
      panel - the drawing panel requesting the drawing
      g - the graphics context on which to draw
    • 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 interface Video
    • notifyFrame

      protected final void notifyFrame(int n, boolean isAsync)
    • getStartFrameNumber

      public final int getStartFrameNumber()
      Gets the start frame number.
      Specified by:
      getStartFrameNumber in interface Video
      Returns:
      the start frame number
      See Also:
    • setStartFrameNumber

      public final void setStartFrameNumber(int n)
      Sets the start frame number.
      Specified by:
      setStartFrameNumber in interface Video
      Parameters:
      n - the desired start frame number
      See Also:
    • getEndFrameNumber

      public final int getEndFrameNumber()
      Gets the end frame number.
      Specified by:
      getEndFrameNumber in interface Video
      Returns:
      the end frame number
      See Also:
    • setEndFrameNumber

      public final void setEndFrameNumber(int n)
      Sets the end frame number.
      Specified by:
      setEndFrameNumber in interface Video
      Parameters:
      n - the desired end frame number,
      See Also:
    • reset

      public final void reset()
      Stops the video and resets it to the start time.
      Specified by:
      reset in interface Video
    • goToStart

      public final void goToStart()
      Sets the frame number to the start frame.
      Specified by:
      goToStart in interface Video
    • goToEnd

      public final void goToEnd()
      Sets the frame number to the end frame.
      Specified by:
      goToEnd in interface Video
    • setPlaying

      @Deprecated public final void setPlaying(boolean playing)
      Deprecated.
      Not used. Starts and stops the video.
      Specified by:
      setPlaying in interface Video
      Parameters:
      playing - true starts the video, and false stops it
    • isPlaying

      public final boolean isPlaying()
      Gets the playing state of this video.
      Specified by:
      isPlaying in interface Video
      Returns:
      true if the video is playing
    • 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 interface Video
      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.
      Specified by:
      isLooping in interface Video
      Returns:
      true if the video loops
    • 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.
      Specified by:
      getRate in interface Video
      Returns:
      the relative play rate.
    • setVisible

      public final void setVisible(boolean visible)
      Shows or hides the video.
      Specified by:
      setVisible in interface DrawableImage
      Parameters:
      visible - true to show the video
    • isVisible

      public final boolean isVisible()
      Gets the visibility of the video.
      Specified by:
      isVisible in interface DrawableImage
      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 interface Measurable
      Returns:
      minimum x
    • getXMax

      public final double getXMax()
      Gets the maximum x needed to draw this object.
      Specified by:
      getXMax in interface Measurable
      Returns:
      maximum x
    • getYMin

      public final double getYMin()
      Gets the minimum y needed to draw this object.
      Specified by:
      getYMin in interface Measurable
      Returns:
      minimum y
    • getYMax

      public final double getYMax()
      Gets the maximum y needed to draw this object.
      Specified by:
      getYMax in interface Measurable
      Returns:
      maximum y
    • isMeasured

      public final boolean isMeasured()
      Reports whether information is available to set min/max values.
      Specified by:
      isMeasured in interface Measurable
      Returns:
      true if min/max values are valid
    • getRawBufferedImage

      public final BufferedImage getRawBufferedImage()
    • findInteractive

      public final Interactive findInteractive(DrawingPanel panel, int xpix, int ypix)
      Returns this video if enabled.
      Specified by:
      findInteractive in interface Interactive
      Parameters:
      panel - the drawing panel
      xpix - the x coordinate in pixels
      ypix - 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 interface Interactive
      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 interface Interactive
      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.
      Specified by:
      setFrameX in interface Video
      Parameters:
      n - the video frame number
      x - the world x position
    • 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 interface Interactive
      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.
      Specified by:
      setFrameY in interface Video
      Parameters:
      n - the video frame number
      y - the world y position
    • 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 interface Interactive
      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 interface Interactive
      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 interface Interactive
      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 interface Video
      Parameters:
      n - the video frame number
      x - the world x position
      y - 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 interface Interactive
      Parameters:
      x - the world x position
      y - 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 interface Video
      Parameters:
      n - the video frame number
      relativeAspect - 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 interface InteractiveImage
      Parameters:
      relativeAspect - the desired relative aspect
    • getRelativeAspect

      public final double getRelativeAspect()
      Gets the relative aspect of the current video frame.
      Specified by:
      getRelativeAspect in interface InteractiveImage
      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 interface Video
      Parameters:
      n - the video frame number
      width - 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 interface InteractiveImage
      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 interface InteractiveImage
      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 interface Video
      Parameters:
      n - the video frame number
      height - 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 interface InteractiveImage
      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 interface InteractiveImage
      Returns:
      the height of the video image
    • getImageSize

      public final Dimension getImageSize(boolean withFilters)
      Description copied from interface: Video
      Gets the image size as a Dimension
      Specified by:
      getImageSize in interface Video
      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 interface Video
      Parameters:
      n - the video frame number
      theta - 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 interface InteractiveImage
      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 interface InteractiveImage
      Returns:
      the angle in radians
    • step

      public final void step()
      Steps the video forward one frame.
      Specified by:
      step in interface Video
    • back

      public final void back()
      Steps the video back one frame.
      Specified by:
      back in interface Video
    • getFrameCount

      public final int getFrameCount()
      Gets the total number of video frames.
      Specified by:
      getFrameCount in interface Video
      Returns:
      the number of video frames
    • getFrameNumber

      public final int getFrameNumber()
      Gets the current video frame number.
      Specified by:
      getFrameNumber in interface Video
      Returns:
      the current frame number
    • finalize

      protected final void finalize()
      Overrides:
      finalize in class Object
    • 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

      protected final String getAbsolutePath(String path)
    • notifySize

      protected final void notifySize(Dimension newDim)
    • setFrameNumber

      public void setFrameNumber(int n)
      Sets the video frame number.
      Specified by:
      setFrameNumber in interface Video
      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 interface Video
      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 interface Video
      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 interface Video
      Returns:
      the start time in milliseconds, or -1 if not known
    • setStartTimes

      protected abstract void setStartTimes()
    • setStartTime

      @Deprecated public void setStartTime(double millis)
      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 interface Video
      Parameters:
      millis - the desired start time in milliseconds
    • getEndTime

      public double getEndTime()
      Gets the end frame time in milliseconds.
      Specified by:
      getEndTime in interface Video
      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 interface Video
      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.
      Specified by:
      setRate in interface Video
      Parameters:
      rate - the relative play rate. A rate of 1.0 plays at the normal rate.
    • getImage

      public BufferedImage getImage()
      Gets the current video image after applying enabled filters.
      Specified by:
      getImage in interface DrawableImage
      Returns:
      the current video image with filters applied
    • updateBufferedImage

      protected void updateBufferedImage()
    • setFrameCount

      protected void setFrameCount(int n)
    • setCoords

      public void setCoords(ImageCoordSystem newCoords)
      Sets the image coordinate system used to convert from imagespace to worldspace.
      Specified by:
      setCoords in interface InteractiveImage
      Parameters:
      newCoords - the image coordinate system
    • getCoords

      public ImageCoordSystem getCoords()
      Gets the image coordinate system.
      Specified by:
      getCoords in interface InteractiveImage
      Returns:
      the image coordinate system
    • setFilterStack

      public void setFilterStack(FilterStack stack)
      Sets the filter stack.
      Specified by:
      setFilterStack in interface DrawableImage
      Parameters:
      stack - the new filter stack
    • getFilterStack

      public FilterStack getFilterStack()
      Gets the filter stack.
      Specified by:
      getFilterStack in interface DrawableImage
      Returns:
      the filter stack
    • setProperty

      public void setProperty(String name, Object value)
      Sets a user property of the video.
      Specified by:
      setProperty in interface DrawableImage
      Parameters:
      name - the name of the property
      value - the value of the property
    • getProperty

      public Object getProperty(String name)
      Gets a user property of the video. May return null.
      Specified by:
      getProperty in interface DrawableImage
      Parameters:
      name - the name of the property
      Returns:
      the value of the property
    • getPropertyNames

      public Collection<String> getPropertyNames()
      Gets a collection of user property names for the video.
      Specified by:
      getPropertyNames in interface DrawableImage
      Returns:
      a collection of property names
    • dispose

      public void dispose()
      Disposes of this video.
      Specified by:
      dispose in interface Video
      Overrides:
      dispose in class OSPRuntime.Supported
    • propertyChange

      public void propertyChange(PropertyChangeEvent e)
      Responds to property change events.
      Specified by:
      propertyChange in interface PropertyChangeListener
      Parameters:
      e - the property change event