Android : CastCompanionLibrary : mApiClient or mRemoteMediaPlayer is null

on Tuesday, September 30, 2014


I'm facing a problem trying to implement Chromecast on my application with CastCompanionLibrary.


Here is how I initialise my CastManager.



public static VideoCastManager mCastMgr;
//chromeCast init
public static VideoCastManager getVideoCastManager(Context ctx) {

if (mCastMgr == null) {
mCastMgr = VideoCastManager.initialize(ctx, ctx.getResources().getString(R.string.CAST_APPLICATION_ID), null, null);
mCastMgr.enableFeatures(VideoCastManager.FEATURE_NOTIFICATION | VideoCastManager.FEATURE_LOCKSCREEN |
VideoCastManager.FEATURE_WIFI_RECONNECT
| VideoCastManager.FEATURE_NOTIFICATION |
VideoCastManager.FEATURE_DEBUGGING);
}
mCastMgr.setContext(ctx);
return mCastMgr;
}


Here is just a test code to display one media. This method is called in the onCreate.



private MediaRouteButton mMediaRouteButton;
private VideoCastManager mVideoCastManager;
private VideoCastConsumerImpl mVideoCastConsumer;

private void setupChromeCast() {
mVideoCastManager = MyApplication.getVideoCastManager(this);
mMediaRouteButton = (MediaRouteButton) findViewById(R.id.media_route_button);
mVideoCastManager.addMediaRouterButton(mMediaRouteButton);

mMediaRouteButton.setVisibility(View.VISIBLE);

mVideoCastConsumer = new VideoCastConsumerImpl() {
// .....
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public void onCastAvailabilityChanged(boolean castPresent) {
super.onCastAvailabilityChanged(castPresent);
mMediaRouteButton.setVisibility(castPresent ? View.VISIBLE : View.INVISIBLE);
}

@Override
public void onApplicationConnected(ApplicationMetadata appMetadata,
String sessionId, boolean wasLaunched) {
Bundle mediaInfo = new Bundle();
mediaInfo.putString(MediaMetadata.KEY_TITLE, "toto");
mediaInfo.putString(MediaMetadata.KEY_SUBTITLE, "le roro");
mediaInfo.putString(MediaMetadata.KEY_STUDIO, "mdr");
mediaInfo.putString("movie-urls", "https://ia902302.us.archive.org/27/items/Pbtestfilemp4videotestmp4/video_test.mp4");
mediaInfo.putString("content-type", "video/mp4");
ArrayList<String> images = new ArrayList<String>();
images.add("https://scontent-a-cdg.xx.fbcdn.net/hphotos-xpa1/v/t1.0-9/10426650_10203984861039843_6191993092115493723_n.jpg?oh=8cb095f97c4b8f7d726d4a4d418d65fc&oe=54C484F9");
images.add("http://upload.wikimedia.org/wikipedia/commons/f/f3/Toto'025.jpg");
mediaInfo.putStringArrayList("images", images);
MediaInfo mSelectedMedia = com.google.sample.castcompanionlibrary.utils.Utils.toMediaInfo(mediaInfo);
try {
mVideoCastManager.startCastControllerActivity(getApplicationContext(), mSelectedMedia, 0, true);
finish();
return ;
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}

};
}


And then in the onResume I assign my VideoCastConsumer to my Manager.



// CHROMECAST
mVideoCastManager.addVideoCastConsumer(mVideoCastConsumer);


I have no problem with the Chromecast detection it's working great. I select my device with the app and then it displays my Application name on my screen and do nothing. The reason must be in this debug message.



[v1.9] mApiClient or mRemoteMediaPlayer is null, so will not proceed



But I have no idea what causes this problem. Any help would be appreciated, thanks.


0 comments:

Post a Comment