I can't get the Cast Companion Library notification to work

1.5k Views Asked by At

I am using the Cast Companion Library and it is mostly working fine, I get the mini player, and also the lock screen controls and the activity for playing content, but I can never get the notification screen to show. I am doing the following when initializing:

mCastMgr.enableFeatures(VideoCastManager.FEATURE_NOTIFICATION |
              VideoCastManager.FEATURE_LOCKSCREEN |
              VideoCastManager.FEATURE_DEBUGGING);

and I am doing the incrementUiCounter() on resume and decrementUiCounter() on pause.

I don't see any errors, I just don't see what I am doing wrong. The only thing I am missing is that I am not passing URLs for images when telling media to play because my URLs are local assets to my app and I'm just not sure how to pass those.

2

There are 2 best solutions below

7
On

Are you using that with your own app or with CastVideos-android? If your own app, first I suggest you try the CastVideos-android app to make sure that works for you.

I suggest you print out the value of mVisibilityCounter in BaseCastManager.incrementUiCounter() and decrementUiCounter() to see if as you move in and out of different activities, it reflects the correct counter. When that counter reaches zero, then notification should show up. If the counter is reaching zero and the notification doesn't show up, I suggest you check your manifest file and see if you have the following in your Manifest:

<service
    android:name="com.google.sample.castcompanionlibrary.notification.VideoCastNotificationService"
    android:exported="false" >
    <intent-filter>
        <action android:name="com.google.sample.castcompanionlibrary.action.toggleplayback" />
        <action android:name="com.google.sample.castcompanionlibrary.action.stop" />
        <action android:name="com.google.sample.castcompanionlibrary.action.notificationvisibility" />
    </intent-filter>
</service>

(you can copy-and-paste from the CastVideos-android manifest file). You may have grabbed what it is from the documentation; there is an error there (I am planning to update a bunch of things tonight or tomorrow and the documentation will be updated as well); basically when the counter reaches zero, it calls into the notification service (see the onUiVisibilityChanged() in VideoCastManager) and if that action in manifest is not correctly set, the notification never gets our memo! Let me know if that is not the issue.

3
On

I had the same trouble. Just an FYI to those looking at this in 2016. The manifest entry is now different. I suggest to grab whatever is in the manifest of the CastVideos-android project.

<receiver android:name="com.google.android.libraries.cast.companionlibrary.remotecontrol.VideoIntentReceiver" />

<service
    android:name="com.google.android.libraries.cast.companionlibrary.notification.VideoCastNotificationService" />

<service android:name="com.google.android.libraries.cast.companionlibrary.cast.reconnection.ReconnectionService"/>