ConnectSDK / Connect-SDK-Cordova-Plugin

Cordova/PhoneGap plugin for Connect SDK
Apache License 2.0
69 stars 46 forks source link

Chromecast + Cordova - problem with playing movie #52

Open ghost opened 8 years ago

ghost commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

@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 commented 8 years ago

@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 commented 7 years ago

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

phablulo commented 7 years ago

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