@Override public void endElement(ELEMENT element) throws SAXException { switch (element) { case deviceType: getInstance().deviceType = getCharacters(); break; case friendlyName: getInstance().friendlyName = getCharacters(); break; case manufacturer: getInstance().manufacturer = getCharacters(); break; case manufacturerURL: getInstance().manufacturerURI = parseURI(getCharacters()); break; case modelDescription: getInstance().modelDescription = getCharacters(); break; case modelName: getInstance().modelName = getCharacters(); break; case modelNumber: getInstance().modelNumber = getCharacters(); break; case modelURL: getInstance().modelURI = parseURI(getCharacters()); break; case presentationURL: getInstance().presentationURI = parseURI(getCharacters()); break; case UPC: getInstance().upc = getCharacters(); break; case serialNumber: getInstance().serialNumber = getCharacters(); break; case UDN: getInstance().udn = UDN.valueOf(getCharacters()); break; case X_DLNADOC: String txt = getCharacters(); try { getInstance().dlnaDocs.add(DLNADoc.valueOf(txt)); } catch (InvalidValueException ex) { log.info("Invalid X_DLNADOC value, ignoring value: " + txt); } break; case X_DLNACAP: getInstance().dlnaCaps = DLNACaps.valueOf(getCharacters()); break; } }
public class MediaServer extends Thread { private UDN udn = UDN.uniqueSystemIdentifier("GNaP-MediaServer"); private LocalDevice localDevice; private static final String deviceType = "MediaServer"; private static final int version = 1; private static final String LOGTAG = "GNaP-MediaServer"; private static final int port = 8192; private static InetAddress localAddress; public MediaServer(InetAddress localAddress) throws ValidationException { DeviceType type = new UDADeviceType(deviceType, version); DeviceDetails details = new DeviceDetails( android.os.Build.MODEL, new ManufacturerDetails(android.os.Build.MANUFACTURER), new ModelDetails("GNaP", "GNaP MediaServer for Android", "v1")); LocalService service = new AnnotationLocalServiceBinder().read(ContentDirectoryService.class); service.setManager( new DefaultServiceManager<ContentDirectoryService>(service, ContentDirectoryService.class)); localDevice = new LocalDevice(new DeviceIdentity(udn), type, details, service); this.localAddress = localAddress; Log.v(LOGTAG, "MediaServer device created: "); Log.v(LOGTAG, "friendly name: " + details.getFriendlyName()); Log.v(LOGTAG, "manufacturer: " + details.getManufacturerDetails().getManufacturer()); Log.v(LOGTAG, "model: " + details.getModelDetails().getModelName()); } public LocalDevice getDevice() { return localDevice; } public String getAddress() { return localAddress.getHostAddress() + ":" + port; } @Override public void run() { // TODO Auto-generated method stub if (localAddress == null) { Log.w(LOGTAG, "no network address avalibe to listen"); return; } ServerSocket Server; try { Server = new ServerSocket(port, 10, localAddress); System.out.println( "TCPServer Waiting for client on " + localAddress.getHostAddress() + ": " + port); while (true) { Socket connected = Server.accept(); (new HttpServer(connected)).start(); } } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }