Search in sources :

Example 1 with TextTrackStyle

use of com.google.android.gms.cast.TextTrackStyle in project Shuttle by timusus.

the class TracksPreferenceManager method getTextTrackStyle.

public TextTrackStyle getTextTrackStyle() {
    final TextTrackStyle textTrackStyle = TextTrackStyle.fromSystemSettings(mContext);
    if (Utils.IS_KITKAT_OR_ABOVE) {
        return textTrackStyle;
    } else {
        // we need to populate all the fields ourselves
        textTrackStyle.setFontGenericFamily(FONT_FAMILY_MAPPING.get(getFontFamily()));
        textTrackStyle.setBackgroundColor(Color.parseColor(getBackgroundColor()));
        textTrackStyle.setEdgeType(EDGE_TYPE_MAPPING.get(getEdgeType()));
        textTrackStyle.setFontScale(getFontScale());
        boolean isBold = Typeface.DEFAULT.isBold();
        boolean isItalic = Typeface.DEFAULT.isItalic();
        int fontStyle = TextTrackStyle.FONT_STYLE_NORMAL;
        if (isBold && isItalic) {
            fontStyle = TextTrackStyle.FONT_STYLE_BOLD_ITALIC;
        } else if (!isBold && !isItalic) {
            fontStyle = TextTrackStyle.FONT_STYLE_NORMAL;
        } else if (isBold) {
            fontStyle = TextTrackStyle.FONT_STYLE_BOLD;
        }
        textTrackStyle.setFontStyle(fontStyle);
        textTrackStyle.setForegroundColor(combineColorAndOpacity(getTextColor(), getTextOpacity()));
        LOGD(TAG, "Edge is: " + getEdgeType());
        textTrackStyle.setBackgroundColor(combineColorAndOpacity(getBackgroundColor(), getBackgroundOpacity()));
    }
    return textTrackStyle;
}
Also used : TextTrackStyle(com.google.android.gms.cast.TextTrackStyle) SuppressLint(android.annotation.SuppressLint)

Example 2 with TextTrackStyle

use of com.google.android.gms.cast.TextTrackStyle in project butter-android by butterproject.

the class CastService method playMedia.

private void playMedia(final com.google.android.gms.cast.MediaInfo mediaInformation, final String mediaAppId, final LaunchListener listener) {
    final ApplicationConnectionResultCallback webAppLaunchCallback = new ApplicationConnectionResultCallback(new LaunchWebAppListener() {

        @Override
        public void onSuccess(final WebAppSession webAppSession) {
            ConnectionListener connectionListener = new ConnectionListener() {

                @Override
                public void onConnected() {
                    try {
                        mMediaPlayer.load(mApiClient, mediaInformation, true).setResultCallback(new ResultCallback<RemoteMediaPlayer.MediaChannelResult>() {

                            @Override
                            public void onResult(MediaChannelResult result) {
                                Status status = result.getStatus();
                                if (status.isSuccess()) {
                                    webAppSession.launchSession.setSessionType(LaunchSessionType.Media);
                                    // White text, black outline, no background
                                    TextTrackStyle textTrackStyle = new TextTrackStyle();
                                    textTrackStyle.setForegroundColor(Color.parseColor("#FFFFFFFF"));
                                    textTrackStyle.setBackgroundColor(Color.parseColor("#01000000"));
                                    textTrackStyle.setWindowType(TextTrackStyle.WINDOW_TYPE_NONE);
                                    textTrackStyle.setEdgeType(TextTrackStyle.EDGE_TYPE_OUTLINE);
                                    textTrackStyle.setEdgeColor(Color.BLACK);
                                    textTrackStyle.setFontGenericFamily(TextTrackStyle.FONT_FAMILY_SANS_SERIF);
                                    mMediaPlayer.setTextTrackStyle(mApiClient, textTrackStyle);
                                    mMediaPlayer.setActiveMediaTracks(mApiClient, new long[] { 1 });
                                    Util.postSuccess(listener, new MediaLaunchObject(webAppSession.launchSession, CastService.this));
                                } else {
                                    Util.postError(listener, new ServiceCommandError(status.getStatusCode(), status.getStatusMessage(), status));
                                }
                            }
                        });
                    } catch (Exception e) {
                        Util.postError(listener, new ServiceCommandError(0, "Unable to load", null));
                    }
                }
            };
            runCommand(connectionListener);
        }

        @Override
        public void onFailure(ServiceCommandError error) {
            Util.postError(listener, error);
        }
    });
    launchingAppId = mediaAppId;
    ConnectionListener connectionListener = new ConnectionListener() {

        @Override
        public void onConnected() {
            boolean relaunchIfRunning = false;
            try {
                if (Cast.CastApi.getApplicationStatus(mApiClient) == null || (!mediaAppId.equals(currentAppId))) {
                    relaunchIfRunning = true;
                }
                LaunchOptions options = new LaunchOptions();
                options.setRelaunchIfRunning(relaunchIfRunning);
                Cast.CastApi.launchApplication(mApiClient, mediaAppId, options).setResultCallback(webAppLaunchCallback);
            } catch (Exception e) {
                Util.postError(listener, new ServiceCommandError(0, "Unable to launch", null));
            }
        }
    };
    runCommand(connectionListener);
}
Also used : Status(com.google.android.gms.common.api.Status) ResultCallback(com.google.android.gms.common.api.ResultCallback) RemoteMediaPlayer(com.google.android.gms.cast.RemoteMediaPlayer) WebAppSession(com.connectsdk.service.sessions.WebAppSession) CastWebAppSession(com.connectsdk.service.sessions.CastWebAppSession) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) IOException(java.io.IOException) LaunchOptions(com.google.android.gms.cast.LaunchOptions) TextTrackStyle(com.google.android.gms.cast.TextTrackStyle) MediaChannelResult(com.google.android.gms.cast.RemoteMediaPlayer.MediaChannelResult)

Example 3 with TextTrackStyle

use of com.google.android.gms.cast.TextTrackStyle in project zype-android by zype.

the class TracksPreferenceManager method getTextTrackStyle.

public TextTrackStyle getTextTrackStyle() {
    final TextTrackStyle textTrackStyle = TextTrackStyle.fromSystemSettings(mContext);
    if (Utils.IS_KITKAT_OR_ABOVE) {
        return textTrackStyle;
    } else {
        // we need to populate all the fields ourselves
        textTrackStyle.setFontGenericFamily(FONT_FAMILY_MAPPING.get(getFontFamily()));
        textTrackStyle.setBackgroundColor(Color.parseColor(getBackgroundColor()));
        textTrackStyle.setEdgeType(EDGE_TYPE_MAPPING.get(getEdgeType()));
        textTrackStyle.setFontScale(getFontScale());
        boolean isBold = Typeface.DEFAULT.isBold();
        boolean isItalic = Typeface.DEFAULT.isItalic();
        int fontStyle = TextTrackStyle.FONT_STYLE_NORMAL;
        if (isBold && isItalic) {
            fontStyle = TextTrackStyle.FONT_STYLE_BOLD_ITALIC;
        } else if (!isBold && !isItalic) {
            fontStyle = TextTrackStyle.FONT_STYLE_NORMAL;
        } else if (isBold) {
            fontStyle = TextTrackStyle.FONT_STYLE_BOLD;
        }
        textTrackStyle.setFontStyle(fontStyle);
        textTrackStyle.setForegroundColor(combineColorAndOpacity(getTextColor(), getTextOpacity()));
        LOGD(TAG, "Edge is: " + getEdgeType());
        textTrackStyle.setBackgroundColor(combineColorAndOpacity(getBackgroundColor(), getBackgroundOpacity()));
    }
    return textTrackStyle;
}
Also used : TextTrackStyle(com.google.android.gms.cast.TextTrackStyle) SuppressLint(android.annotation.SuppressLint)

Aggregations

TextTrackStyle (com.google.android.gms.cast.TextTrackStyle)3 SuppressLint (android.annotation.SuppressLint)2 ServiceCommandError (com.connectsdk.service.command.ServiceCommandError)1 CastWebAppSession (com.connectsdk.service.sessions.CastWebAppSession)1 WebAppSession (com.connectsdk.service.sessions.WebAppSession)1 LaunchOptions (com.google.android.gms.cast.LaunchOptions)1 RemoteMediaPlayer (com.google.android.gms.cast.RemoteMediaPlayer)1 MediaChannelResult (com.google.android.gms.cast.RemoteMediaPlayer.MediaChannelResult)1 ResultCallback (com.google.android.gms.common.api.ResultCallback)1 Status (com.google.android.gms.common.api.Status)1 IOException (java.io.IOException)1