Example usage for android.media.tv TvTrackInfo TYPE_SUBTITLE

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

Introduction

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

Prototype

int TYPE_SUBTITLE

To view the source code for android.media.tv TvTrackInfo TYPE_SUBTITLE.

Click Source Link

Document

The type value for subtitle tracks.

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;//www  . j  a v  a2 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

public void selectTrack(int type, TvTrackInfo track) {
    mTvView.selectTrack(type, track == null ? null : track.getId());
    if (type == TvTrackInfo.TYPE_AUDIO) {
        mTvOptionsManager//  w  w w  . j a va2 s . com
                .onMultiAudioChanged(track == null ? null : Utils.getMultiAudioString(this, track, false));
    } else if (type == TvTrackInfo.TYPE_SUBTITLE) {
        mTvOptionsManager.onClosedCaptionsChanged(track);
    }
}

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;
                }/*  w w  w  . java2  s  .  c o m*/
            }
        }
    }
}