/* * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * * * * * * * * * * * * * * * * * * * * */ package com.sun.media.jfxmedia; import java.util.Collections; import java.util.Map; import java.util.ArrayList; import java.util.List; import com.sun.media.jfxmedia.locator.Locator; import com.sun.media.jfxmedia.track.Track; /** * A class representing a particular media. * * @see MediaManager * @see MediaPlayer */ public abstract class Media { private Locator locator; private final List tracks = new ArrayList(); /** * Create a Media object. * * @param locator Locator of the Media * @throws IllegalArgumentException if locator * is null. */ protected Media(Locator locator) { if (locator == null) { throw new IllegalArgumentException("locator == null!"); } this.locator = locator; } /** * Adds a marker to the media playback. This marker will not be as precise * as embedded markers in the media file. * * @param markerName Arbitrary name of the marker * @param presentationTime Presentation time for the marker * @throws IllegalArgumentException if markerName * is null or presentationTime is negative. */ public abstract void addMarker(String markerName, double presentationTime); /** * Removes a marker by name. * * @param markerName Name of the marker * @return The presentation time of the deleted marker. * @throws IllegalArgumentException if markerName * is null. */ public abstract double removeMarker(String markerName); /** * Removes all markers, added programmatically, from the media playback. * Embedded markers will still cause notifications to fire. */ public abstract void removeAllMarkers(); /** * Gets the tracks found in the media. The returned value will be * null if no tracks have yet been encountered while scanning * the media. The returned List us unmodifiable. * * @return the tracks in the media or null if no tracks found. */ public List getTracks() { List returnValue; synchronized(tracks) { if (tracks.isEmpty()) { returnValue = null; } else { returnValue = Collections.unmodifiableList(new ArrayList(tracks)); } } return returnValue; } /** * Get the markers of the media. The returned * Map is unmodifiable. * * @return the markers or null if no markers found. */ public abstract Map getMarkers(); /** * Gets the Locator which was the source of the media. * * @return the source Locator. */ public Locator getLocator() { return locator; } /** * Adds a Track. * @throws IllegalArgumentException if track is * null. */ protected void addTrack(Track track) { if (track == null) { throw new IllegalArgumentException("track == null!"); } synchronized(tracks) { this.tracks.add(track); } } @Override public String toString() { StringBuffer buffer = new StringBuffer(); if(tracks != null && !tracks.isEmpty()) { for(Track track : tracks) { buffer.append(track); buffer.append("\n"); } } return buffer.toString(); } }