/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
package javafx.scene.media;
import java.util.Collections;
import java.util.Locale;
import java.util.Map;
/**
* A class representing a track contained in a media resource.
* A media resource may have multiple parallel tracks, such as a video
* track with several audio tracks in different languages. The types of tracks
* supported by the system may be inferred from the existing subclasses of this
* class. Not all media resources will contain a track of each supported type,
* and the time span of a given track need not be commensurate with the time
* span of the containing media.
* @since JavaFX 2.0
*/
public abstract class Track {
/**
* The name of the track or null
if the track is unnamed.
*/
private String name;
private long trackID; // opaque, unique track ID used by players to identify it
private Locale locale;
private Map metadata;
/**
* Retrieves the name of the track.
* @return the track name or null
.
*/
public final String getName() {
return name;
}
/**
* The {@link Locale} specifying the language and possibly the country that
* the Track
contents are formatted for. For {@link AudioTrack}s
* this will be the language spoken, for {@link SubtitleTrack}s this will be
* the language presented in the captions. Not all Track
s will
* have an associated language, in which case this method will return null.
*
* @return the Track
s language information or null
* @since JavaFX 8.0
*/
public final Locale getLocale() {
return locale;
}
/**
* Get the track ID as defined by the media container format. The ID of each
* Track
must be unique for its source {@link Media}.
* @return the Track
s unique ID
* @since JavaFX 8.0
*/
public final long getTrackID() {
return trackID;
}
/**
* @return a Map containing all known metadata for this Track
* @since JavaFX 8.0
*/
public final Map getMetadata() {
return metadata;
}
Track(long trackID, Map metadata) {
this.trackID = trackID;
Object value = metadata.get("name");
if (null != value && value instanceof String) {
name = (String)value;
}
value = metadata.get("locale");
if (null != value && value instanceof Locale) {
locale = (Locale)value;
}
this.metadata = Collections.unmodifiableMap(metadata);
}
private String description;
@Override
public final String toString() {
synchronized(this) {
if (null == description) {
StringBuilder sb = new StringBuilder();
Map md = getMetadata();
sb.append(this.getClass().getName());
sb.append("[ track id = ");
sb.append(trackID);
for (Map.Entry entry : md.entrySet()) {
Object value = entry.getValue();
if (null != value) {
sb.append(", ");
sb.append(entry.getKey());
sb.append(" = ");
sb.append(value.toString());
}
}
sb.append("]");
description = sb.toString();
}
}
return description;
}
}