I'm using the awesome Cling
library to scan my network for UPnP devices. My goal is to throw together a little DLNA library browser so I can learn the technology. I have so far been able to 1. scan the network and get connected UPnP devices, 2. scan each remote device and determine if it has a DLNA service running, and 3. browse immediate children of known nodes. In short, this is my method that is able to run all of this:
public void remoteDeviceAdded(Registry registry, RemoteDevice device) {
logger.debug("remote device added: {}[{}]", device.getDetails().getFriendlyName(),
device.getType().getType());
if (device.getType().getType().equals("MediaServer")) {
for (RemoteService service : device.getServices()) {
if (service.getServiceType().getType().equals("ContentDirectory")) {
// '1' is Music, '2' is Video, '3' is Pictures
this.service.getControlPoint().execute(new Browse(service, "3", BrowseFlag.DIRECT_CHILDREN) {
@Override public void received(ActionInvocation arg0,
DIDLContent didl) {
logger.debug("found {} items.", didl.getItems().size());
}
@Override public void updateStatus(Status arg0) { };
@Override public void failure(ActionInvocation arg0, UpnpResponse arg1, String arg2) { };
});
}
}
}
}
I know, it probably looks like a horrible mess and it is, but it works :) When I drop into a debugger, I can see what I've got. However, unlike the instructions from the guide here, I don't get back any actual media items, just storage directories in the browse result. This kind of makes sense as DLNA organizes things into a hierarchy like so:
Music
All Music
Artists
Fleetwood Mac
...
Albums
...
Video
All Video
Folders
...
My question is this, what's the easiest way to browse these folders and climb through the hierarchy? I'm already at a point where I'm connected to the UPnP DLNA server that I was looking for, now how do I get these root storage directories? In the browse command given above, I have to actually pass a string representation of some index to get "Music" or "Video" or the like. How do I get the top level of storage directories, then how can I browse each one of those directories? My goal is to at least build a simple browser.