org.fourthline.cling.support.model.BrowseFlag Java Examples

The following examples show how to use org.fourthline.cling.support.model.BrowseFlag. 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: Browse.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param maxResults Can be <code>null</code>, then {@link #getDefaultMaxResults()} is used.
 */
public Browse(Service service, String objectID, BrowseFlag flag,
                            String filter, long firstResult, Long maxResults, SortCriterion... orderBy) {

    super(new ActionInvocation(service.getAction("Browse")));

    log.fine("Creating browse action for object ID: " + objectID);

    getActionInvocation().setInput("ObjectID", objectID);
    getActionInvocation().setInput("BrowseFlag", flag.toString());
    getActionInvocation().setInput("Filter", filter);
    getActionInvocation().setInput("StartingIndex", new UnsignedIntegerFourBytes(firstResult));
    getActionInvocation().setInput("RequestedCount",
            new UnsignedIntegerFourBytes(maxResults == null ? getDefaultMaxResults() : maxResults)
    );
    getActionInvocation().setInput("SortCriteria", SortCriterion.toString(orderBy));
}
 
Example #2
Source File: BeyondContentDirectoryService.java    From BeyondUPnP with Apache License 2.0 6 votes vote down vote up
@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 #3
Source File: Browse.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @param maxResults Can be <code>null</code>, then {@link #getDefaultMaxResults()} is used.
 */
public Browse(Service service, String objectID, BrowseFlag flag,
                            String filter, long firstResult, Long maxResults, SortCriterion... orderBy) {

    super(new ActionInvocation(service.getAction("Browse")));

    log.fine("Creating browse action for object ID: " + objectID);

    getActionInvocation().setInput("ObjectID", objectID);
    getActionInvocation().setInput("BrowseFlag", flag.toString());
    getActionInvocation().setInput("Filter", filter);
    getActionInvocation().setInput("StartingIndex", new UnsignedIntegerFourBytes(firstResult));
    getActionInvocation().setInput("RequestedCount",
            new UnsignedIntegerFourBytes(maxResults == null ? getDefaultMaxResults() : maxResults)
    );
    getActionInvocation().setInput("SortCriteria", SortCriterion.toString(orderBy));
}
 
Example #4
Source File: FolderBasedContentDirectory.java    From subsonic with GNU General Public License v3.0 5 votes vote down vote up
@Override
public BrowseResult browse(String objectId, BrowseFlag browseFlag, String filter, long firstResult,
        long maxResults, SortCriterion[] orderby) throws ContentDirectoryException {

    if (!settingsService.getLicenseInfo().isLicenseOrTrialValid()) {
        LOG.warn("UPnP/DLNA media server not available. Please upgrade to Subsonic Premium.");
        throw new ContentDirectoryException(ContentDirectoryErrorCode.CANNOT_PROCESS, "Please upgrade to Subsonic Premium");
    }

    LOG.info("UPnP request - objectId: " + objectId + ", browseFlag: " + browseFlag + ", filter: " + filter +
            ", firstResult: " + firstResult + ", maxResults: " + maxResults);

    // maxResult == 0 means all.
    if (maxResults == 0) {
        maxResults = Integer.MAX_VALUE;
    }

    try {
        if (CONTAINER_ID_ROOT.equals(objectId)) {
            return browseFlag == BrowseFlag.METADATA ? browseRootMetadata() : browseRoot(firstResult, maxResults);
        }
        if (CONTAINER_ID_PLAYLIST_ROOT.equals(objectId)) {
            return browseFlag == BrowseFlag.METADATA ? browsePlaylistRootMetadata() : browsePlaylistRoot(firstResult, maxResults);
        }
        if (objectId.startsWith(CONTAINER_ID_PLAYLIST_PREFIX)) {
            int playlistId = Integer.parseInt(objectId.replace(CONTAINER_ID_PLAYLIST_PREFIX, ""));
            Playlist playlist = playlistService.getPlaylist(playlistId);
            return browseFlag == BrowseFlag.METADATA ? browsePlaylistMetadata(playlist) : browsePlaylist(playlist, firstResult, maxResults);
        }

        int mediaFileId = Integer.parseInt(objectId.replace(CONTAINER_ID_FOLDER_PREFIX, ""));
        MediaFile mediaFile = mediaFileService.getMediaFile(mediaFileId);
        return browseFlag == BrowseFlag.METADATA ? browseMediaFileMetadata(mediaFile) : browseMediaFile(mediaFile, firstResult, maxResults);

    } catch (Throwable x) {
        LOG.error("UPnP error: " + x, x);
        throw new ContentDirectoryException(ContentDirectoryErrorCode.CANNOT_PROCESS, x.toString());
    }
}
 
Example #5
Source File: ContentContainerActivity.java    From BeyondUPnP with Apache License 2.0 5 votes vote down vote up
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 #6
Source File: ContentBrowseActionCallback.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
public ContentBrowseActionCallback(Activity activity, Service service,
		Container container, ArrayList<ContentItem> list, Handler handler) {
	super(service, container.getId(), BrowseFlag.DIRECT_CHILDREN, "*", 0,
			null, new SortCriterion(true, "dc:title"));
	this.activity = activity;
	this.service = service;
	this.container = container;
	this.list = list;
	this.handler = handler;
}
 
Example #7
Source File: Browse.java    From TVRemoteIME with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Browse with first result 0 and {@link #getDefaultMaxResults()}, filters with {@link #CAPS_WILDCARD}.
 */
public Browse(Service service, String containerId, BrowseFlag flag) {
    this(service, containerId, flag, CAPS_WILDCARD, 0, null);
}
 
Example #8
Source File: ContentDirectoryService.java    From HPlayer with Apache License 2.0 4 votes vote down vote up
@Override
public BrowseResult browse(String objectID, BrowseFlag browseFlag, String s1, long l, long l1,
                           SortCriterion[] sortCriterions) throws ContentDirectoryException {
    try {

        DIDLContent didl = new DIDLContent();

        ContentNode contentNode = ContentTree.getNode(objectID);

        Log.d(TAG, "someone's browsing id: " + objectID);

        if (contentNode == null) { // 没有共享资源
            return new BrowseResult("", 0, 0);
        }

        if (contentNode.isItem()) { // 是文件
            didl.addItem(contentNode.getItem());

            Log.v(TAG, "returing item: " + contentNode.getItem().getTitle());

            return new BrowseResult(new DIDLParser().generate(didl), 1, 1);

        } else { // 是文件夹
            if (browseFlag == BrowseFlag.METADATA) {
                didl.addContainer(contentNode.getContainer());

                Log.v(TAG, "returning metadata of container: " + contentNode.getContainer().getTitle());

                return new BrowseResult(new DIDLParser().generate(didl), 1, 1);

            } else {
                for (Container container : contentNode.getContainer().getContainers()) {
                    didl.addContainer(container);

                    Log.v(TAG, "getting child container: " + container.getTitle());
                }
                for (Item item : contentNode.getContainer().getItems()) {
                    didl.addItem(item);

                    Log.v(TAG, "getting child item: " + item.getTitle());
                }
                return new BrowseResult(new DIDLParser().generate(didl),
                        contentNode.getContainer().getChildCount(),
                        contentNode.getContainer().getChildCount());
            }

        }

    } catch (Exception e) {
        throw new ContentDirectoryException(
                ContentDirectoryErrorCode.CANNOT_PROCESS, e.toString());
    }
}
 
Example #9
Source File: ContentBrowseActionCallback.java    From HPlayer with Apache License 2.0 4 votes vote down vote up
public ContentBrowseActionCallback(Service service, Container container, OnReceiveListener listener) {
    super(service, container.getId(), BrowseFlag.DIRECT_CHILDREN, "*", 0,
            null, new SortCriterion(true, "dc:title"));
    this.service = service;
    this.onReceiveListener = listener;
}
 
Example #10
Source File: ContentBrowseActionCallback.java    From HPlayer with Apache License 2.0 4 votes vote down vote up
public ContentBrowseActionCallback(Service service, String id, OnReceiveListener listener) {
    super(service, id, BrowseFlag.DIRECT_CHILDREN, "*", 0,
            null, new SortCriterion(true, "dc:title"));
    this.service = service;
    this.onReceiveListener = listener;
}
 
Example #11
Source File: Browse.java    From DroidDLNA with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Browse with first result 0 and {@link #getDefaultMaxResults()}, filters with {@link #CAPS_WILDCARD}.
 */
public Browse(Service service, String containerId, BrowseFlag flag) {
    this(service, containerId, flag, CAPS_WILDCARD, 0, null);
}
 
Example #12
Source File: ContentDirectoryService.java    From DroidDLNA with GNU General Public License v3.0 4 votes vote down vote up
@Override
public BrowseResult browse(String objectID, BrowseFlag browseFlag,
		String filter, long firstResult, long maxResults,
		SortCriterion[] orderby) throws ContentDirectoryException {
	// TODO Auto-generated method stub
	try {

		DIDLContent didl = new DIDLContent();

		ContentNode contentNode = ContentTree.getNode(objectID);
		
		Log.v(LOGTAG, "someone's browsing id: " + objectID);

		if (contentNode == null)
			return new BrowseResult("", 0, 0);

		if (contentNode.isItem()) {
			didl.addItem(contentNode.getItem());
			
			Log.v(LOGTAG, "returing item: " + contentNode.getItem().getTitle());
			
			return new BrowseResult(new DIDLParser().generate(didl), 1, 1);
		} else {
			if (browseFlag == BrowseFlag.METADATA) {
				didl.addContainer(contentNode.getContainer());
				
				Log.v(LOGTAG, "returning metadata of container: " + contentNode.getContainer().getTitle());
				
				return new BrowseResult(new DIDLParser().generate(didl), 1,
						1);
			} else {
				for (Container container : contentNode.getContainer()
						.getContainers()) {
					didl.addContainer(container);
					
					Log.v(LOGTAG, "getting child container: " + container.getTitle());
				}
				for (Item item : contentNode.getContainer().getItems()) {
					didl.addItem(item);
					
					Log.v(LOGTAG, "getting child item: " + item.getTitle());
				}
				return new BrowseResult(new DIDLParser().generate(didl),
						contentNode.getContainer().getChildCount(),
						contentNode.getContainer().getChildCount());
			}

		}

	} catch (Exception ex) {
		throw new ContentDirectoryException(
				ContentDirectoryErrorCode.CANNOT_PROCESS, ex.toString());
	}
}
 
Example #13
Source File: AbstractContentDirectoryService.java    From TVRemoteIME with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Implement this method to implement browsing of your content.
 * <p>
 * This is a required action defined by <em>ContentDirectory:1</em>.
 * </p>
 * <p>
 * You should wrap any exception into a {@link ContentDirectoryException}, so a propery
 * error message can be returned to control points.
 * </p>
 */
public abstract BrowseResult browse(String objectID, BrowseFlag browseFlag,
                                    String filter,
                                    long firstResult, long maxResults,
                                    SortCriterion[] orderby) throws ContentDirectoryException;
 
Example #14
Source File: AbstractContentDirectoryService.java    From DroidDLNA with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Implement this method to implement browsing of your content.
 * <p>
 * This is a required action defined by <em>ContentDirectory:1</em>.
 * </p>
 * <p>
 * You should wrap any exception into a {@link ContentDirectoryException}, so a propery
 * error message can be returned to control points.
 * </p>
 */
public abstract BrowseResult browse(String objectID, BrowseFlag browseFlag,
                                    String filter,
                                    long firstResult, long maxResults,
                                    SortCriterion[] orderby) throws ContentDirectoryException;