javaandroidchromecastgoogle-cast-sdk

Chromecast crashes when cast icon clicked


I am trying to add Chromecast function to my Android app. I've been following the code lab tutorial from Google's cast dev page, I've managed to get it working using there test app. But when I try to copy the code to from the test app to my own app i get the option to connect to my test device. But once it connects it just resets my Chromecast, then disconnects again.

This is my CastOptionProvider Class

public final class CastOptionsProvider implements OptionsProvider {




@Override
public CastOptions getCastOptions(Context context) {
    return new CastOptions.Builder()
            .setReceiverApplicationId(context.getString(R.string.app_id))
            .build();
}

public List<SessionProvider> getAdditionalSessionProviders(Context context) {
    return null;
}
}

This is my activities xml that I want to have Chromecast support

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="studios.p9p.harrop99.p9pdocumentaries.Actual_Genres.Taboo">

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:minHeight="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

The activities java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_taboo);
    setupActionBar();
    mCastContext = CastContext.getSharedInstance(this);
}

 private void setupActionBar() {
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle("Taboo");
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
private MenuItem mediaRouteMenuItem;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.browse, menu);
    mediaRouteMenuItem = CastButtonFactory.setUpMediaRouteButton(getApplicationContext(), menu, R.id.media_route_menu_item);
    return true;
}

I know the tutorial is not complete yet but by this point in the tutorial I can connect to my test casting device and a casting logo appears on my screen. But in my own app it resets my Chromecast and does not actually connect. Also I have a Google speaker that in the tutorial it will offer to connect to this. It does not even show in my app.

Here is a link to the tutorial I'm following.

Edit

Do I need a custom receiver? If so where would I upload it to?


Solution

  • fixed this issue, it was that i needed a custom Reciever adding to my server. it was crashing because i was trying to use the basic a basic Reciever from Googles dev page. the basic reciever only allows for mp4 streams and direct video sources. But because im using youtube streams i had to use a package from github. this included a custom reciever to upload.

    the basic tutorial i used can be found here chromecast tutorial

    and his github can be found here github package and sample app

    i also want to thank Pier Francescosoffritti for all the hard work he has put in to this