org.fourthline.cling.support.model.DIDLContent Java Examples
The following examples show how to use
org.fourthline.cling.support.model.DIDLContent.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UpnpContentProcessor.java From airsonic with GNU General Public License v3.0 | 6 votes |
/** * Browses the top-level content of a type. */ public BrowseResult browseRoot(String filter, long firstResult, long maxResults, SortCriterion[] orderBy) throws Exception { DIDLContent didl = new DIDLContent(); List<T> allItems = getAllItems(); if (filter != null) { // filter items (not implemented yet) } if (orderBy != null) { // sort items (not implemented yet) } List<T> selectedItems = Util.subList(allItems, firstResult, maxResults); for (T item : selectedItems) { addItem(didl, item); } return createBrowseResult(didl, (int) didl.getCount(), allItems.size()); }
Example #2
Source File: DIDLParser.java From DroidDLNA with GNU General Public License v3.0 | 6 votes |
protected void generateRoot(DIDLContent content, Document descriptor, boolean nestedItems) { Element rootElement = descriptor.createElementNS(DIDLContent.NAMESPACE_URI, "DIDL-Lite"); descriptor.appendChild(rootElement); // rootElement.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:didl", DIDLContent.NAMESPACE_URI); rootElement.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:upnp", DIDLObject.Property.UPNP.NAMESPACE.URI); rootElement.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:dc", DIDLObject.Property.DC.NAMESPACE.URI); rootElement.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:sec", DIDLObject.Property.SEC.NAMESPACE.URI); for (Container container : content.getContainers()) { if (container == null) continue; generateContainer(container, descriptor, rootElement, nestedItems); } for (Item item : content.getItems()) { if (item == null) continue; generateItem(item, descriptor, rootElement); } for (DescMeta descMeta : content.getDescMetadata()) { if (descMeta == null) continue; generateDescMetadata(descMeta, descriptor, rootElement); } }
Example #3
Source File: DIDLParser.java From TVRemoteIME with GNU General Public License v2.0 | 6 votes |
@Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { super.startElement(uri, localName, qName, attributes); if (!DIDLContent.NAMESPACE_URI.equals(uri)) return; if (localName.equals("container")) { Container container = createContainer(attributes); getInstance().addContainer(container); createContainerHandler(container, this); } else if (localName.equals("item")) { Item item = createItem(attributes); getInstance().addItem(item); createItemHandler(item, this); } else if (localName.equals("desc")) { DescMeta desc = createDescMeta(attributes); getInstance().addDescMetadata(desc); createDescMetaHandler(desc, this); } }
Example #4
Source File: DIDLParser.java From TVRemoteIME with GNU General Public License v2.0 | 6 votes |
@Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { super.startElement(uri, localName, qName, attributes); if (!DIDLContent.NAMESPACE_URI.equals(uri)) return; if (localName.equals("res")) { Res res = createResource(attributes); if (res != null) { getInstance().addResource(res); createResHandler(res, this); } } else if (localName.equals("desc")) { DescMeta desc = createDescMeta(attributes); getInstance().addDescMetadata(desc); createDescMetaHandler(desc, this); } }
Example #5
Source File: RecentAlbumUpnpProcessor.java From airsonic with GNU General Public License v3.0 | 6 votes |
/** * Browses the top-level content. */ public BrowseResult browseRoot(String filter, long firstResult, long maxResults, SortCriterion[] orderBy) throws Exception { // AlbumUpnpProcessor overrides browseRoot() with an optimization; // this restores the default behavior for the subclass. DIDLContent didl = new DIDLContent(); List<Album> allItems = getAllItems(); if (filter != null) { // filter items (not implemented yet) } if (orderBy != null) { // sort items (not implemented yet) } List<Album> selectedItems = Util.subList(allItems, firstResult, maxResults); for (Album item : selectedItems) { addItem(didl, item); } return createBrowseResult(didl, (int) didl.getCount(), allItems.size()); }
Example #6
Source File: UpnpContentProcessor.java From airsonic-advanced with GNU General Public License v3.0 | 6 votes |
public BrowseResult searchByName(String name, long firstResult, long maxResults, SortCriterion[] orderBy) { DIDLContent didl = new DIDLContent(); Class clazz = (Class) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]; try { List<MusicFolder> allFolders = getDispatchingContentDirectory().getSettingsService().getAllMusicFolders(); ParamSearchResult<T> result = getDispatcher().getSearchService().searchByName(name, (int) firstResult, (int) maxResults, allFolders, clazz); List<T> selectedItems = result.getItems(); for (T item : selectedItems) { addItem(didl, item); } return createBrowseResult(didl, (int) didl.getCount(), result.getTotalHits()); } catch (Exception e) { return null; } }
Example #7
Source File: ContentContainerActivity.java From BeyondUPnP with Apache License 2.0 | 6 votes |
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); }
Example #8
Source File: UpnpContentProcessor.java From airsonic-advanced with GNU General Public License v3.0 | 6 votes |
/** * Browses a child of the container. */ public BrowseResult browseObject(String id, String filter, long firstResult, long maxResults, SortCriterion[] orderBy) throws Exception { T item = getItemById(id); List<U> allChildren = getChildren(item); if (filter != null) { // filter items (not implemented yet) } if (orderBy != null) { // sort items (not implemented yet) } List<U> selectedChildren = Util.subList(allChildren, firstResult, maxResults); DIDLContent didl = new DIDLContent(); for (U child : selectedChildren) { addChild(didl, child); } return createBrowseResult(didl, selectedChildren.size(), allChildren.size()); }
Example #9
Source File: DIDLParser.java From DroidDLNA with GNU General Public License v3.0 | 6 votes |
@Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { super.startElement(uri, localName, qName, attributes); if (!DIDLContent.NAMESPACE_URI.equals(uri)) return; if (localName.equals("container")) { Container container = createContainer(attributes); getInstance().addContainer(container); createContainerHandler(container, this); } else if (localName.equals("item")) { Item item = createItem(attributes); getInstance().addItem(item); createItemHandler(item, this); } else if (localName.equals("desc")) { DescMeta desc = createDescMeta(attributes); getInstance().addDescMetadata(desc); createDescMetaHandler(desc, this); } }
Example #10
Source File: UpnpContentProcessor.java From airsonic-advanced with GNU General Public License v3.0 | 6 votes |
/** * Browses the top-level content of a type. */ public BrowseResult browseRoot(String filter, long firstResult, long maxResults, SortCriterion[] orderBy) throws Exception { DIDLContent didl = new DIDLContent(); List<T> allItems = getAllItems(); if (filter != null) { // filter items (not implemented yet) } if (orderBy != null) { // sort items (not implemented yet) } List<T> selectedItems = Util.subList(allItems, firstResult, maxResults); for (T item : selectedItems) { addItem(didl, item); } return createBrowseResult(didl, (int) didl.getCount(), allItems.size()); }
Example #11
Source File: BeyondContentDirectoryService.java From BeyondUPnP with Apache License 2.0 | 6 votes |
@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); }
Example #12
Source File: GenreUpnpProcessor.java From airsonic-advanced with GNU General Public License v3.0 | 6 votes |
/** * Browses the top-level content of a type. */ public BrowseResult browseRoot(String filter, long firstResult, long maxResults, SortCriterion[] orderBy) throws Exception { // we have to override this to do an index-based id. DIDLContent didl = new DIDLContent(); List<Genre> allItems = getAllItems(); if (filter != null) { // filter items } if (orderBy != null) { // sort items } List<Genre> selectedItems = Util.subList(allItems, firstResult, maxResults); for (int i = 0; i < selectedItems.size(); i++) { Genre item = selectedItems.get(i); didl.addContainer(createContainer(item, (int) (i + firstResult))); } return createBrowseResult(didl, (int) didl.getCount(), allItems.size()); }
Example #13
Source File: DIDLParser.java From DroidDLNA with GNU General Public License v3.0 | 6 votes |
@Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { super.startElement(uri, localName, qName, attributes); if (!DIDLContent.NAMESPACE_URI.equals(uri)) return; if (localName.equals("res")) { Res res = createResource(attributes); if (res != null) { getInstance().addResource(res); createResHandler(res, this); } } else if (localName.equals("desc")) { DescMeta desc = createDescMeta(attributes); getInstance().addDescMetadata(desc); createDescMetaHandler(desc, this); } }
Example #14
Source File: UpnpContentProcessor.java From airsonic with GNU General Public License v3.0 | 6 votes |
/** * Browses a child of the container. */ public BrowseResult browseObject(String id, String filter, long firstResult, long maxResults, SortCriterion[] orderBy) throws Exception { T item = getItemById(id); List<U> allChildren = getChildren(item); if (filter != null) { // filter items (not implemented yet) } if (orderBy != null) { // sort items (not implemented yet) } List<U> selectedChildren = Util.subList(allChildren, firstResult, maxResults); DIDLContent didl = new DIDLContent(); for (U child : selectedChildren) { addChild(didl, child); } return createBrowseResult(didl, selectedChildren.size(), allChildren.size()); }
Example #15
Source File: GenreUpnpProcessor.java From airsonic with GNU General Public License v3.0 | 6 votes |
/** * Browses the top-level content of a type. */ public BrowseResult browseRoot(String filter, long firstResult, long maxResults, SortCriterion[] orderBy) throws Exception { // we have to override this to do an index-based id. DIDLContent didl = new DIDLContent(); List<Genre> allItems = getAllItems(); if (filter != null) { // filter items } if (orderBy != null) { // sort items } List<Genre> selectedItems = Util.subList(allItems, firstResult, maxResults); for (int i = 0; i < selectedItems.size(); i++) { Genre item = selectedItems.get(i); didl.addContainer(createContainer(item, (int) (i + firstResult))); } return createBrowseResult(didl, (int) didl.getCount(), allItems.size()); }
Example #16
Source File: Browse.java From DroidDLNA with GNU General Public License v3.0 | 5 votes |
public void success(ActionInvocation invocation) { log.fine("Successful browse action, reading output argument values"); BrowseResult result = new BrowseResult( invocation.getOutput("Result").getValue().toString(), (UnsignedIntegerFourBytes) invocation.getOutput("NumberReturned").getValue(), (UnsignedIntegerFourBytes) invocation.getOutput("TotalMatches").getValue(), (UnsignedIntegerFourBytes) invocation.getOutput("UpdateID").getValue() ); boolean proceed = receivedRaw(invocation, result); if (proceed && result.getCountLong() > 0 && result.getResult().length() > 0) { try { DIDLParser didlParser = new DIDLParser(); DIDLContent didl = didlParser.parse(result.getResult()); received(invocation, didl); updateStatus(Status.OK); } catch (Exception ex) { invocation.setFailure( new ActionException(ErrorCode.ACTION_FAILED, "Can't parse DIDL XML response: " + ex, ex) ); failure(invocation, null); } } else { received(invocation, new DIDLContent()); updateStatus(Status.NO_CONTENT); } }
Example #17
Source File: MediaFileUpnpProcessor.java From airsonic with GNU General Public License v3.0 | 5 votes |
public void addItem(DIDLContent didl, MediaFile item) { if (item.isFile()) { didl.addItem(createItem(item)); } else { didl.addContainer(createContainer(item)); } }
Example #18
Source File: AbstractContentDirectoryService.java From DroidDLNA with GNU General Public License v3.0 | 5 votes |
/** * Override this method to implement searching of your content. * <p> * The default implementation returns an empty result. * </p> */ public BrowseResult search(String containerId, String searchCriteria, String filter, long firstResult, long maxResults, SortCriterion[] orderBy) throws ContentDirectoryException { try { return new BrowseResult(new DIDLParser().generate(new DIDLContent()), 0, 0); } catch (Exception ex) { throw new ContentDirectoryException(ErrorCode.ACTION_FAILED, ex.toString()); } }
Example #19
Source File: ContentContainerActivity.java From BeyondUPnP with Apache License 2.0 | 5 votes |
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) { } }); } }
Example #20
Source File: DIDLParser.java From DroidDLNA with GNU General Public License v3.0 | 5 votes |
/** * Reads and unmarshalls an XML representation into a DIDL content model. * * @param xml The XML representation. * @return A DIDL content model. * @throws Exception */ public DIDLContent parse(String xml) throws Exception { if (xml == null || xml.length() == 0) { throw new RuntimeException("Null or empty XML"); } DIDLContent content = new DIDLContent(); createRootHandler(content, this); log.fine("Parsing DIDL XML content"); parse(new InputSource(new StringReader(xml))); return content; }
Example #21
Source File: DIDLParser.java From DroidDLNA with GNU General Public License v3.0 | 5 votes |
@Override protected boolean isLastElement(String uri, String localName, String qName) { if (DIDLContent.NAMESPACE_URI.equals(uri) && "container".equals(localName)) { if (getInstance().getTitle() == null) { log.warning("In DIDL content, missing 'dc:title' element for container: " + getInstance().getId()); } if (getInstance().getClazz() == null) { log.warning("In DIDL content, missing 'upnp:class' element for container: " + getInstance().getId()); } return true; } return false; }
Example #22
Source File: DIDLParser.java From DroidDLNA with GNU General Public License v3.0 | 5 votes |
@Override protected boolean isLastElement(String uri, String localName, String qName) { if (DIDLContent.NAMESPACE_URI.equals(uri) && "item".equals(localName)) { if (getInstance().getTitle() == null) { log.warning("In DIDL content, missing 'dc:title' element for item: " + getInstance().getId()); } if (getInstance().getClazz() == null) { log.warning("In DIDL content, missing 'upnp:class' element for item: " + getInstance().getId()); } return true; } return false; }
Example #23
Source File: UpnpContentProcessor.java From airsonic with GNU General Public License v3.0 | 5 votes |
/** * Browses metadata for a child. */ public BrowseResult browseObjectMetadata(String id) throws Exception { T item = getItemById(id); DIDLContent didl = new DIDLContent(); addItem(didl, item); return createBrowseResult(didl, 1, 1); }
Example #24
Source File: DIDLParser.java From TVRemoteIME with GNU General Public License v2.0 | 5 votes |
@Override protected boolean isLastElement(String uri, String localName, String qName) { if (DIDLContent.NAMESPACE_URI.equals(uri) && "DIDL-Lite".equals(localName)) { // Now transform all the generically typed Container and Item instances into // more specific Album, MusicTrack, etc. instances getInstance().replaceGenericContainerAndItems(); return true; } return false; }
Example #25
Source File: DIDLParser.java From TVRemoteIME with GNU General Public License v2.0 | 5 votes |
@Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { super.startElement(uri, localName, qName, attributes); if (!DIDLContent.NAMESPACE_URI.equals(uri)) return; if (localName.equals("item")) { Item item = createItem(attributes); getInstance().addItem(item); createItemHandler(item, this); } else if (localName.equals("desc")) { DescMeta desc = createDescMeta(attributes); getInstance().addDescMetadata(desc); createDescMetaHandler(desc, this); } else if (localName.equals("res")) { Res res = createResource(attributes); if (res != null) { getInstance().addResource(res); createResHandler(res, this); } } // We do NOT support recursive container embedded in container! The schema allows it // but the spec doesn't: // // Section 2.8.3: Incremental navigation i.e. the full hierarchy is never returned // in one call since this is likely to flood the resources available to the control // point (memory, network bandwidth, etc.). }
Example #26
Source File: DIDLParser.java From TVRemoteIME with GNU General Public License v2.0 | 5 votes |
@Override protected boolean isLastElement(String uri, String localName, String qName) { if (DIDLContent.NAMESPACE_URI.equals(uri) && "container".equals(localName)) { if (getInstance().getTitle() == null) { log.warning("In DIDL content, missing 'dc:title' element for container: " + getInstance().getId()); } if (getInstance().getClazz() == null) { log.warning("In DIDL content, missing 'upnp:class' element for container: " + getInstance().getId()); } return true; } return false; }
Example #27
Source File: UpnpControlSet.java From HPlayer with Apache License 2.0 | 5 votes |
public void setAVTransportURI(String url, int schedule, String title, String id, String creator, String parentID) { alreadyPlay = false; currentPosition = schedule; //TODO 此处有问题 究竟如何才是正确的DLNA推屏数据? DIDLParser didlParser = new DIDLParser(); DIDLContent content = new DIDLContent(); Res res = new Res(); Movie movie = new Movie(id, parentID, title, creator, res); content.addItem(movie); String didlString = ""; try { didlString = didlParser.generate(content); } catch (Exception e) { e.printStackTrace(); } ActionCallback setAVTransport = new SetAVTransportURI( avTransportService, url, didlString) { @Override public void failure(ActionInvocation arg0, UpnpResponse arg1, String arg2) { onFailureCallBack(SET_AVTRANSPORT, arg2); } @Override public void success(ActionInvocation invocation) { onVideoPlay(); // TODO 究竟如何将当前进度一起推送过去,让播放器播放时自动跳转? // TODO DLNA 是否支持这个尚不清楚 getDMRTransportInfo();// 远程渲染器播放准备完成不会主动告诉终端,需获取状态来做进度推送 onSuccessCallBack(SET_AVTRANSPORT); } }; mUpnpService.getControlPoint().execute(setAVTransport); }
Example #28
Source File: MediaFileUpnpProcessor.java From airsonic with GNU General Public License v3.0 | 5 votes |
@Override // overriding for the case of browsing a file public BrowseResult browseObjectMetadata(String id) throws Exception { MediaFile item = getItemById(id); DIDLContent didl = new DIDLContent(); addChild(didl, item); return createBrowseResult(didl, 1, 1); }
Example #29
Source File: DIDLParser.java From DroidDLNA with GNU General Public License v3.0 | 5 votes |
@Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { super.startElement(uri, localName, qName, attributes); if (!DIDLContent.NAMESPACE_URI.equals(uri)) return; if (localName.equals("item")) { Item item = createItem(attributes); getInstance().addItem(item); createItemHandler(item, this); } else if (localName.equals("desc")) { DescMeta desc = createDescMeta(attributes); getInstance().addDescMetadata(desc); createDescMetaHandler(desc, this); } else if (localName.equals("res")) { Res res = createResource(attributes); if (res != null) { getInstance().addResource(res); createResHandler(res, this); } } // We do NOT support recursive container embedded in container! The schema allows it // but the spec doesn't: // // Section 2.8.3: Incremental navigation i.e. the full hierarchy is never returned // in one call since this is likely to flood the resources available to the control // point (memory, network bandwidth, etc.). }
Example #30
Source File: GenerateXml.java From DroidDLNA with GNU General Public License v3.0 | 5 votes |
protected void generateRoot(ContentItem content, Document descriptor, boolean nestedItems) { Element rootElement = descriptor.createElementNS( DIDLContent.NAMESPACE_URI, "DIDL-Lite"); descriptor.appendChild(rootElement); // rootElement.setAttributeNS("http://www.w3.org/2000/xmlns/", // "xmlns:didl", DIDLContent.NAMESPACE_URI); rootElement.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:upnp", DIDLObject.Property.UPNP.NAMESPACE.URI); rootElement.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:dc", DIDLObject.Property.DC.NAMESPACE.URI); rootElement.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:dlna", DIDLObject.Property.DLNA.NAMESPACE.URI); rootElement.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:sec", DIDLObject.Property.SEC.NAMESPACE.URI); if (null != content.getContainer()) { generateContainer(content.getContainer(), descriptor, rootElement, nestedItems); } if (null != content.getItem()) { generateItem(content.getItem(), descriptor, rootElement); } // // for (DescMeta descMeta : content.getContainer().getDescMetadata()) { // if (descMeta == null) // continue; // generateDescMetadata(descMeta, descriptor, rootElement); // } }