Saturday 3 December 2016

discovery - Chromecast device is not discovered on some Android devices

Recently we added support for Chromecast in our Android application but during an extended testing on various mobile devices (phones and tablets) it turned out that on many, Chromecast is not discovered by Flipps app. More than that on the same devices we tested with latest build of the official Chromecast SDK demo app, downloaded from https://github.com/googlecast/CastVideos-android (master branch, update on Jun 30th and similar results observed - Chromecast device not discovered.



In short our implementation is the following - we extend VideoCastConsumerImpl listener and add it to VideoCastManager object initialized in AmsApplication (AmsApplication is app Application class):



this.controller = AmsApplication.getApplication().getSharingService().getDeviceController();
try {
mCastManager = AmsApplication.getCastManager(context);
mCastConsumer = new VideoCastConsumerImpl() {


@Override
public void onFailed(int resourceId, int statusCode) {

}

@Override
public void onConnectionSuspended(int cause) {

}


@Override
public void onConnectivityRecovered() {

}

@Override
public void onCastDeviceDetected(final RouteInfo info) {
CastDevice dev = new CastDevice(info, mCastManager);
controller.onDeviceAdded(dev);

}
};
mCastManager.addVideoCastConsumer(mCastConsumer);
isActive = true;
} catch (Exception ex) {
Log.e(TAG, "Error initializing cast manager", ex);
}


Unfortunately none of the callbacks is called even though а Chromecast device is available and registered in the same WiFi network. Similar is the implementation and behaviour of the demo app.




Due to that we implemented our own device discovery mechanism based on mDNS protocol (using JmDNS library, version 3.4.1). As a result Chromecast device is discovered and an object of type CastDevice is constructed by using reflection to call private class constructor. The CastDevice object is set as device to already initialised VideoCastManager object (method: public void setDevice(CastDevice device, boolean stopAppOnExit) ) which subsequently calls connect() method of GoogleApiClient class. In around 15 seconds later a network error is returned.



All the error states from above are consistently reproduced on all tested devices. Here is the list of the devices (including OS and Google Play Services versions) we were able to reproduce the issue:





HTC One X | 4.2.2 | 5.0.84 (1259630-036)



Samsung Galaxy S4 (GT-I9505) | 4.4.2 | 5.0.84 (1259630-038)




Samsung Galaxy S4 mini (GT-I9195) | 4.2.2 | 3.2.25 (761454-30)



Samsung Galaxy TAB3 (GT-P5200) | 4.2.2 | 5.0.84 (1259630-070)



Motorola XOOM (MZ601) | 3.2 | 5.0.84 (1259630-032)



Sony Tablet S | 4.0.3 | 4.3.25 (1117461-032)



Nexus 5 | 4.4.4 | 5.0.89




On the other side Chromecast is successfully discovered and works without any issues on the following list of devices:





HTC One | 4.4.2 | 5.0.88 (1297476-038)



Samsung Galaxy S3 (GT-I9300) | 4.3 | 5.0.84 (1259630-036)



HTC One S | 4.0.4 | 5.0.84 (1259630-036)




Samsung Galaxy 7 TAB2 (GT-P3100) | 4.1.2 | 5.0.84 (1259630-032)



Samsung Galaxy S2 (GT-9105P) | 4.2.2 | 5.0.84 (1259630-034)



Samsung Galaxy Nexus | 4.2.1 | 5.0.84 (1259630-036)



Sony Xperia Z | 4.2.2 | 5.0.84 (1259630-038)



Nexus 7 (ME370T) | 4.3 | 5.0.84 (1259630-030)

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...