mediaserverfactory.java

来自「国外的j2me播放器软件」· Java 代码 · 共 83 行

JAVA
83
字号
package no.auc.one.portableplayer.communication.mediaserver;

import java.util.Vector;

import org.apache.log4j.*;
import org.xml.sax.SAXException;

import no.auc.one.portableplayer.communication.*;

public final class MediaServerFactory extends UPnPDeviceFactory {
	private static Logger LOG = Logger.getLogger("MS");
	
	/**
	 * Find all media servers available.
	 */
	public Vector findMediaServers() {
		return findMediaServers("urn:schemas-upnp-org:device:MediaServer:1");
	}
    
    public Vector findMediaServers(String searchString) {
		return super.findUPnPDevice(
            searchString,
			new MediaServerDeviceDescriptionHandler());
    }
    
    public MediaServer getMediaServer(String locationUrl) {
		MediaServer ms = null;
    			
        ms = (MediaServer)super.getUPnPDevice(
                locationUrl, 
                new MediaServerDeviceDescriptionHandler(locationUrl));

        if (ms != null) {
            LOG.debug(
                "MediaServer found " + 
                " Name:" + ms.getFriendlyName() + 
                " URLBase:"  + ms.getURLBase() + 
                " CDS:" + ms.getContentDirectoryService().toString());
        }
        
        return ms;
    }
    	
    private class MediaServerDeviceDescriptionHandler extends UPnPDeviceDescriptionHandler {
    	private MediaServer ms;
        
    	public MediaServerDeviceDescriptionHandler() {
            super();
        }
		
    	public MediaServerDeviceDescriptionHandler(String url) {
            super(url);
        }
        
        public void endDocument() throws SAXException {
            super.endDocument();
            
    		if (services == null) {
    			return;
    		}
			
			ms = new MediaServer(dev);
			dev = (UPnPDevice)ms;

        	for (int i=0; i < services.size(); i++){
        		UPnPService currentService = (UPnPService)services.elementAt(i);
        		
        		if (currentService == null) {
        			continue;
        		}
                
        		if (currentService.getServiceType().equals("urn:schemas-upnp-org:service:ContentDirectory:1")){
                    ms.setContentDirectoryService(
						new ContentDirectoryService(currentService));
                    break;  // FYI: If more services are needed to be 
                            //      initialized in the future then this break
                            //      statement must be removed!
        		}
        	}
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?