Example usage for android.media.tv TvTrackInfo getLanguage

List of usage examples for android.media.tv TvTrackInfo getLanguage

Introduction

In this page you can find the example usage for android.media.tv TvTrackInfo getLanguage.

Prototype

public final String getLanguage() 

Source Link

Document

Returns the language information encoded by either ISO 639-1 or ISO 639-2/T.

Usage

From source file:com.android.tv.MainActivity.java

private void applyClosedCaption() {
    List<TvTrackInfo> tracks = getTracks(TvTrackInfo.TYPE_SUBTITLE);
    if (tracks == null) {
        mTvOptionsManager.onClosedCaptionsChanged(null);
        return;//from w  ww  .ja  v  a 2 s .co m
    }

    boolean enabled = mCaptionSettings.isEnabled();
    mTvView.setClosedCaptionEnabled(enabled);

    String selectedTrackId = getSelectedTrack(TvTrackInfo.TYPE_SUBTITLE);
    TvTrackInfo alternativeTrack = null;
    if (enabled) {
        String language = mCaptionSettings.getLanguage();
        String trackId = mCaptionSettings.getTrackId();
        for (TvTrackInfo track : tracks) {
            if (Utils.isEqualLanguage(track.getLanguage(), language)) {
                if (track.getId().equals(trackId)) {
                    if (!track.getId().equals(selectedTrackId)) {
                        selectTrack(TvTrackInfo.TYPE_SUBTITLE, track);
                    } else {
                        // Already selected. Update the option string only.
                        mTvOptionsManager.onClosedCaptionsChanged(track);
                    }
                    if (DEBUG) {
                        Log.d(TAG, "Subtitle Track Selected {id=" + track.getId() + ", language="
                                + track.getLanguage() + "}");
                    }
                    return;
                } else if (alternativeTrack == null) {
                    alternativeTrack = track;
                }
            }
        }
        if (alternativeTrack != null) {
            if (!alternativeTrack.getId().equals(selectedTrackId)) {
                selectTrack(TvTrackInfo.TYPE_SUBTITLE, alternativeTrack);
            } else {
                mTvOptionsManager.onClosedCaptionsChanged(alternativeTrack);
            }
            if (DEBUG) {
                Log.d(TAG, "Subtitle Track Selected {id=" + alternativeTrack.getId() + ", language="
                        + alternativeTrack.getLanguage() + "}");
            }
            return;
        }
    }
    if (selectedTrackId != null) {
        selectTrack(TvTrackInfo.TYPE_SUBTITLE, null);
        if (DEBUG)
            Log.d(TAG, "Subtitle Track Unselected");
        return;
    }
    mTvOptionsManager.onClosedCaptionsChanged(null);
}

From source file:com.android.tv.MainActivity.java

private void saveClosedCaptionSetting(int option, String trackId) {
    mCaptionSettings.setEnableOption(option);
    if (option == CaptionSettings.OPTION_ON) {
        List<TvTrackInfo> tracks = getTracks(TvTrackInfo.TYPE_SUBTITLE);
        if (tracks != null) {
            for (TvTrackInfo track : tracks) {
                if (track.getId().equals(trackId)) {
                    mCaptionSettings.setLanguage(track.getLanguage());
                    mCaptionSettings.setTrackId(trackId);
                    return;
                }//from  w  w  w  .j av  a  2s .  c om
            }
        }
    }
}

From source file:com.android.tv.MainActivity.java

private void saveMultiAudioSetting(String trackId) {
    List<TvTrackInfo> tracks = getTracks(TvTrackInfo.TYPE_AUDIO);
    if (tracks != null) {
        for (TvTrackInfo track : tracks) {
            if (track.getId().equals(trackId)) {
                TvSettings.setMultiAudioId(this, track.getId());
                TvSettings.setMultiAudioLanguage(this, track.getLanguage());
                TvSettings.setMultiAudioChannelCount(this, track.getAudioChannelCount());
                return;
            }// w  ww  . jav  a  2 s  .  c  o  m
        }
    }
    TvSettings.setMultiAudioId(this, null);
    TvSettings.setMultiAudioLanguage(this, null);
    TvSettings.setMultiAudioChannelCount(this, 0);
}