Search in sources :

Example 1 with SubtitlesDialogFragment

use of com.zype.android.ui.dialog.SubtitlesDialogFragment in project zype-android by zype.

the class PlayerFragment method showClosedCaptionsDialog.

private void showClosedCaptionsDialog() {
    if (player == null) {
        return;
    }
    // Get CC tracks
    final List<CharSequence> tracks = new ArrayList<>();
    for (int i = 0; i < player.getTrackCount(CustomPlayer.TYPE_TEXT); i++) {
        MediaFormat mediaFormat = player.getTrackFormat(CustomPlayer.TYPE_TEXT, i);
        tracks.add(mediaFormat.trackId);
    }
    tracks.add(getString(R.string.subtitles_off));
    int selectedIndex;
    if (ccEnabled) {
        selectedIndex = getClosedCaptionsTrackIndex(SettingsProvider.getInstance().getString(SettingsProvider.SELECTED_CLOSED_CAPTIONS_TRACK));
    } else {
        selectedIndex = tracks.size() - 1;
    }
    // Show selection dialog
    SubtitlesDialogFragment.createAndShowSubtitlesDialogFragment(getActivity(), "Select track", tracks.toArray(new CharSequence[tracks.size()]), selectedIndex, new SubtitlesDialogFragment.ISubtitlesDialogListener() {

        @Override
        public void onItemSelected(SubtitlesDialogFragment dialog, int selectedItem) {
            if (selectedItem == tracks.size() - 1) {
                ccEnabled = false;
                ccTrack = "";
            } else {
                ccEnabled = true;
                ccTrack = tracks.get(selectedItem).toString();
            }
            SettingsProvider.getInstance().setBoolean(SettingsProvider.CLOSED_CAPTIONS_ENABLED, ccEnabled);
            SettingsProvider.getInstance().setString(SettingsProvider.SELECTED_CLOSED_CAPTIONS_TRACK, ccTrack);
            updateClosedCaptionsTrack();
            getActivity().invalidateOptionsMenu();
            dialog.dismiss();
        }
    });
}
Also used : MediaFormat(com.google.android.exoplayer.MediaFormat) ArrayList(java.util.ArrayList) SubtitlesDialogFragment(com.zype.android.ui.dialog.SubtitlesDialogFragment) Point(android.graphics.Point)

Aggregations

Point (android.graphics.Point)1 MediaFormat (com.google.android.exoplayer.MediaFormat)1 SubtitlesDialogFragment (com.zype.android.ui.dialog.SubtitlesDialogFragment)1 ArrayList (java.util.ArrayList)1