use of org.fourthline.cling.support.model.DIDLContent in project BeyondUPnP by kevinshine.
the class ContentContainerActivity method loadContent.
private void loadContent() {
SystemManager systemManager = SystemManager.getInstance();
Device device = null;
try {
device = systemManager.getRegistry().getDevice(new UDN(mIdentifierString), false);
} catch (NullPointerException e) {
Log.e(TAG, "Get device error.");
}
if (device != null) {
//Get cds to browse children directories.
Service contentDeviceService = device.findService(SystemManager.CONTENT_DIRECTORY_SERVICE);
//Execute Browse action and init list view
systemManager.getControlPoint().execute(new Browse(contentDeviceService, mObjectId, BrowseFlag.DIRECT_CHILDREN, "*", 0, null, new SortCriterion(true, "dc:title")) {
@Override
public void received(ActionInvocation actionInvocation, DIDLContent didl) {
Message msg = Message.obtain(handler, ADD_OBJECTS, didl);
msg.sendToTarget();
}
@Override
public void updateStatus(Status status) {
}
@Override
public void failure(ActionInvocation invocation, UpnpResponse operation, String defaultMsg) {
}
});
}
}
use of org.fourthline.cling.support.model.DIDLContent in project BeyondUPnP by kevinshine.
the class ContentContainerActivity method addToPlaylist.
private void addToPlaylist(Item item) {
if (item == null)
return;
Res res = item.getFirstResource();
String uri = res.getValue();
//Parse content.
DIDLContent content = new DIDLContent();
content.addItem(item);
DIDLParser didlParser = new DIDLParser();
String metadata = null;
try {
//Generate track metadata.
metadata = didlParser.generate(content);
} catch (Exception e) {
//ignore
}
String albumUri = null;
try {
for (DIDLObject.Property property : item.getProperties()) {
if (property instanceof DIDLObject.Property.UPNP.ALBUM_ART_URI) {
albumUri = ((DIDLObject.Property.UPNP.ALBUM_ART_URI) property).getValue().toString();
}
}
} catch (Exception e) {
//ignore
}
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(item.getCreator());
stringBuilder.append(item.getTitle());
stringBuilder.append(res.getSize());
//Create md5 code
String md5 = null;
try {
md5 = MD5.createMD5(stringBuilder.toString());
} catch (NoSuchAlgorithmException e) {
md5 = null;
}
ContentValues values = new ContentValues();
values.put(PlaylistItem.ITEM_TITLE, item.getTitle());
values.put(PlaylistItem.ITEM_URI, uri);
values.put(PlaylistItem.ITEM_THUMB, albumUri);
values.put(PlaylistItem.ITEM_METADATA, metadata);
values.put(PlaylistItem.ITEM_DATE, System.currentTimeMillis());
values.put(PlaylistItem.ITEM_VERIFICATION_CODE, md5);
getContentResolver().insert(PlaylistItem.CONTENT_URI, values);
}
use of org.fourthline.cling.support.model.DIDLContent in project BeyondUPnP by kevinshine.
the class ContentContainerActivity method playItem.
private void playItem(Item item) {
if (item == null)
return;
Res res = item.getFirstResource();
String uri = res.getValue();
DIDLContent content = new DIDLContent();
content.addItem(item);
DIDLParser didlParser = new DIDLParser();
String metadata = null;
try {
metadata = didlParser.generate(content);
} catch (Exception e) {
//ignore
}
//Log.d(TAG,"Item metadata:" + metadata);
//Play on the selected device.
PlaybackCommand.playNewItem(uri, metadata);
}
use of org.fourthline.cling.support.model.DIDLContent in project BeyondUPnP by kevinshine.
the class BeyondContentDirectoryService method browse.
@Override
public BrowseResult browse(String objectID, BrowseFlag browseFlag, String filter, long firstResult, long maxResults, SortCriterion[] orderby) throws ContentDirectoryException {
String address = Utils.getIPAddress(true);
String serverUrl = "http://" + address + ":" + JettyResourceServer.JETTY_SERVER_PORT;
//Create container by id
Container resultBean = ContainerFactory.createContainer(objectID, serverUrl);
DIDLContent content = new DIDLContent();
for (Container c : resultBean.getContainers()) content.addContainer(c);
for (Item item : resultBean.getItems()) content.addItem(item);
int count = resultBean.getChildCount();
String contentModel = "";
try {
contentModel = new DIDLParser().generate(content);
} catch (Exception e) {
throw new ContentDirectoryException(ContentDirectoryErrorCode.CANNOT_PROCESS, e.toString());
}
return new BrowseResult(contentModel, count, count);
}
Aggregations