Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chromecast + Cordova - problem with playing movie #52

Open
ghost opened this issue May 28, 2016 · 6 comments
Open

Chromecast + Cordova - problem with playing movie #52

ghost opened this issue May 28, 2016 · 6 comments

Comments

@ghost
Copy link

ghost commented May 28, 2016

Hi, I am trying to run ConnectSDK in Cordova. I can connect with my Chromecast device, but when I try to call device.getMediaPlayer().playMedia(("http://media.w3.org/2010/05/sintel/trailer.mp4", "video/mp4");, I get error:

com.connectsdk.cordova.JSCommandDispatcher$DispatcherException: Exception calling playMedia: java.lang.NullPointerException: Attempt to invoke interface method 'void com.connectsdk.service.capability.MediaPlayer.playMedia(com.connectsdk.core.MediaInfo, boolean, com.connectsdk.service.capability.MediaPlayer$LaunchListener)' on a null object reference

Do you know how to resolve this problem?

Cordova: 6.1.1
Plugins:
cordova-plugin-compat 1.0.0 "Compat"
cordova-plugin-connectsdk 1.6.0 "Connect SDK"
cordova-plugin-dialogs 1.2.1 "Notification"
cordova-plugin-file 4.2.0 "File"
cordova-plugin-file-transfer 1.5.1 "File Transfer"
cordova-plugin-whitelist 1.2.2 "Whitelist"
cordova-plugin-x-toast 2.5.1 "Toast"

@ghost
Copy link
Author

ghost commented May 28, 2016

I have already fixed it. In this case the chromecast was discovered always only as a DIAL device and the solution written by @jamescahall resolved my problem.

jamescahall commented on 22 Jan:
Ok. So the issue is that "onRouteAdded" is not getting called (except for like 1% of the time it seems). Instead "onRouteChanged" is being called. In this function, it checks to see if it's a new found service or not. There was no case to assume onRouteAdded was never called.

Just add this:

if (isNew) {
foundService = new ServiceDescription(CastService.ID, uuid,
castDevice.getIpAddress().getHostAddress());
foundService.setFriendlyName(castDevice.getFriendlyName());
foundService.setServiceID(CastService.ID);
listUpdateFlag = true;
isNew = false;
}

above the if (!isNew) in the CastDiscoveryProvider and all should be solved.

@Sprotte
Copy link

Sprotte commented Aug 16, 2016

Where do you found the CastDiscoveryProvider, he is not part of the Cordova SDK, he comes from the native SDKs? Can you explain me how to apply these fix?

@ghost
Copy link
Author

ghost commented Aug 21, 2016

@Sprotte , this file is a part of native SDK (/your_app/platforms/android/cordova-plugin-connectsdk/Connect-SDK-Android/modules/google_cast/src/com/connectsdk/discovery/provider/CastDiscoveryProvider.java)

In this file you have to find method public void onRouteChanged(MediaRouter router, RouteInfo route) and add it:

        if (isNew) {
            foundService = new ServiceDescription(CastService.ID, uuid,
            castDevice.getIpAddress().getHostAddress());
            foundService.setFriendlyName(castDevice.getFriendlyName());
            foundService.setServiceID(CastService.ID);
            listUpdateFlag = true;
            isNew = false;
        }

        if (!isNew) { // rest code without any change

Remember that when you remove the connectsdk plugin and install it one more time, you have to change this piece of code everytime.

@JRogaishio
Copy link

@jasmin89 Thank you so much for your solution. I've been pulling my hair out for the last hour wondering why the service would only work sometimes.

@jdomian
Copy link

jdomian commented Jan 25, 2017

This worked for me as well. Was having the same issue when trying to invoke .launchWebApp(). Thanks for the fix.

@phablulo
Copy link

Also worked for me. Thank you so much, @jasmin89

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants