1

Ive tried the Google Cast Android sample app, and is crashing for device below 5.0. Anyone has any idea why? below is my crash log:

08­30 12:38:57.242: E/AndroidRuntime(16269): Caused by: java.lang.RuntimeException: com.google.android.gms.internal.zzsb$zza: No acceptable module found. Local version is 0 and remote version is 0. 08­30 12:38:57.242: E/AndroidRuntime(16269): at com.google.android.gms.internal.zzni.zzbg(Unknown Source) 08­30 12:38:57.242: E/AndroidRuntime(16269): at com.google.android.gms.internal.zzni.zza(Unknown Source) 08­30 12:38:57.242: E/AndroidRuntime(16269): at com.google.android.gms.cast.framework.CastContext. 没有加一

Qing
  • 1,401
  • 2
  • 21
  • 41
  • Is this a real device that you are testing, or an emulator? Does it have the appropriate Google Play Services? – Ali Naddaf Sep 04 '16 at 06:21
  • I used a real device, samsung one, I think it has the appropriate google play services, and its the google sample app... – Qing Sep 05 '16 at 02:16
  • compile 'com.google.android.gms:play-services:9.4.0' compile 'com.android.support:appcompat-v7:24.1.1' compile 'com.android.support:mediarouter-v7:24.1.1' compile 'com.android.support:recyclerview-v7:24.1.1' compile 'com.google.android.gms:play-services-cast-framework:9.4.0' compile 'com.googlecode.android-query:android-query:0.25.9' – Qing Sep 05 '16 at 02:18

1 Answers1

6

There was a change in the latest Cast SDK that made it incompatible (crashing) with older versions of Google Play Services. Unfortunately, even cast sample app crashes when using latest Cast SDK with outdated GPS (or on emulators). The issue has been discussed here: https://github.com/googlecast/CastVideos-android/issues/12

The solution is to check Google Play Services version before initialising any cast components, including mini controller (i.e. you can't just put mini controller fragment into your xml layout file - you either have to inflate it dynamically, or have two layout files - one with, and one without your mini controller).

Code to check GPS version:

GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
int resultCode = apiAvailability.isGooglePlayServicesAvailable(context);
isGPSAvailable = (resultCode == ConnectionResult.SUCCESS);

If the results is not ConnectionResult.SUCCESS, don't initialise your MiniControllerFragment and do not access CastContext.

Also, please keep in mind that it is not possible to instantiate MiniControllerFragment using new MiniControllerFragment(). You have to inflate it from xml or you will get NullPointerException.

There are two ways to inflate MiniControllerFragment:

  1. Create separate xml layout files and inflate appropriate one in your Activity.onCreate:

    setContentView(isGPSAvailable ? R.layout.activity_main_with_controller : R.layout.activity_main_without_controller);
    
  2. Create ViewStub in your layout pointing to MiniControllerFragment and inflate it only when you have play services.

activity layout:

<ViewStub
android:id="@+id/cast_minicontroller"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout="@layout/cast_mini_controller_fragment"
/>

cast_mini_controller_fragment:

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/castMiniController"
          class="com.google.android.gms.cast.framework.media.widget.MiniControllerFragment"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:visibility="gone"/>

code in your activity onCreate():

ViewStub miniControllerStub = (ViewStub) findViewById(R.id.cast_minicontroller);
if (isGPSAvailable) {
    miniControllerStub.inflate();
}

I prefer the ViewStub approach as it does not duplicate your layouts.