我正在使用很棒的Cling
库来扫描我的网络以查找 UPnP 设备。我的目标是组装一个小的 DLNA 库浏览器,这样我就可以学习这项技术。到目前为止,我已经能够 1. 扫描网络并连接 UPnP 设备,2. 扫描每个远程设备并确定它是否运行 DLNA 服务,以及 3. 浏览已知节点的直接子节点。简而言之,这是我能够运行所有这些的方法:
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) { };
});
}
}
}
}
我知道,它可能看起来像一个可怕的混乱,但它确实有效:) 当我进入调试器时,我可以看到我所拥有的。但是,与此处指南中的说明不同,我没有取回任何实际的媒体项目,只是浏览结果中的存储目录。这种方式是有意义的,因为 DLNA 将事物组织成这样的层次结构:
Music
All Music
Artists
Fleetwood Mac
...
Albums
...
Video
All Video
Folders
...
我的问题是,浏览这些文件夹并爬过层次结构的最简单方法是什么?我已经连接到我正在寻找的 UPnP DLNA 服务器,现在如何获取这些根存储目录?在上面给出的浏览命令中,我实际上必须传递一些索引的字符串表示来获取“音乐”或“视频”等。如何获得顶级存储目录,然后如何浏览这些目录中的每一个?我的目标是至少构建一个简单的浏览器。