Carlos López
Carlos López

Reputation: 759

Invoke chromecast media router outside an activity

I'm exposing Chromecast sdk to a library that can be consumed in react native.

So, when I run

VideoCastManager.initialize(mCurrentActivity, options);
mCastManager = VideoCastManager.getInstance();
mCastManager.startCastDiscovery();

Inside the main activity, it works great. But if I do it from a class, It crashed with

java.lang.IllegalStateException: The media router service must only be accessed on the application's main thread.

But I need a way to invoke the startDiscovery method outside the activity, as it will be called from another action, and it will be broadcasting if it found a chromecast or not.

Is there a way to do it?

Upvotes: 2

Views: 392

Answers (1)

Ali Naddaf
Ali Naddaf

Reputation: 19084

The exception is talking about main vs worker thread; are you calling that on a worker thread? If so, you should make some changes to call that on the main thread of your application.

Upvotes: 1

Related Questions