/*
 * Copyright (c) 2008-2011, Oracle and/or its affiliates. All rights reserved.
 */

package javafx.scene.media;

import java.util.Locale;

import com.sun.javafx.beans.annotations.NoBuilder;

/**
 * A {@link Track} that describes an audio track. An audio track may for example
 * be the unique track in a piece of digital music or one of several tracks in
 * an audiovisual media resource.
 *
 * @see Track
 * @see Media
 */
@NoBuilder
public final class AudioTrack extends Track {
    private String language;

    /**
     * Retrieves the language of the audio track. The IANA language code might
     * be for example "en" for English or "ru" for Russian. The list of all
     * registered IANA language codes is available in the
     * <a href="http://www.iana.org/assignments/language-subtag-registry">
     * IANA Language Subtag Registry</a>.
     * @return the IANA language code or <code>null</code>.
     */
    public final String getLanguage() {
        return language;
    }

    /**
     * Creates a new {@link AudioTrack} from a {@link com.sun.media.jfxmedia.track.AudioTrack}.
     *
     * @param nativeTrack the implementation layer track.
     * @throws NullPointerException if <code>nativeTrack</code> is <code>null</code>.
     */
    AudioTrack(com.sun.media.jfxmedia.track.AudioTrack nativeTrack) {
        super(nativeTrack);

        Locale locale = ((com.sun.media.jfxmedia.track.AudioTrack) nativeTrack).getLocale();
        if (locale != null) {
            language = locale.getLanguage();
        } else {
            language = null;
        }
    }

    /**
     * Returns a string representation of this <code>AudioTrack</code> object.
     * @return a string representation of this <code>AudioTrack</code> object.
     */ 
    @Override
    public String toString() {
        return "Audio Track: name="+super.getName()+", language="+language;
    }
}
