Search in sources :

Example 1 with CaptioningManager

use of android.view.accessibility.CaptioningManager in project Shuttle by timusus.

the class VideoCastManager method registerCaptionListener.

@SuppressLint("NewApi")
private void registerCaptionListener(final Context context) {
    if (Utils.IS_KITKAT_OR_ABOVE) {
        CaptioningManager captioningManager = (CaptioningManager) context.getSystemService(Context.CAPTIONING_SERVICE);
        captioningManager.addCaptioningChangeListener(new CaptioningManager.CaptioningChangeListener() {

            @Override
            public void onEnabledChanged(boolean enabled) {
                onTextTrackEnabledChanged(enabled);
            }

            @Override
            public void onUserStyleChanged(@NonNull CaptioningManager.CaptionStyle userStyle) {
                onTextTrackStyleChanged(mTrackManager.getTextTrackStyle());
            }

            @Override
            public void onFontScaleChanged(float fontScale) {
                onTextTrackStyleChanged(mTrackManager.getTextTrackStyle());
            }

            @Override
            public void onLocaleChanged(Locale locale) {
                onTextTrackLocaleChanged(locale);
            }
        });
    }
}
Also used : Locale(java.util.Locale) CaptioningManager(android.view.accessibility.CaptioningManager) SuppressLint(android.annotation.SuppressLint)

Example 2 with CaptioningManager

use of android.view.accessibility.CaptioningManager in project edx-app-android by edx.

the class PlayerFragment method displaySrtData.

/**
 * This function is used to display CC data when a transcript is selected
 */
private void displaySrtData() {
    if (subtitleDisplayHandler != null) {
        subtitleDisplayHandler.removeCallbacks(SUBTITLES_PROCESSOR_RUNNABLE);
    }
    resetClosedCaptioning();
    if (srtList != null && srtList.size() > 0) {
        String languageSubtitle = getSubtitleLanguage();
        // Check if captioning is enabled in accessibility settings and set the captioning language implicitly
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            if (languageSubtitle == null) {
                final CaptioningManager cManager = (CaptioningManager) getContext().getSystemService(Context.CAPTIONING_SERVICE);
                if (cManager.isEnabled()) {
                    final String defaultCcLanguage;
                    {
                        final Locale cManagerLocale = cManager.getLocale();
                        if (cManagerLocale != null) {
                            defaultCcLanguage = cManagerLocale.getLanguage();
                        } else {
                            defaultCcLanguage = Locale.getDefault().getLanguage();
                        }
                    }
                    if (srtList.containsKey(defaultCcLanguage)) {
                        languageSubtitle = defaultCcLanguage;
                        setSubtitleLanguage(languageSubtitle);
                    }
                }
            }
        }
        if (languageSubtitle != null) {
            subtitlesObj = srtList.get(languageSubtitle);
            if (subtitlesObj != null) {
                closedCaptionsEnabled = true;
                if (player != null) {
                    environment.getAnalyticsRegistry().trackShowTranscript(videoEntry.videoId, player.getCurrentPosition() / AppConstants.MILLISECONDS_PER_SECOND, videoEntry.eid, videoEntry.lmsUrl);
                }
            }
        }
        if (transcriptListener != null) {
            if (subtitlesObj == null) {
                subtitlesObj = srtList.entrySet().iterator().next().getValue();
            }
            transcriptListener.updateTranscript(subtitlesObj);
        }
        // Run the subtitle handler if any among transcripts or closed captions is enabled
        if (subtitlesObj != null || transcriptListener != null) {
            if (subtitleDisplayHandler == null) {
                subtitleDisplayHandler = new Handler();
            }
            subtitleDisplayHandler.post(SUBTITLES_PROCESSOR_RUNNABLE);
        }
    }
}
Also used : Locale(java.util.Locale) CaptioningManager(android.view.accessibility.CaptioningManager) Handler(android.os.Handler)

Example 3 with CaptioningManager

use of android.view.accessibility.CaptioningManager in project zype-android by zype.

the class VideoCastManager method registerCaptionListener.

@SuppressLint("NewApi")
private void registerCaptionListener(final Context context) {
    if (Utils.IS_KITKAT_OR_ABOVE) {
        CaptioningManager captioningManager = (CaptioningManager) context.getSystemService(Context.CAPTIONING_SERVICE);
        captioningManager.addCaptioningChangeListener(new CaptioningManager.CaptioningChangeListener() {

            @Override
            public void onEnabledChanged(boolean enabled) {
                onTextTrackEnabledChanged(enabled);
            }

            @Override
            public void onUserStyleChanged(CaptioningManager.CaptionStyle userStyle) {
                onTextTrackStyleChanged(mTrackManager.getTextTrackStyle());
            }

            @Override
            public void onFontScaleChanged(float fontScale) {
                onTextTrackStyleChanged(mTrackManager.getTextTrackStyle());
            }

            @Override
            public void onLocaleChanged(Locale locale) {
                onTextTrackLocaleChanged(locale);
            }
        });
    }
}
Also used : Locale(java.util.Locale) CaptioningManager(android.view.accessibility.CaptioningManager) SuppressLint(android.annotation.SuppressLint)

Aggregations

CaptioningManager (android.view.accessibility.CaptioningManager)3 Locale (java.util.Locale)3 SuppressLint (android.annotation.SuppressLint)2 Handler (android.os.Handler)1