⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 renderingcontrolservice.java

📁 国外的j2me播放器软件
💻 JAVA
字号:
package no.auc.one.portableplayer.communication.mediarenderer;

import java.io.ByteArrayInputStream;
import java.io.IOException;

import no.auc.one.portableplayer.communication.UPnPService;
import no.auc.one.portableplayer.communication.soap.*;
import no.auc.one.portableplayer.utils.Cloneable;

import org.apache.log4j.Logger;

public class RenderingControlService extends UPnPService implements Cloneable {

    private static Logger LOG = Logger.getLogger("RCS");

    // XXX Notice that most/all actions are OPTIONAL defined in the UPnP spec.
    //     Therefore need a mechanism to check the SCPD if it is supported or 
    //     not.

    /**
     * Construct instance based on a UPnPService.
     */
    public RenderingControlService(UPnPService service) {
        super(
            service.getServiceType(), 
            service.getServiceID(), 
            service.getScpdURL(), 
            service.getEventSubURL(), 
            service.getControlURL());
	}

    /**
     * Creates a clone of this class instance.
     *
     * @return Clone of this class instance.
     */
    public Object clone() {
        return new RenderingControlService((UPnPService)this);
    }

    /**
     * Get the current status of the mute property for the master channel.
     *
     * (XXX InstanceID SHOULD be state held by this class.)
     *
     * @return Current master mute setting.
     */
    public boolean getMute() throws IOException {
        SoapInvoke si = new SoapInvoke(
            "\"urn:schemas-upnp-org:service:RenderingControl:1#GetMute\"",
            getControlURL());

        StringBuffer buffer = new StringBuffer();
        buffer.append("<?xml version=\"1.0\" encoding=\"utf-8\">\r\n");
	    buffer.append(
            "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" " + 
            "s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n");
	    buffer.append("<s:Body>\r\n");
		buffer.append(
            "<u:GetMute xmlns:u=\"urn:schemas-upnp-org:service:RenderingControl:1\">\r\n");
		buffer.append("<InstanceID>0</InstanceID>\r\n"); // TODO Add support for specific instances
		buffer.append("<Channel>Master</CurrentURI>\r\n");
		buffer.append("</u:GetMute>\r\n");
		buffer.append("</s:Body>\r\n");
		buffer.append("</s:Envelope>\r\n");

	    si.setBody(buffer.toString());

	    String resp = si.invoke(
	        "\"urn:schemas-upnp-org:service:RenderingControl:1#GetMute\"");

        System.out.println("Response: \r\n" + resp);
        SoapResultParser srp = new SoapResultParser(new ByteArrayInputStream(resp.getBytes()));
	        
        srp.parseSoapResult("CurrentMute");
        boolean ret = false;

        try {
            ret = srp.getBooleanResult();
        
            LOG.debug("GetMute result (" + ret + ")");
        } catch (Exception e) {
            LOG.fatal("Error getting result");
            LOG.fatal(e);
        }

        return ret;
    }
    
    /**
     * Set the mute property for a specific channel.
     */
    public void setMute(boolean mute) throws IOException {
        SoapInvoke si = new SoapInvoke(
            "\"urn:schemas-upnp-org:service:RenderingControl:1#SetMute\"",
            getControlURL());

        StringBuffer buffer = new StringBuffer();
        buffer.append("<?xml version=\"1.0\" encoding=\"utf-8\">\r\n");
	    buffer.append(
            "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" " + 
            "s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n");
	    buffer.append("<s:Body>\r\n");
		buffer.append(
            "<u:SetMute xmlns:u=\"urn:schemas-upnp-org:service:RenderingControl:1\">\r\n");
		buffer.append("<InstanceID>0</InstanceID>\r\n"); // TODO Add support for specific instances
		buffer.append("<Channel>Master</CurrentURI>\r\n");
        buffer.append("<DesiredMute>");
        if (mute) {
            buffer.append("1");
        } else {
            buffer.append("0");
        }
        buffer.append("</DesiredMute>");
		buffer.append("</u:SetMute>\r\n");
		buffer.append("</s:Body>\r\n");
		buffer.append("</s:Envelope>\r\n");

	    si.setBody(buffer.toString());

	    String resp = si.invoke(
	        "\"urn:schemas-upnp-org:service:RenderingControl:1#SetMute\"");

        System.out.println("Response: \r\n" + resp);
    }
    
    
    
    
    /**
     * Get the current status of the volume property for the master channel.
     *
     * (XXX InstanceID SHOULD be state held by this class.)
     *
     * @return Current master volume setting.
     * @throws IOException 
     */
    
    public int getVolume() throws IOException {
	    
	    SoapInvoke si = new SoapInvoke(
            "\"urn:schemas-upnp-org:service:RenderingControl:1#GetVolume\"",
            getControlURL());

        StringBuffer buffer = new StringBuffer();
        buffer.append("<?xml version=\"1.0\" encoding=\"utf-8\">\r\n");
	    buffer.append(
            "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" " + 
            "s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n");
	    buffer.append("<s:Body>\r\n");
		buffer.append(
            "<u:GetVolume xmlns:u=\"urn:schemas-upnp-org:service:RenderingControl:1\">\r\n");
		buffer.append("<InstanceID>0</InstanceID>\r\n"); // TODO Add support for specific instances
		buffer.append("<Channel>Master</CurrentURI>\r\n");
		buffer.append("</u:GetVolume>\r\n");
		buffer.append("</s:Body>\r\n");
		buffer.append("</s:Envelope>\r\n");

	    si.setBody(buffer.toString());

	    String resp = si.invoke(
	        "\"urn:schemas-upnp-org:service:RenderingControl:1#GetVolume\"");

        System.out.println("Response: \r\n" + resp);
        SoapResultParser srp = new SoapResultParser(new ByteArrayInputStream(resp.getBytes()));
	        
        srp.parseSoapResult("CurrentVolume");
        int ret = 0;

        try {
            ret = srp.getIntegerResult();
        
            LOG.debug("GetVolume result (" + ret + ")");
        } catch (Exception e) {
            LOG.fatal("Error getting result");
            LOG.fatal(e);
        }

        return ret;
	    
	    
    }
    
    
     /**
     * Set the volume property for a specific channel.
     * @throws IOException 
     */
    public void setVolume(int volume) throws IOException {
	    SoapInvoke si = new SoapInvoke(
            "\"urn:schemas-upnp-org:service:RenderingControl:1#SetVolume\"",
            getControlURL());

        StringBuffer buffer = new StringBuffer();
        buffer.append("<?xml version=\"1.0\" encoding=\"utf-8\">\r\n");
	    buffer.append(
            "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" " + 
            "s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n");
	    buffer.append("<s:Body>\r\n");
		buffer.append(
            "<u:SetVolume xmlns:u=\"urn:schemas-upnp-org:service:RenderingControl:1\">\r\n");
		buffer.append("<InstanceID>0</InstanceID>\r\n"); // TODO Add support for specific instances
		buffer.append("<Channel>Master</CurrentURI>\r\n");
        buffer.append("<DesiredVolume>");
        buffer.append(volume);
        buffer.append("</DesiredVolume>");
		buffer.append("</u:SetVolume>\r\n");
		buffer.append("</s:Body>\r\n");
		buffer.append("</s:Envelope>\r\n");

	    si.setBody(buffer.toString());

	    String resp = si.invoke(
	        "\"urn:schemas-upnp-org:service:RenderingControl:1#SetVolume\"");

        System.out.println("Response: \r\n" + resp);
    }
    
    // XXX To be implemented later... 
    
    public void getVolumeDB() {
    }

    public void setVolumeDB() {
    }

    public void getVolumeDBRange() {
    }

    public void getLoudness() {
    }

    public void setLoudness() {
    }
}

⌨️ 快捷键说明

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