use of com.google.android.gms.cast.RemoteMediaPlayer.MediaChannelResult in project Shuttle by timusus.
the class VideoCastManager method onApplicationConnected.
@Override
protected void onApplicationConnected(ApplicationMetadata appMetadata, String applicationStatus, String sessionId, boolean wasLaunched) {
LOGD(TAG, "onApplicationConnected() reached with sessionId: " + sessionId + ", and mReconnectionStatus=" + mReconnectionStatus);
mApplicationErrorCode = NO_APPLICATION_ERROR;
if (mReconnectionStatus == RECONNECTION_STATUS_IN_PROGRESS) {
// we have tried to reconnect and successfully launched the app, so
// it is time to select the route and make the cast icon happy :-)
List<RouteInfo> routes = mMediaRouter.getRoutes();
if (routes != null) {
String routeId = mPreferenceAccessor.getStringFromPreference(PREFS_KEY_ROUTE_ID);
for (RouteInfo routeInfo : routes) {
if (routeId.equals(routeInfo.getId())) {
// found the right route
LOGD(TAG, "Found the correct route during reconnection attempt");
mReconnectionStatus = RECONNECTION_STATUS_FINALIZED;
mMediaRouter.selectRoute(routeInfo);
break;
}
}
}
}
startNotificationService();
try {
attachDataChannel();
attachMediaChannel();
mSessionId = sessionId;
// saving device for future retrieval; we only save the last session info
mPreferenceAccessor.saveStringToPreference(PREFS_KEY_SESSION_ID, mSessionId);
mRemoteMediaPlayer.requestStatus(mApiClient).setResultCallback(new ResultCallback<RemoteMediaPlayer.MediaChannelResult>() {
@Override
public void onResult(MediaChannelResult result) {
if (!result.getStatus().isSuccess()) {
onFailed(R.string.ccl_failed_status_request, result.getStatus().getStatusCode());
}
}
});
for (VideoCastConsumer consumer : mVideoConsumers) {
consumer.onApplicationConnected(appMetadata, mSessionId, wasLaunched);
}
} catch (TransientNetworkDisconnectionException e) {
LOGE(TAG, "Failed to attach media/data channel due to network issues", e);
onFailed(R.string.ccl_failed_no_connection_trans, NO_STATUS_CODE);
} catch (NoConnectionException e) {
LOGE(TAG, "Failed to attach media/data channel due to network issues", e);
onFailed(R.string.ccl_failed_no_connection, NO_STATUS_CODE);
}
}
use of com.google.android.gms.cast.RemoteMediaPlayer.MediaChannelResult in project zype-android by zype.
the class VideoCastManager method onTextTrackStyleChanged.
/**
* Signals a change in the Text Track style. Clients should not call this directly.
*/
public void onTextTrackStyleChanged(TextTrackStyle style) {
LOGD(TAG, "onTextTrackStyleChanged() reached");
if (mRemoteMediaPlayer == null || mRemoteMediaPlayer.getMediaInfo() == null) {
return;
}
mRemoteMediaPlayer.setTextTrackStyle(mApiClient, style).setResultCallback(new ResultCallback<MediaChannelResult>() {
@Override
public void onResult(MediaChannelResult result) {
if (!result.getStatus().isSuccess()) {
onFailed(R.string.ccl_failed_to_set_track_style, result.getStatus().getStatusCode());
}
}
});
for (VideoCastConsumer consumer : mVideoConsumers) {
try {
consumer.onTextTrackStyleChanged(style);
} catch (Exception e) {
LOGE(TAG, "onTextTrackStyleChanged(): Failed to inform " + consumer, e);
}
}
}
use of com.google.android.gms.cast.RemoteMediaPlayer.MediaChannelResult in project Shuttle by timusus.
the class VideoCastManager method onTextTrackStyleChanged.
/**
* Signals a change in the Text Track style. Clients should not call this directly.
*/
public void onTextTrackStyleChanged(TextTrackStyle style) {
LOGD(TAG, "onTextTrackStyleChanged() reached");
if (mRemoteMediaPlayer == null || mRemoteMediaPlayer.getMediaInfo() == null) {
return;
}
mRemoteMediaPlayer.setTextTrackStyle(mApiClient, style).setResultCallback(new ResultCallback<MediaChannelResult>() {
@Override
public void onResult(MediaChannelResult result) {
if (!result.getStatus().isSuccess()) {
onFailed(R.string.ccl_failed_to_set_track_style, result.getStatus().getStatusCode());
}
}
});
for (VideoCastConsumer consumer : mVideoConsumers) {
try {
consumer.onTextTrackStyleChanged(style);
} catch (Exception e) {
LOGE(TAG, "onTextTrackStyleChanged(): Failed to inform " + consumer, e);
}
}
}
use of com.google.android.gms.cast.RemoteMediaPlayer.MediaChannelResult 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);
}
use of com.google.android.gms.cast.RemoteMediaPlayer.MediaChannelResult in project butter-android by butterproject.
the class CastService method seek.
@Override
public void seek(final long position, final ResponseListener<Object> listener) {
if (mMediaPlayer == null || mMediaPlayer.getMediaStatus() == null) {
Util.postError(listener, new ServiceCommandError(0, "There is no media currently available", null));
return;
}
ConnectionListener connectionListener = new ConnectionListener() {
@Override
public void onConnected() {
try {
mMediaPlayer.seek(mApiClient, position, RemoteMediaPlayer.RESUME_STATE_UNCHANGED).setResultCallback(new ResultCallback<MediaChannelResult>() {
@Override
public void onResult(MediaChannelResult result) {
Status status = result.getStatus();
if (status.isSuccess()) {
Util.postSuccess(listener, null);
} else {
Util.postError(listener, new ServiceCommandError(status.getStatusCode(), status.getStatusMessage(), status));
}
}
});
} catch (Exception e) {
Util.postError(listener, new ServiceCommandError(0, "Unable to seek", null));
}
}
};
runCommand(connectionListener);
}
Aggregations