Search in sources :

Example 1 with DIDLParser

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);
}
Also used : ContentValues(android.content.ContentValues) Res(org.fourthline.cling.support.model.Res) DIDLParser(org.fourthline.cling.support.contentdirectory.DIDLParser) DIDLObject(org.fourthline.cling.support.model.DIDLObject) DIDLContent(org.fourthline.cling.support.model.DIDLContent) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 2 with DIDLParser

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);
}
Also used : Res(org.fourthline.cling.support.model.Res) DIDLParser(org.fourthline.cling.support.contentdirectory.DIDLParser) DIDLContent(org.fourthline.cling.support.model.DIDLContent) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 3 with DIDLParser

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);
}
Also used : Item(org.fourthline.cling.support.model.item.Item) Container(org.fourthline.cling.support.model.container.Container) DIDLParser(org.fourthline.cling.support.contentdirectory.DIDLParser) ContentDirectoryException(org.fourthline.cling.support.contentdirectory.ContentDirectoryException) DIDLContent(org.fourthline.cling.support.model.DIDLContent) BrowseResult(org.fourthline.cling.support.model.BrowseResult) ContentDirectoryException(org.fourthline.cling.support.contentdirectory.ContentDirectoryException)

Aggregations

DIDLParser (org.fourthline.cling.support.contentdirectory.DIDLParser)3 DIDLContent (org.fourthline.cling.support.model.DIDLContent)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 Res (org.fourthline.cling.support.model.Res)2 ContentValues (android.content.ContentValues)1 ContentDirectoryException (org.fourthline.cling.support.contentdirectory.ContentDirectoryException)1 BrowseResult (org.fourthline.cling.support.model.BrowseResult)1 DIDLObject (org.fourthline.cling.support.model.DIDLObject)1 Container (org.fourthline.cling.support.model.container.Container)1 Item (org.fourthline.cling.support.model.item.Item)1