com.google.android.gms.cast.framework.CastState Java Examples

The following examples show how to use com.google.android.gms.cast.framework.CastState. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GoogleCastDelegate.java    From edx-app-android with Apache License 2.0 6 votes vote down vote up
public void showIntroductoryOverlay(@NonNull Activity activity, @Nullable final MenuItem mediaRouteMenuItem) {
    if (castContext.getCastState() != CastState.NO_DEVICES_AVAILABLE) {
        if (introductoryOverlay != null) {
            introductoryOverlay.remove();
        }
        if (mediaRouteMenuItem != null && mediaRouteMenuItem.isVisible()) {
            new Handler().post(() -> {
                introductoryOverlay = new IntroductoryOverlay.Builder(
                        activity, mediaRouteMenuItem)
                        .setTitleText(context.getString(R.string.introducing_cast_text))
                        .setSingleTime()
                        .setOnOverlayDismissedListener(
                                () -> introductoryOverlay = null)
                        .build();
                introductoryOverlay.show();
            });
        }
    }
}
 
Example #2
Source File: MainActivity.java    From AndroidDemoProjects with Apache License 2.0 6 votes vote down vote up
@Override
public void onCastStateChanged(int newState) {
    Log.e("Tuts+", "onCastStateChanged");

    switch( newState ) {
        case CastState.CONNECTED: {

            break;
        } case CastState.CONNECTING: {

            break;
        } case CastState.NOT_CONNECTED: {

            break;
        } case CastState.NO_DEVICES_AVAILABLE: {

        }
    }

    if (newState != CastState.NO_DEVICES_AVAILABLE) {
        showIntroductoryOverlay();
    }
}
 
Example #3
Source File: VideoBrowserActivity.java    From cast-videos-android with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.video_browser);
    setupActionBar();

    mCastStateListener = new CastStateListener() {
        @Override
        public void onCastStateChanged(int newState) {
            if (newState != CastState.NO_DEVICES_AVAILABLE) {
                showIntroductoryOverlay();
            }
        }
    };

    mCastContext = CastContext.getSharedInstance(this);
}
 
Example #4
Source File: VideoBrowserActivity.java    From CastVideos-android with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.video_browser);
    setupActionBar();

    mCastStateListener = new CastStateListener() {
        @Override
        public void onCastStateChanged(int newState) {
            if (newState != CastState.NO_DEVICES_AVAILABLE) {
                showIntroductoryOverlay();
            }
        }
    };
    mCastContext = CastContext.getSharedInstance(this);
}
 
Example #5
Source File: StreamFragment.java    From Pocket-Plays-for-Twitch with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCastStateChanged(int i) {
    switch (i) {
        case CastState.CONNECTED:
            CastSession session = mCastContext != null ? mCastContext.getSessionManager().getCurrentCastSession() : null;
            if (session == null) break;
            castingTextView.setText(getString(R.string.stream_chromecast_playing, session.getCastDevice().getFriendlyName()));
            break;

        case CastState.CONNECTING:
            castingTextView.setText(getString(R.string.stream_chromecast_connecting));
            break;

        default:
            break;
    }
}
 
Example #6
Source File: Casty.java    From Casty with MIT License 5 votes vote down vote up
@NonNull
private CastStateListener createCastStateListener() {
    return new CastStateListener() {
        @Override
        public void onCastStateChanged(int state) {
            if (state != CastState.NO_DEVICES_AVAILABLE && introductionOverlay != null) {
                showIntroductionOverlay();
            }
        }
    };
}
 
Example #7
Source File: GoogleCastButtonManager.java    From react-native-google-cast with MIT License 5 votes vote down vote up
private void updateButtonState(MediaRouteButton button, int state) {
  // hide the button when no device available (default behavior is show it
  // disabled)
  if (CastState.NO_DEVICES_AVAILABLE == state) {
    button.setVisibility(View.GONE);
  } else {
    button.setVisibility(View.VISIBLE);
  }
}
 
Example #8
Source File: SessionManagerImpl.java    From android_packages_apps_GmsCore with Apache License 2.0 5 votes vote down vote up
public void onSessionStarting(SessionImpl session) {
    this.setCastState(CastState.CONNECTING);
    for (ISessionManagerListener listener : this.sessionManagerListeners) {
        try {
            listener.onSessionStarting(session.getSessionProxy().getWrappedSession());
        } catch (RemoteException e) {
            Log.d(TAG, "Remote exception calling onSessionStarting: " + e.getMessage());
        }
    }
}
 
Example #9
Source File: SessionManagerImpl.java    From android_packages_apps_GmsCore with Apache License 2.0 5 votes vote down vote up
public void onSessionStartFailed(SessionImpl session, int error) {
    this.currentSession = null;
    this.setCastState(CastState.NOT_CONNECTED);
    for (ISessionManagerListener listener : this.sessionManagerListeners) {
        try {
            listener.onSessionStartFailed(session.getSessionProxy().getWrappedSession(), error);
        } catch (RemoteException e) {
            Log.d(TAG, "Remote exception calling onSessionStartFailed: " + e.getMessage());
        }
    }
}
 
Example #10
Source File: SessionManagerImpl.java    From android_packages_apps_GmsCore with Apache License 2.0 5 votes vote down vote up
public void onSessionStarted(SessionImpl session, String sessionId) {
    this.currentSession = session;
    this.setCastState(CastState.CONNECTED);
    for (ISessionManagerListener listener : this.sessionManagerListeners) {
        try {
            listener.onSessionStarted(session.getSessionProxy().getWrappedSession(), sessionId);
        } catch (RemoteException e) {
            Log.d(TAG, "Remote exception calling onSessionStarted: " + e.getMessage());
        }
    }
}
 
Example #11
Source File: SessionManagerImpl.java    From android_packages_apps_GmsCore with Apache License 2.0 5 votes vote down vote up
public void onSessionResumed(SessionImpl session, boolean wasSuspended) {
    this.setCastState(CastState.CONNECTED);
    for (ISessionManagerListener listener : this.sessionManagerListeners) {
        try {
            listener.onSessionResumed(session.getSessionProxy().getWrappedSession(), wasSuspended);
        } catch (RemoteException e) {
            Log.d(TAG, "Remote exception calling onSessionResumed: " + e.getMessage());
        }
    }
}
 
Example #12
Source File: SessionManagerImpl.java    From android_packages_apps_GmsCore with Apache License 2.0 5 votes vote down vote up
public void onSessionEnded(SessionImpl session, int error) {
    this.currentSession = null;
    this.setCastState(CastState.NOT_CONNECTED);
    for (ISessionManagerListener listener : this.sessionManagerListeners) {
        try {
            listener.onSessionEnded(session.getSessionProxy().getWrappedSession(), error);
        } catch (RemoteException e) {
            Log.d(TAG, "Remote exception calling onSessionEnded: " + e.getMessage());
        }
    }
}
 
Example #13
Source File: SessionManagerImpl.java    From android_packages_apps_GmsCore with Apache License 2.0 5 votes vote down vote up
public void onSessionResumeFailed(SessionImpl session, int error) {
    this.currentSession = null;
    this.setCastState(CastState.NOT_CONNECTED);
    for (ISessionManagerListener listener : this.sessionManagerListeners) {
        try {
            listener.onSessionResumeFailed(session.getSessionProxy().getWrappedSession(), error);
        } catch (RemoteException e) {
            Log.d(TAG, "Remote exception calling onSessionResumeFailed: " + e.getMessage());
        }
    }
}
 
Example #14
Source File: SessionManagerImpl.java    From android_packages_apps_GmsCore with Apache License 2.0 5 votes vote down vote up
public void onSessionSuspended(SessionImpl session, int reason) {
    this.setCastState(CastState.NOT_CONNECTED);
    for (ISessionManagerListener listener : this.sessionManagerListeners) {
        try {
            listener.onSessionSuspended(session.getSessionProxy().getWrappedSession(), reason);
        } catch (RemoteException e) {
            Log.d(TAG, "Remote exception calling onSessionSuspended: " + e.getMessage());
        }
    }
}
 
Example #15
Source File: WatchLaterVideosFragment.java    From Loop with Apache License 2.0 4 votes vote down vote up
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    ((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);

    final ActionBar ab = ((AppCompatActivity) getActivity()).getSupportActionBar();
    if(ab != null){
        ab.setHomeAsUpIndicator(R.drawable.ic_menu_light);
        ab.setDisplayHomeAsUpEnabled(true);
        ab.setTitle(TrestleUtility.getFormattedText(getString(R.string.watch_later), font));
    }

    castStateListener = new CastStateListener() {
        @Override
        public void onCastStateChanged(int newState) {
            if (newState != CastState.NO_DEVICES_AVAILABLE) {
                showIntroductoryOverlay();
            }
        }
    };

    setUpRxBusSubscription();

    layoutManager = new LinearLayoutManager(getActivity());
    recyclerView.setLayoutManager(layoutManager);
    videosAdapter = new VideosAdapter();
    videosAdapter.setOnItemClickListener(this);
    videosAdapter.setOnReloadClickListener(this);

    recyclerView.setItemAnimator(new SlideInUpAnimator());
    recyclerView.setAdapter(videosAdapter);

    // Pagination
    recyclerView.addOnScrollListener(recyclerViewOnScrollListener);

    Call findWatchLaterVideosCall = vimeoService.findWatchLaterVideos(null,
            sortByValue,
            sortOrderValue,
            currentPage,
            PAGE_SIZE);
    calls.add(findWatchLaterVideosCall);
    findWatchLaterVideosCall.enqueue(findVideosFirstFetchCallback);
}
 
Example #16
Source File: GoogleCastDelegate.java    From edx-app-android with Apache License 2.0 4 votes vote down vote up
private void registerRemoteCallback() {
    if (castContext.getCastState() == CastState.CONNECTED) {
        castSession.getRemoteMediaClient().registerCallback(this);
    }
}
 
Example #17
Source File: StreamFragment.java    From Pocket-Plays-for-Twitch with GNU General Public License v3.0 4 votes vote down vote up
private void onCastMediaPlaying() {
    onCastStateChanged(CastState.CONNECTED);
}
 
Example #18
Source File: StreamFragment.java    From Pocket-Plays-for-Twitch with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Sends the URL to a chromecast (Or android TV) if it is connected.
 *
 * @param videoURL
 */
private void playOnCast(String videoURL) {
    //ToDo: We probably need to make a custom Cast receiver to play a link from Twitch. As Twitch doesnt allow third party receivers to play link from another origin
    // Use https://www.udacity.com/course/progress#!/c-ud875B and
    // https://github.com/googlecast/CastReferencePlayer
    try {
        String logoImageUrl = mChannelInfo.getLogoURLString();
        String streamerName = mChannelInfo.getDisplayName();
        if (mCastContext != null && mCastContext.getCastState() == CastState.CONNECTED) {
            MediaMetadata mediaMetadata = new MediaMetadata();
            mediaMetadata.putString(getString(R.string.stream_fragment_vod_id), vodId);
            mediaMetadata.putInt(getString(R.string.stream_fragment_vod_length), vodLength);
            mediaMetadata.putString(getString(R.string.stream_fragment_streamerInfo), new Gson().toJson(mChannelInfo));
            mediaMetadata.putString(MediaMetadata.KEY_TITLE, streamerName);
            if (logoImageUrl != null) {
                mediaMetadata.addImage(new WebImage(Uri.parse(logoImageUrl)));
            }

            MediaInfo.Builder mediaBuilder = new MediaInfo.Builder(videoURL)
                    .setMetadata(mediaMetadata)
                    .setContentType("application/x-mpegURL");


            if (vodId == null) {
                mediaBuilder
                        .setStreamType(MediaInfo.STREAM_TYPE_LIVE)
                        .setStreamDuration(MediaInfo.UNKNOWN_DURATION);
            } else {
                mediaBuilder
                        .setStreamType(MediaInfo.STREAM_TYPE_BUFFERED)
                        .setStreamDuration(vodLength / 1000);
            }


            CastSession session = mCastContext.getSessionManager().getCurrentCastSession();
            if (session != null) {
                checkChromecastConnection();
                session.getRemoteMediaClient().load(mediaBuilder.build(), true, 0);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}