All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sun.media.jfxmedia.Media Maven / Gradle / Ivy

There is a newer version: 24-ea+5
Show newest version
/*
 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.  Oracle designates this
 * particular file as subject to the "Classpath" exception as provided
 * by Oracle in the LICENSE file that accompanied this code.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */

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();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy