Spec-Zone .ru
спецификации, руководства, описания, API
|
001/* 002 * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved. 003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 004 * 005 * This code is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU General Public License version 2 only, as 007 * published by the Free Software Foundation. Oracle designates this 008 * particular file as subject to the "Classpath" exception as provided 009 * by Oracle in the LICENSE file that accompanied this code. 010 * 011 * This code is distributed in the hope that it will be useful, but WITHOUT 012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 014 * version 2 for more details (a copy is included in the LICENSE file that 015 * accompanied this code). 016 * 017 * You should have received a copy of the GNU General Public License version 018 * 2 along with this work; if not, write to the Free Software Foundation, 019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 020 * 021 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 022 * or visit www.oracle.com if you need additional information or have any 023 * questions. 024 */ 025 026package javafx.scene.media; 027 028import java.util.Collections; 029import java.util.Locale; 030import java.util.Map; 031 032/** 033 * A class representing a track contained in a media resource. 034 * A media resource may have multiple parallel tracks, such as a video 035 * track with several audio tracks in different languages. The types of tracks 036 * supported by the system may be inferred from the existing subclasses of this 037 * class. Not all media resources will contain a track of each supported type, 038 * and the time span of a given track need not be commensurate with the time 039 * span of the containing media. 040 */ 041public abstract class Track { 042 /** 043 * The name of the track or <code>null</code> if the track is unnamed. 044 */ 045 private String name; 046 private long trackID; // opaque, unique track ID used by players to identify it 047 private Locale locale; 048 private Map<String,Object> metadata; 049 050 /** 051 * Retrieves the name of the track. 052 * @return the track name or <code>null</code>. 053 */ 054 public final String getName() { 055 return name; 056 } 057 058 /** 059 * The {@link Locale} specifying the language and possibly the country that 060 * the <code>Track</code> contents are formatted for. For {@link AudioTrack}s 061 * this will be the language spoken, for {@link SubtitleTrack}s this will be 062 * the language presented in the captions. Not all <code>Track</code>s will 063 * have an associated language, in which case this method will return null. 064 * 065 * @return the <code>Track</code>s language information or null 066 */ 067 public final Locale getLocale() { 068 return locale; 069 } 070 071 /** 072 * Get the track ID as defined by the media container format. The ID of each 073 * <code>Track</code> must be unique for its source {@link Media}. 074 * @return the <code>Track</code>s unique ID 075 */ 076 public final long getTrackID() { 077 return trackID; 078 } 079 080 /** 081 * @return a Map containing all known metadata for this <code>Track</code> 082 */ 083 public final Map<String,Object> getMetadata() { 084 return metadata; 085 } 086 087 Track(long trackID, Map<String,Object> metadata) { 088 this.trackID = trackID; 089 090 Object value = metadata.get("name"); 091 if (null != value && value instanceof String) { 092 name = (String)value; 093 } 094 095 value = metadata.get("locale"); 096 if (null != value && value instanceof Locale) { 097 locale = (Locale)value; 098 } 099 100 this.metadata = Collections.unmodifiableMap(metadata); 101 } 102 103 private String description; 104 @Override 105 public final String toString() { 106 synchronized(this) { 107 if (null == description) { 108 StringBuilder sb = new StringBuilder(); 109 Map<String,Object> md = getMetadata(); 110 111 sb.append(this.getClass().getName()); 112 sb.append("[ track id = "); 113 sb.append(trackID); 114 115 for (Map.Entry<String,Object> entry : md.entrySet()) { 116 Object value = entry.getValue(); 117 if (null != value) { 118 sb.append(", "); 119 sb.append(entry.getKey()); 120 sb.append(" = "); 121 sb.append(value.toString()); 122 } 123 } 124 sb.append("]"); 125 description = sb.toString(); 126 } 127 } 128 return description; 129 } 130}