org.fourthline.cling.support.model.DIDLObject Java Examples
The following examples show how to use
org.fourthline.cling.support.model.DIDLObject.
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 Project: airsonic-advanced Author: airsonic-advanced File: MediaFileUpnpProcessor.java License: GNU General Public License v3.0 | 6 votes |
public Item createItem(MediaFile song) { MediaFile parent = getMediaFileService().getParentOf(song); MusicTrack item = new MusicTrack(); item.setId(String.valueOf(song.getId())); item.setParentID(String.valueOf(parent.getId())); item.setTitle(song.getTitle()); item.setAlbum(song.getAlbumName()); if (song.getArtist() != null) { item.setArtists(getDispatcher().getAlbumProcessor().getAlbumArtists(song.getArtist())); } Integer year = song.getYear(); if (year != null) { item.setDate(year + "-01-01"); } item.setOriginalTrackNumber(song.getTrackNumber()); if (song.getGenre() != null) { item.setGenres(new String[]{song.getGenre()}); } item.setResources(Arrays.asList(getDispatcher().createResourceForSong(song))); item.setDescription(song.getComment()); item.addProperty(new DIDLObject.Property.UPNP.ALBUM_ART_URI(getDispatcher().getAlbumProcessor().getAlbumArtURI(parent.getId()))); return item; }
Example #2
Source Project: TVRemoteIME Author: kingthy File: DIDLParser.java License: GNU General Public License v2.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 Project: TVRemoteIME Author: kingthy File: DIDLParser.java License: GNU General Public License v2.0 | 6 votes |
@Override public void endElement(String uri, String localName, String qName) throws SAXException { super.endElement(uri, localName, qName); if (DIDLObject.Property.UPNP.NAMESPACE.URI.equals(uri)) { if ("searchClass".equals(localName)) { getInstance().getSearchClasses().add( new DIDLObject.Class( getCharacters(), getAttributes().getValue("name"), "true".equals(getAttributes().getValue("includeDerived")) ) ); } else if ("createClass".equals(localName)) { getInstance().getCreateClasses().add( new DIDLObject.Class( getCharacters(), getAttributes().getValue("name"), "true".equals(getAttributes().getValue("includeDerived")) ) ); } } }
Example #4
Source Project: airsonic Author: airsonic File: MediaFileUpnpProcessor.java License: GNU General Public License v3.0 | 6 votes |
public Item createItem(MediaFile song) { MediaFile parent = getMediaFileService().getParentOf(song); MusicTrack item = new MusicTrack(); item.setId(String.valueOf(song.getId())); item.setParentID(String.valueOf(parent.getId())); item.setTitle(song.getTitle()); item.setAlbum(song.getAlbumName()); if (song.getArtist() != null) { item.setArtists(getDispatcher().getAlbumProcessor().getAlbumArtists(song.getArtist())); } Integer year = song.getYear(); if (year != null) { item.setDate(year + "-01-01"); } item.setOriginalTrackNumber(song.getTrackNumber()); if (song.getGenre() != null) { item.setGenres(new String[]{song.getGenre()}); } item.setResources(Arrays.asList(getDispatcher().createResourceForSong(song))); item.setDescription(song.getComment()); item.addProperty(new DIDLObject.Property.UPNP.ALBUM_ART_URI(getDispatcher().getAlbumProcessor().getAlbumArtURI(parent.getId()))); return item; }
Example #5
Source Project: subsonic Author: sindremehus File: FolderBasedContentDirectory.java License: GNU General Public License v3.0 | 6 votes |
private Item createItem(MediaFile song) throws Exception { MediaFile parent = mediaFileService.getParentOf(song); MusicTrack item = new MusicTrack(); item.setId(String.valueOf(song.getId())); item.setParentID(String.valueOf(parent.getId())); item.setTitle(song.getTitle()); item.setAlbum(song.getAlbumName()); if (song.getArtist() != null) { item.setArtists(new PersonWithRole[]{new PersonWithRole(song.getArtist())}); } Integer year = song.getYear(); if (year != null) { item.setDate(year + "-01-01"); } item.setOriginalTrackNumber(song.getTrackNumber()); if (song.getGenre() != null) { item.setGenres(new String[]{song.getGenre()}); } item.setResources(Arrays.asList(createResourceForSong(song))); item.setDescription(song.getComment()); item.addProperty(new DIDLObject.Property.UPNP.ALBUM_ART_URI(getAlbumArtUrl(parent))); return item; }
Example #6
Source Project: DroidDLNA Author: offbye File: DIDLParser.java License: 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 #7
Source Project: DroidDLNA Author: offbye File: DIDLParser.java License: GNU General Public License v3.0 | 6 votes |
@Override public void endElement(String uri, String localName, String qName) throws SAXException { super.endElement(uri, localName, qName); if (DIDLObject.Property.UPNP.NAMESPACE.URI.equals(uri)) { if ("searchClass".equals(localName)) { getInstance().getSearchClasses().add( new DIDLObject.Class( getCharacters(), getAttributes().getValue("name"), "true".equals(getAttributes().getValue("includeDerived")) ) ); } else if ("createClass".equals(localName)) { getInstance().getCreateClasses().add( new DIDLObject.Class( getCharacters(), getAttributes().getValue("name"), "true".equals(getAttributes().getValue("includeDerived")) ) ); } } }
Example #8
Source Project: DroidDLNA Author: offbye File: ContentActivity.java License: GNU General Public License v3.0 | 6 votes |
private String getThumbUri(ContentItem contentItem) { String thumbUri = null; int i = contentItem.getItem().getProperties().size(); for (int j = 0; j < i; j++) { if (null != contentItem.getItem() && null != contentItem.getItem().getProperties() && null != contentItem.getItem().getProperties().get(j) && ((DIDLObject.Property) contentItem.getItem() .getProperties().get(j)).getDescriptorName() .equals("albumArtURI")) { thumbUri = ((DIDLObject.Property) contentItem.getItem() .getProperties().get(j)).getValue().toString(); break; } } return thumbUri; }
Example #9
Source Project: TVRemoteIME Author: kingthy File: DIDLParser.java License: GNU General Public License v2.0 | 5 votes |
protected void appendProperties(Document descriptor, Element parent, DIDLObject object, String prefix, Class<? extends DIDLObject.Property.NAMESPACE> namespace, String namespaceURI) { for (DIDLObject.Property<Object> property : object.getPropertiesByNamespace(namespace)) { Element el = descriptor.createElementNS(namespaceURI, prefix + ":" + property.getDescriptorName()); parent.appendChild(el); property.setOnElement(el); } }
Example #10
Source Project: TVRemoteIME Author: kingthy File: DIDLParser.java License: GNU General Public License v2.0 | 5 votes |
protected void appendClass(Document descriptor, Element parent, DIDLObject.Class clazz, String element, boolean appendDerivation) { Element classElement = appendNewElementIfNotNull( descriptor, parent, element, clazz.getValue(), DIDLObject.Property.UPNP.NAMESPACE.URI ); if (clazz.getFriendlyName() != null && clazz.getFriendlyName().length() > 0) classElement.setAttribute("name", clazz.getFriendlyName()); if (appendDerivation) classElement.setAttribute("includeDerived", Boolean.toString(clazz.isIncludeDerived())); }
Example #11
Source Project: DroidDLNA Author: offbye File: DIDLParser.java License: GNU General Public License v3.0 | 5 votes |
protected void appendProperties(Document descriptor, Element parent, DIDLObject object, String prefix, Class<? extends DIDLObject.Property.NAMESPACE> namespace, String namespaceURI) { for (DIDLObject.Property<Object> property : object.getPropertiesByNamespace(namespace)) { Element el = descriptor.createElementNS(namespaceURI, prefix + ":" + property.getDescriptorName()); parent.appendChild(el); property.setOnElement(el); } }
Example #12
Source Project: DroidDLNA Author: offbye File: DIDLParser.java License: GNU General Public License v3.0 | 5 votes |
protected void appendClass(Document descriptor, Element parent, DIDLObject.Class clazz, String element, boolean appendDerivation) { Element classElement = appendNewElementIfNotNull( descriptor, parent, element, clazz.getValue(), DIDLObject.Property.UPNP.NAMESPACE.URI ); if (clazz.getFriendlyName() != null && clazz.getFriendlyName().length() > 0) classElement.setAttribute("name", clazz.getFriendlyName()); if (appendDerivation) classElement.setAttribute("includeDerived", Boolean.toString(clazz.isIncludeDerived())); }
Example #13
Source Project: DroidDLNA Author: offbye File: GenerateXml.java License: 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); // } }
Example #14
Source Project: DroidDLNA Author: offbye File: GenerateXml.java License: GNU General Public License v3.0 | 5 votes |
protected void appendClass(Document descriptor, Element parent, DIDLObject.Class clazz, String element, boolean appendDerivation) { Element classElement = appendNewElementIfNotNull(descriptor, parent, element, clazz.getValue(), DIDLObject.Property.UPNP.NAMESPACE.URI); if (clazz.getFriendlyName() != null && clazz.getFriendlyName().length() > 0) classElement.setAttribute("name", clazz.getFriendlyName()); if (appendDerivation) classElement.setAttribute("includeDerived", Boolean.toString(clazz.isIncludeDerived())); }
Example #15
Source Project: DroidDLNA Author: offbye File: GenerateXml.java License: GNU General Public License v3.0 | 5 votes |
protected void appendProperties(Document descriptor, Element parent, DIDLObject object, String prefix, Class<? extends DIDLObject.Property.NAMESPACE> namespace, String namespaceURI) { for (DIDLObject.Property<Object> property : object .getPropertiesByNamespace(namespace)) { Element el = descriptor.createElementNS(namespaceURI, prefix + ":" + property.getDescriptorName()); parent.appendChild(el); property.setOnElement(el); } }
Example #16
Source Project: TVRemoteIME Author: kingthy File: Item.java License: GNU General Public License v2.0 | 4 votes |
public Item(String id, Container parent, String title, String creator, DIDLObject.Class clazz) { this(id, parent.getId(), title, creator, false, null, clazz, new ArrayList(), new ArrayList(), new ArrayList()); }
Example #17
Source Project: TVRemoteIME Author: kingthy File: Item.java License: GNU General Public License v2.0 | 4 votes |
public Item(String id, Container parent, String title, String creator, DIDLObject.Class clazz, String refID) { this(id, parent.getId(), title, creator, false, null, clazz, new ArrayList(), new ArrayList(), new ArrayList(), refID); }
Example #18
Source Project: TVRemoteIME Author: kingthy File: Item.java License: GNU General Public License v2.0 | 4 votes |
public Item(String id, String parentID, String title, String creator, DIDLObject.Class clazz) { this(id, parentID, title, creator, false, null, clazz, new ArrayList(), new ArrayList(), new ArrayList()); }
Example #19
Source Project: TVRemoteIME Author: kingthy File: Item.java License: GNU General Public License v2.0 | 4 votes |
public Item(String id, String parentID, String title, String creator, DIDLObject.Class clazz, String refID) { this(id, parentID, title, creator, false, null, clazz, new ArrayList(), new ArrayList(), new ArrayList(), refID); }
Example #20
Source Project: TVRemoteIME Author: kingthy File: Container.java License: GNU General Public License v2.0 | 4 votes |
public Container(String id, Container parent, String title, String creator, DIDLObject.Class clazz, Integer childCount) { this(id, parent.getId(), title, creator, true, null, clazz, new ArrayList(), new ArrayList(), new ArrayList(), childCount, false, new ArrayList(), new ArrayList(), new ArrayList()); }
Example #21
Source Project: TVRemoteIME Author: kingthy File: Container.java License: GNU General Public License v2.0 | 4 votes |
public Container(String id, String parentID, String title, String creator, DIDLObject.Class clazz, Integer childCount) { this(id, parentID, title, creator, true, null, clazz, new ArrayList(), new ArrayList(), new ArrayList(), childCount, false, new ArrayList(), new ArrayList(), new ArrayList()); }
Example #22
Source Project: TVRemoteIME Author: kingthy File: Container.java License: GNU General Public License v2.0 | 4 votes |
public Container(String id, Container parent, String title, String creator, DIDLObject.Class clazz, Integer childCount, boolean searchable, List<Class> createClasses, List<Class> searchClasses, List<Item> items) { this(id, parent.getId(), title, creator, true, null, clazz, new ArrayList(), new ArrayList(), new ArrayList(), childCount, searchable, createClasses, searchClasses, items); }
Example #23
Source Project: TVRemoteIME Author: kingthy File: Container.java License: GNU General Public License v2.0 | 4 votes |
public Container(String id, String parentID, String title, String creator, DIDLObject.Class clazz, Integer childCount, boolean searchable, List<Class> createClasses, List<Class> searchClasses, List<Item> items) { this(id, parentID, title, creator, true, null, clazz, new ArrayList(), new ArrayList(), new ArrayList(), childCount, searchable, createClasses, searchClasses, items); }
Example #24
Source Project: TVRemoteIME Author: kingthy File: DIDLParser.java License: GNU General Public License v2.0 | 4 votes |
protected void generateContainer(Container container, Document descriptor, Element parent, boolean nestedItems) { if (container.getClazz() == null) { throw new RuntimeException("Missing 'upnp:class' element for container: " + container.getId()); } Element containerElement = appendNewElement(descriptor, parent, "container"); if (container.getId() == null) throw new NullPointerException("Missing id on container: " + container); containerElement.setAttribute("id", container.getId()); if (container.getParentID() == null) throw new NullPointerException("Missing parent id on container: " + container); containerElement.setAttribute("parentID", container.getParentID()); if (container.getChildCount() != null) { containerElement.setAttribute("childCount", Integer.toString(container.getChildCount())); } containerElement.setAttribute("restricted", booleanToInt(container.isRestricted())); containerElement.setAttribute("searchable", booleanToInt(container.isSearchable())); String title = container.getTitle(); if (title == null) { log.warning("Missing 'dc:title' element for container: " + container.getId()); title = UNKNOWN_TITLE; } appendNewElementIfNotNull( descriptor, containerElement, "dc:title", title, DIDLObject.Property.DC.NAMESPACE.URI ); appendNewElementIfNotNull( descriptor, containerElement, "dc:creator", container.getCreator(), DIDLObject.Property.DC.NAMESPACE.URI ); appendNewElementIfNotNull( descriptor, containerElement, "upnp:writeStatus", container.getWriteStatus(), DIDLObject.Property.UPNP.NAMESPACE.URI ); appendClass(descriptor, containerElement, container.getClazz(), "upnp:class", false); for (DIDLObject.Class searchClass : container.getSearchClasses()) { appendClass(descriptor, containerElement, searchClass, "upnp:searchClass", true); } for (DIDLObject.Class createClass : container.getCreateClasses()) { appendClass(descriptor, containerElement, createClass, "upnp:createClass", true); } appendProperties(descriptor, containerElement, container, "upnp", DIDLObject.Property.UPNP.NAMESPACE.class, DIDLObject.Property.UPNP.NAMESPACE.URI); appendProperties(descriptor, containerElement, container, "dc", DIDLObject.Property.DC.NAMESPACE.class, DIDLObject.Property.DC.NAMESPACE.URI); if (nestedItems) { for (Item item : container.getItems()) { if (item == null) continue; generateItem(item, descriptor, containerElement); } } for (Res resource : container.getResources()) { if (resource == null) continue; generateResource(resource, descriptor, containerElement); } for (DescMeta descMeta : container.getDescMetadata()) { if (descMeta == null) continue; generateDescMetadata(descMeta, descriptor, containerElement); } }
Example #25
Source Project: TVRemoteIME Author: kingthy File: DIDLParser.java License: GNU General Public License v2.0 | 4 votes |
protected void generateItem(Item item, Document descriptor, Element parent) { if (item.getClazz() == null) { throw new RuntimeException("Missing 'upnp:class' element for item: " + item.getId()); } Element itemElement = appendNewElement(descriptor, parent, "item"); if (item.getId() == null) throw new NullPointerException("Missing id on item: " + item); itemElement.setAttribute("id", item.getId()); if (item.getParentID() == null) throw new NullPointerException("Missing parent id on item: " + item); itemElement.setAttribute("parentID", item.getParentID()); if (item.getRefID() != null) itemElement.setAttribute("refID", item.getRefID()); itemElement.setAttribute("restricted", booleanToInt(item.isRestricted())); String title = item.getTitle(); if (title == null) { log.warning("Missing 'dc:title' element for item: " + item.getId()); title = UNKNOWN_TITLE; } appendNewElementIfNotNull( descriptor, itemElement, "dc:title", title, DIDLObject.Property.DC.NAMESPACE.URI ); appendNewElementIfNotNull( descriptor, itemElement, "dc:creator", item.getCreator(), DIDLObject.Property.DC.NAMESPACE.URI ); appendNewElementIfNotNull( descriptor, itemElement, "upnp:writeStatus", item.getWriteStatus(), DIDLObject.Property.UPNP.NAMESPACE.URI ); appendClass(descriptor, itemElement, item.getClazz(), "upnp:class", false); appendProperties(descriptor, itemElement, item, "upnp", DIDLObject.Property.UPNP.NAMESPACE.class, DIDLObject.Property.UPNP.NAMESPACE.URI); appendProperties(descriptor, itemElement, item, "dc", DIDLObject.Property.DC.NAMESPACE.class, DIDLObject.Property.DC.NAMESPACE.URI); appendProperties(descriptor, itemElement, item, "sec", DIDLObject.Property.SEC.NAMESPACE.class, DIDLObject.Property.SEC.NAMESPACE.URI); for (Res resource : item.getResources()) { if (resource == null) continue; generateResource(resource, descriptor, itemElement); } for (DescMeta descMeta : item.getDescMetadata()) { if (descMeta == null) continue; generateDescMetadata(descMeta, descriptor, itemElement); } }
Example #26
Source Project: HPlayer Author: hezhubo File: GenerateContentTask.java License: Apache License 2.0 | 4 votes |
/** * 添加视频 */ private void addVideoContent(Context context, ContentNode rootNode) { Container videoContainer = new Container(); videoContainer.setClazz(new DIDLObject.Class("object.container")); videoContainer.setId(ContentTree.VIDEO_ID); videoContainer.setParentID(ContentTree.ROOT_ID); videoContainer.setTitle("Videos"); videoContainer.setRestricted(true); videoContainer.setWriteStatus(WriteStatus.NOT_WRITABLE); videoContainer.setChildCount(0); rootNode.getContainer().addContainer(videoContainer); rootNode.getContainer().setChildCount( rootNode.getContainer().getChildCount() + 1); ContentTree.addNode(ContentTree.VIDEO_ID, new ContentNode( ContentTree.VIDEO_ID, videoContainer)); Cursor cursor = context.getContentResolver() .query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, null, null, null, null); if (cursor == null) { return; } while (cursor.moveToNext()) { String id = ContentTree.VIDEO_PREFIX + cursor.getInt(cursor.getColumnIndex(MediaStore.Video.Media._ID)); String title = cursor.getString(cursor .getColumnIndexOrThrow(MediaStore.Video.Media.TITLE)); String creator = cursor.getString(cursor .getColumnIndexOrThrow(MediaStore.Video.Media.ARTIST)); String filePath = cursor.getString(cursor .getColumnIndexOrThrow(MediaStore.Video.Media.DATA)); String mimeType = cursor.getString(cursor .getColumnIndexOrThrow(MediaStore.Video.Media.MIME_TYPE)); long size = cursor.getLong(cursor .getColumnIndexOrThrow(MediaStore.Video.Media.SIZE)); long duration = cursor.getLong(cursor .getColumnIndexOrThrow(MediaStore.Video.Media.DURATION)); String resolution = cursor.getString(cursor .getColumnIndexOrThrow(MediaStore.Video.Media.RESOLUTION)); Res res = new Res(new MimeType(mimeType.substring(0, mimeType.indexOf('/')), mimeType.substring(mimeType.indexOf('/') + 1)), size, "http://" + address + "/" + id); res.setDuration(duration / (1000 * 60 * 60) + ":" + (duration % (1000 * 60 * 60)) / (1000 * 60) + ":" + (duration % (1000 * 60)) / 1000); res.setResolution(resolution); VideoItem videoItem = new VideoItem(id, ContentTree.VIDEO_ID, title, creator, res); videoContainer.addItem(videoItem); videoContainer.setChildCount(videoContainer.getChildCount() + 1); ContentTree.addNode(id, new ContentNode(id, videoItem, filePath)); // Log.d(TAG, "added video item " + title + "from " + filePath); } cursor.close(); }
Example #27
Source Project: HPlayer Author: hezhubo File: GenerateContentTask.java License: Apache License 2.0 | 4 votes |
/** * 添加音频 */ private void addAudioContent(Context context, ContentNode rootNode) { Container audioContainer = new Container(ContentTree.AUDIO_ID, ContentTree.ROOT_ID, "Audios", "HPlayer MediaServer", new DIDLObject.Class("object.container"), 0); audioContainer.setRestricted(true); audioContainer.setWriteStatus(WriteStatus.NOT_WRITABLE); rootNode.getContainer().addContainer(audioContainer); rootNode.getContainer().setChildCount( rootNode.getContainer().getChildCount() + 1); ContentTree.addNode(ContentTree.AUDIO_ID, new ContentNode( ContentTree.AUDIO_ID, audioContainer)); Cursor cursor = context.getContentResolver() .query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, null, null, null); if (cursor == null) { return; } while (cursor.moveToNext()) { String id = ContentTree.AUDIO_PREFIX + cursor.getInt(cursor.getColumnIndex(MediaStore.Audio.Media._ID)); String title = cursor.getString(cursor .getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE)); String creator = cursor.getString(cursor .getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST)); String filePath = cursor.getString(cursor .getColumnIndexOrThrow(MediaStore.Audio.Media.DATA)); String mimeType = cursor.getString(cursor .getColumnIndexOrThrow(MediaStore.Audio.Media.MIME_TYPE)); long size = cursor.getLong(cursor .getColumnIndexOrThrow(MediaStore.Audio.Media.SIZE)); long duration = cursor.getLong(cursor .getColumnIndexOrThrow(MediaStore.Audio.Media.DURATION)); String album = cursor.getString(cursor .getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM)); Res res = new Res(new MimeType(mimeType.substring(0, mimeType.indexOf('/')), mimeType.substring(mimeType.indexOf('/') + 1)), size, "http://" + address + "/" + id); res.setDuration(duration / (1000 * 60 * 60) + ":" + (duration % (1000 * 60 * 60)) / (1000 * 60) + ":" + (duration % (1000 * 60)) / 1000); // Music Track must have `artist' with role field, or // DIDLParser().generate(didl) will throw nullpointException MusicTrack musicTrack = new MusicTrack(id, ContentTree.AUDIO_ID, title, creator, album, new PersonWithRole(creator, "Performer"), res); audioContainer.addItem(musicTrack); audioContainer.setChildCount(audioContainer.getChildCount() + 1); ContentTree.addNode(id, new ContentNode(id, musicTrack, filePath)); // Log.d(TAG, "added audio item " + title + "from " + filePath); } cursor.close(); }
Example #28
Source Project: HPlayer Author: hezhubo File: GenerateContentTask.java License: Apache License 2.0 | 4 votes |
/** * 添加图片 */ private void addImageContent(Context context, ContentNode rootNode) { Container imageContainer = new Container(ContentTree.IMAGE_ID, ContentTree.ROOT_ID, "Images", "HPlayer MediaServer", new DIDLObject.Class("object.container"), 0); imageContainer.setRestricted(true); imageContainer.setWriteStatus(WriteStatus.NOT_WRITABLE); rootNode.getContainer().addContainer(imageContainer); rootNode.getContainer().setChildCount( rootNode.getContainer().getChildCount() + 1); ContentTree.addNode(ContentTree.IMAGE_ID, new ContentNode( ContentTree.IMAGE_ID, imageContainer)); Cursor cursor = context.getContentResolver() .query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, null, null, null, null); if (cursor == null) { return; } while (cursor.moveToNext()) { String id = ContentTree.IMAGE_PREFIX + cursor.getInt(cursor.getColumnIndex(MediaStore.Images.Media._ID)); String title = cursor.getString(cursor .getColumnIndexOrThrow(MediaStore.Images.Media.TITLE)); String creator = "unkown"; String filePath = cursor.getString(cursor .getColumnIndexOrThrow(MediaStore.Images.Media.DATA)); String mimeType = cursor.getString(cursor .getColumnIndexOrThrow(MediaStore.Images.Media.MIME_TYPE)); long size = cursor.getLong(cursor .getColumnIndexOrThrow(MediaStore.Images.Media.SIZE)); Res res = new Res(new MimeType(mimeType.substring(0, mimeType.indexOf('/')), mimeType.substring(mimeType.indexOf('/') + 1)), size, "http://" + address + "/" + id); ImageItem imageItem = new ImageItem(id, ContentTree.IMAGE_ID, title, creator, res); imageContainer.addItem(imageItem); imageContainer.setChildCount(imageContainer.getChildCount() + 1); ContentTree.addNode(id, new ContentNode(id, imageItem, filePath)); // Log.d(TAG, "added image item " + title + "from " + filePath); } cursor.close(); }
Example #29
Source Project: HPlayer Author: hezhubo File: ContentItem.java License: Apache License 2.0 | 4 votes |
public DIDLObject getDidlObject() { return didlObject; }
Example #30
Source Project: BeyondUPnP Author: kevinshine File: ContentContainerActivity.java License: Apache License 2.0 | 4 votes |
@Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) convertView = mLayoutInflater.inflate(R.layout.listview_items, null); final DIDLObject item = getItem(position); if (item == null) { return convertView; } //Init container icon if (item instanceof Container){ ImageView imageView = (ImageView)convertView.findViewById(R.id.listview_item_image); imageView.setBackgroundResource(R.drawable.ic_action_dock); }else if (item instanceof Item){ ImageView moreBtn = (ImageView)convertView.findViewById(R.id.listview_item_popup_menu); moreBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //Init popup menu. PopupMenu popupMenu = new PopupMenu(ContentContainerActivity.this, v); popupMenu.inflate(R.menu.menu_item_actions); popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { switch (menuItem.getItemId()){ case R.id.action_play : playItem((Item)item); break; case R.id.action_add_to_playlist : addToPlaylist((Item)item); break; default: break; } return true; } }); popupMenu.show(); } }); moreBtn.setVisibility(View.VISIBLE); } TextView titleView = (TextView)convertView.findViewById(R.id.listview_item_line_one); titleView.setText(item.getTitle()); TextView creatorView = (TextView)convertView.findViewById(R.id.listview_item_line_two); creatorView.setText(item.getCreator()); return convertView; }