protected boolean isProtocolInfoMatch(List<ProtocolInfo> supportedProtocols, Res resource) { ProtocolInfo resourceProtocolInfo = resource.getProtocolInfo(); if (!resourceProtocolInfo.getProtocol().equals(Protocol.HTTP_GET)) return false; MimeType resourceMimeType; try { resourceMimeType = resourceProtocolInfo.getContentFormatMimeType(); } catch (IllegalArgumentException ex) { ContentDirectoryControlPoint.LOGGER.warning( "Illegal resource mime type: " + resourceProtocolInfo.getContentFormat() ); return false; } for (ProtocolInfo supportedProtocol : supportedProtocols) { // We currently only support HTTP-GET if (!Protocol.HTTP_GET.equals(supportedProtocol.getProtocol())) continue; try { if (supportedProtocol.getContentFormatMimeType().equals(resourceMimeType)) { return true; } else if (supportedProtocol.getContentFormatMimeType().isCompatible(resourceMimeType)) { return true; } } catch (IllegalArgumentException ex) { ContentDirectoryControlPoint.LOGGER.warning( "Illegal MediaRenderer supported mime type: " + supportedProtocol.getContentFormat() ); } } return false; }
@Override public Response serve(IHTTPSession session) { String itemId = session.getUri().replaceFirst("/", ""); itemId = URLDecoder.decode(itemId); if (itemId != null && ContentTree.hasNode(itemId)) { ContentNode node = ContentTree.getNode(itemId); if (node.isItem()) { String localPath = node.getFullPath(); Long fileSize = node.getItem().getFirstResource().getSize(); String mimeType = node.getItem().getFirstResource() .getProtocolInfo().getContentFormatMimeType().toString(); return responseFile(mimeType, localPath, fileSize); } } Log.d(TAG, " response error!"); String msg = "<html><body><h1>Error</h1>\n" + "</body></html>\n"; return newFixedLengthResponse(msg); }