Class MediaItem

java.lang.Object
paletai.mapping.MediaItem
Direct Known Subclasses:
GenerativeMediaItem

public class MediaItem extends Object
A class for managing media items (images/videos) with homography transformation capabilities. Handles loading, playback, and rendering of media files with perspective correction.

Key features include:

  • Automatic aspect ratio correction
  • Video playback control
  • Thumbnail generation
  • Homography transformation via VidMap
  • Media file management
  • Generative content support
  • UI controls for calibration and playback
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    int
    Assigned screen index and media identifier
    boolean
    Calibration mode status
    Base filename with scene index
    Content generator for generative media
    int
    Original media dimensions
    int
    Assigned screen index and media identifier
    int
    Original media dimensions
    processing.core.PImage
    Thumbnail representation
    float
    Thumbnail display position
    float
    Thumbnail display position
    Homography transformation handler
  • Constructor Summary

    Constructors
    Constructor
    Description
    MediaItem(processing.core.PApplet p, String filePath, int screenIndex, int mediaId)
    Constructs a new MediaItem from a file path.
    MediaItem(processing.core.PApplet p, LunaContentGenerator generator, int screenIndex, int mediaId)
    Constructs a generative MediaItem from a content generator.
    MediaItem(processing.core.PApplet p, LunaContentGenerator generator, processing.data.XML mediaXML)
    Constructs a generative MediaItem from XML configuration.
    MediaItem(processing.core.PApplet p, processing.data.XML mediaXML)
    Constructs a MediaItem from XML configuration.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    applyAspectRatioCorrection(int mediaWidth, int mediaHeight)
    Adjusts media display to maintain aspect ratio.
    void
    assignToDisplay(int w, int h, int screenIndex)
    Assigns this media item to a display with specific dimensions.
    void
    checkHover(float x, float y)
    Checks hover state for homography points at specified coordinates.
    void
    Generates a thumbnail image for this media item.
    Returns the filename of the media.
    Returns the full file path of the media.
    processing.opengl.PGraphics2D
    Returns the transformed media canvas with homography applied.
    processing.core.PImage
    Returns the thumbnail image for this media item.
    void
    Hides the media item's control group.
    boolean
    Checks if media is successfully loaded and ready for display.
    boolean
    Checks if this media item is a video file.
    void
    Starts media playback in loop mode.
    void
    Handles mouse release events for homography point interaction.
    void
    moveHoverPoint(float x, float y)
    Moves the hover point to specified coordinates.
    void
    Mutes video audio playback.
    void
    Turns off calibration mode for this media item.
    void
    Turns on calibration mode for this media item.
    void
    Starts media playback.
    void
    Renders the media with homography transformation.
    void
    Resets the homography transformation to default state.
    void
    setPreviewArea(float px, float py, float pw, float ph)
    Sets the preview area dimensions for homography point display.
    void
    setThumbnailPosition(int x, int y)
    Sets the thumbnail position and updates control group placement.
    void
    Shows the media item's control group.
    void
    Stops media playback and cleans up resources.
    void
    Toggles calibration mode for this media item.
    void
    Toggles input checking for homography points.
    void
    Toggles video loop mode.
    void
    Toggles video playback state.
    void
    updateHomography(processing.core.PVector[] xyNew, processing.core.PVector[] uvNew)
    Updates the homography transformation with new coordinate points.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • fileName

      public String fileName
      Base filename with scene index
    • thumbnail

      public processing.core.PImage thumbnail
      Thumbnail representation
    • thumbnailX

      public float thumbnailX
      Thumbnail display position
    • thumbnailY

      public float thumbnailY
      Thumbnail display position
    • vm

      public VidMap vm
      Homography transformation handler
    • mediaWidth

      public int mediaWidth
      Original media dimensions
    • mediaHeight

      public int mediaHeight
      Original media dimensions
    • assignedScreen

      public int assignedScreen
      Assigned screen index and media identifier
    • mediaId

      public int mediaId
      Assigned screen index and media identifier
    • calibrate

      public boolean calibrate
      Calibration mode status
    • generator

      public LunaContentGenerator generator
      Content generator for generative media
  • Constructor Details

    • MediaItem

      public MediaItem(processing.core.PApplet p, String filePath, int screenIndex, int mediaId)
      Constructs a new MediaItem from a file path.
      Parameters:
      p - The parent PApplet instance
      filePath - Path to media file
      screenIndex - The screen index this media is assigned to
      mediaId - Unique identifier for this media item
      Throws:
      RuntimeException - If media file cannot be loaded
    • MediaItem

      public MediaItem(processing.core.PApplet p, processing.data.XML mediaXML)
      Constructs a MediaItem from XML configuration. Recreates a media item from saved project data.
      Parameters:
      p - The parent PApplet instance
      mediaXML - XML element containing media configuration
    • MediaItem

      public MediaItem(processing.core.PApplet p, LunaContentGenerator generator, int screenIndex, int mediaId)
      Constructs a generative MediaItem from a content generator.
      Parameters:
      p - The parent PApplet instance
      generator - The content generator to use
      screenIndex - The screen index this media is assigned to
      mediaId - Unique identifier for this media item
    • MediaItem

      public MediaItem(processing.core.PApplet p, LunaContentGenerator generator, processing.data.XML mediaXML)
      Constructs a generative MediaItem from XML configuration. Recreates a generative media item from saved project data.
      Parameters:
      p - The parent PApplet instance
      generator - The content generator to use
      mediaXML - XML element containing media configuration
  • Method Details

    • showControls

      public void showControls()
      Shows the media item's control group. Makes the calibration and playback controls visible.
    • hideControls

      public void hideControls()
      Hides the media item's control group. Removes the calibration and playback controls from display.
    • setThumbnailPosition

      public void setThumbnailPosition(int x, int y)
      Sets the thumbnail position and updates control group placement. Positions the thumbnail and aligns the control group above it.
      Parameters:
      x - The x-coordinate for thumbnail placement
      y - The y-coordinate for thumbnail placement
    • assignToDisplay

      public void assignToDisplay(int w, int h, int screenIndex)
      Assigns this media item to a display with specific dimensions. Creates the media canvas, sets resolution, and configures the homography transformation for the target display. For generative content, calls the generator's setup method.
      Parameters:
      w - The width of the target display
      h - The height of the target display
      screenIndex - The index of the screen to assign to
      See Also:
    • isLoaded

      public boolean isLoaded()
      Checks if media is successfully loaded and ready for display.
      Returns:
      true if media is ready for display, false otherwise
    • applyAspectRatioCorrection

      public void applyAspectRatioCorrection(int mediaWidth, int mediaHeight)
      Adjusts media display to maintain aspect ratio. Automatically updates homography points to fit media properly within the display canvas while preserving the original aspect ratio.
      Parameters:
      mediaWidth - Original media width
      mediaHeight - Original media height
      See Also:
    • updateHomography

      public void updateHomography(processing.core.PVector[] xyNew, processing.core.PVector[] uvNew)
      Updates the homography transformation with new coordinate points. Wrapper method for VidMap's updateHomography functionality.
      Parameters:
      xyNew - New destination points for transformation
      uvNew - New source points for transformation
      See Also:
    • toggleCalibration

      public void toggleCalibration()
      Toggles calibration mode for this media item. Wrapper method for VidMap's toggleCalibration functionality.
      See Also:
    • offCalibration

      public void offCalibration()
      Turns off calibration mode for this media item. Wrapper method for VidMap's offCalibration functionality.
      See Also:
    • onCalibration

      public void onCalibration()
      Turns on calibration mode for this media item. Wrapper method for VidMap's onCalibration functionality.
      See Also:
    • toggleInput

      public void toggleInput()
      Toggles input checking for homography points. Enables or disables mouse interaction with transformation points.
      See Also:
    • checkHover

      public void checkHover(float x, float y)
      Checks hover state for homography points at specified coordinates. Wrapper method for VidMap's checkHover functionality.
      Parameters:
      x - The x-coordinate to check
      y - The y-coordinate to check
      See Also:
    • moveHoverPoint

      public void moveHoverPoint(float x, float y)
      Moves the hover point to specified coordinates. Wrapper method for VidMap's moveHoverPoint functionality.
      Parameters:
      x - The target x-coordinate
      y - The target y-coordinate
      See Also:
    • mouseReleased

      public void mouseReleased()
      Handles mouse release events for homography point interaction. Wrapper method for VidMap's mouseReleased functionality.
      See Also:
    • resetHomography

      public void resetHomography()
      Resets the homography transformation to default state. Clears custom transformation points and reapplies aspect ratio correction.
      See Also:
    • generateThumbnail

      public void generateThumbnail()
      Generates a thumbnail image for this media item. For generative content: captures the current generator output. For images: creates a resized copy of the original image. For videos: captures the first available frame and resizes it. Sets thumbnailGenerated flag to true when complete.
      See Also:
    • setPreviewArea

      public void setPreviewArea(float px, float py, float pw, float ph)
      Sets the preview area dimensions for homography point display. Wrapper method for VidMap's setPreviewArea functionality.
      Parameters:
      px - Preview area x-coordinate
      py - Preview area y-coordinate
      pw - Preview area width
      ph - Preview area height
      See Also:
    • render

      public void render()
      Renders the media with homography transformation. Handles static images, video playback, and generative content. For videos: reads new frames and manages thumbnail generation. For generative content: updates and draws the generator output. Applies homography transformation to the final output.
      See Also:
    • togglePlayback

      public void togglePlayback()
      Toggles video playback state. Plays if paused, pauses if playing. No effect on static images or generative content.
    • toggleLoop

      public void toggleLoop()
      Toggles video loop mode. Switches between single playback and continuous looping for video content.
    • playMedia

      public void playMedia()
      Starts media playback. For videos: begins playback from the start in single-play mode. Stops any existing playback before starting new playback. No effect on static images or generative content.
    • loopMedia

      public void loopMedia()
      Starts media playback in loop mode. For videos: begins continuous looping playback. Stops any existing playback before starting new looped playback. No effect on static images or generative content.
    • stopMedia

      public void stopMedia()
      Stops media playback and cleans up resources. For videos: stops playback, disposes native resources, and clears the display. Crucial for GStreamer cleanup to release native pipeline resources. No effect on static images or generative content.
    • muteMedia

      public void muteMedia()
      Mutes video audio playback. Sets video volume to zero if the video is not currently playing. No effect on static images or generative content.
    • getFilePath

      public String getFilePath()
      Returns the full file path of the media.
      Returns:
      The complete file path, or null for generative content
    • getFileName

      public String getFileName()
      Returns the filename of the media.
      Returns:
      The filename without path, or generator name for generative content
    • getThumbnail

      public processing.core.PImage getThumbnail()
      Returns the thumbnail image for this media item.
      Returns:
      The thumbnail PImage, or null if not generated
      See Also:
      • thumbnailGenerated
    • isVideo

      public boolean isVideo()
      Checks if this media item is a video file.
      Returns:
      true if this is a video media item
    • getMediaCanvas

      public processing.opengl.PGraphics2D getMediaCanvas()
      Returns the transformed media canvas with homography applied. Wrapper method for VidMap's getMediaCanvas functionality.
      Returns:
      PGraphics2D containing the transformed media output
      See Also: