use of org.fourthline.cling.support.contentdirectory.DIDLParser 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.contentdirectory.DIDLParser 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.contentdirectory.DIDLParser 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