Search in sources :

Example 1 with DIDLContent

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) {
            }
        });
    }
}
Also used : Message(android.os.Message) UpnpResponse(org.fourthline.cling.model.message.UpnpResponse) Device(org.fourthline.cling.model.meta.Device) ActionInvocation(org.fourthline.cling.model.action.ActionInvocation) SystemManager(com.kevinshen.beyondupnp.core.SystemManager) Service(org.fourthline.cling.model.meta.Service) DIDLContent(org.fourthline.cling.support.model.DIDLContent) Browse(org.fourthline.cling.support.contentdirectory.callback.Browse) SortCriterion(org.fourthline.cling.support.model.SortCriterion) UDN(org.fourthline.cling.model.types.UDN)

Example 2 with DIDLContent

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);
}
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 3 with DIDLContent

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);
}
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 4 with DIDLContent

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);
}
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

DIDLContent (org.fourthline.cling.support.model.DIDLContent)4 DIDLParser (org.fourthline.cling.support.contentdirectory.DIDLParser)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 Res (org.fourthline.cling.support.model.Res)2 ContentValues (android.content.ContentValues)1 Message (android.os.Message)1 SystemManager (com.kevinshen.beyondupnp.core.SystemManager)1 ActionInvocation (org.fourthline.cling.model.action.ActionInvocation)1 UpnpResponse (org.fourthline.cling.model.message.UpnpResponse)1 Device (org.fourthline.cling.model.meta.Device)1 Service (org.fourthline.cling.model.meta.Service)1 UDN (org.fourthline.cling.model.types.UDN)1 ContentDirectoryException (org.fourthline.cling.support.contentdirectory.ContentDirectoryException)1 Browse (org.fourthline.cling.support.contentdirectory.callback.Browse)1 BrowseResult (org.fourthline.cling.support.model.BrowseResult)1 DIDLObject (org.fourthline.cling.support.model.DIDLObject)1 SortCriterion (org.fourthline.cling.support.model.SortCriterion)1 Container (org.fourthline.cling.support.model.container.Container)1 Item (org.fourthline.cling.support.model.item.Item)1