Search in sources :

Example 6 with ActionInvocation

use of org.fourthline.cling.model.action.ActionInvocation in project BeyondUPnP by kevinshine.

the class PlaybackCommand method play.

public static void play() {
    Device device = SystemManager.getInstance().getSelectedDevice();
    //Check selected device
    if (device == null)
        return;
    Service avtService = device.findService(SystemManager.AV_TRANSPORT_SERVICE);
    if (avtService != null) {
        ControlPoint cp = SystemManager.getInstance().getControlPoint();
        cp.execute(new Play(avtService) {

            @Override
            public void success(ActionInvocation invocation) {
                Log.i(TAG, "Play success.");
            }

            @Override
            public void failure(ActionInvocation arg0, UpnpResponse arg1, String arg2) {
                Log.e(TAG, "Play failed");
            }
        });
    }
}
Also used : Play(org.fourthline.cling.support.avtransport.callback.Play) UpnpResponse(org.fourthline.cling.model.message.UpnpResponse) Device(org.fourthline.cling.model.meta.Device) ActionInvocation(org.fourthline.cling.model.action.ActionInvocation) Service(org.fourthline.cling.model.meta.Service) ControlPoint(org.fourthline.cling.controlpoint.ControlPoint)

Example 7 with ActionInvocation

use of org.fourthline.cling.model.action.ActionInvocation in project libresonic by Libresonic.

the class ClingRouter method addPortMappingImpl.

private void addPortMappingImpl(Service connectionService, int port) throws Exception {
    final Semaphore gotReply = new Semaphore(0);
    final AtomicReference<String> error = new AtomicReference<String>();
    upnpService.getControlPoint().execute(new PortMappingAdd(connectionService, createPortMapping(port)) {

        @Override
        public void success(ActionInvocation invocation) {
            gotReply.release();
        }

        @Override
        public void failure(ActionInvocation invocation, UpnpResponse response, String defaultMsg) {
            error.set(String.valueOf(response) + ": " + defaultMsg);
            gotReply.release();
        }
    });
    gotReply.acquire();
    if (error.get() != null) {
        throw new Exception(error.get());
    }
}
Also used : UpnpResponse(org.fourthline.cling.model.message.UpnpResponse) ActionInvocation(org.fourthline.cling.model.action.ActionInvocation) AtomicReference(java.util.concurrent.atomic.AtomicReference) Semaphore(java.util.concurrent.Semaphore) PortMappingAdd(org.fourthline.cling.support.igd.callback.PortMappingAdd) UnknownHostException(java.net.UnknownHostException)

Example 8 with ActionInvocation

use of org.fourthline.cling.model.action.ActionInvocation in project BeyondUPnP by kevinshine.

the class PlaybackCommand method getPositionInfo.

public static void getPositionInfo(final Handler handler) {
    Device device = SystemManager.getInstance().getSelectedDevice();
    //Check selected device
    if (device == null)
        return;
    Service avtService = device.findService(SystemManager.AV_TRANSPORT_SERVICE);
    if (avtService != null) {
        ControlPoint cp = SystemManager.getInstance().getControlPoint();
        cp.execute(new GetPositionInfo(avtService) {

            @Override
            public void received(ActionInvocation invocation, PositionInfo positionInfo) {
                Message msg = Message.obtain(handler, NowplayingFragment.GET_POSITION_INFO_ACTION);
                msg.obj = positionInfo;
                msg.sendToTarget();
            }

            @Override
            public void failure(ActionInvocation invocation, UpnpResponse operation, String defaultMsg) {
                Log.e(TAG, "GetPositionInfo failed");
            }
        });
    }
}
Also used : Message(android.os.Message) UpnpResponse(org.fourthline.cling.model.message.UpnpResponse) Device(org.fourthline.cling.model.meta.Device) ActionInvocation(org.fourthline.cling.model.action.ActionInvocation) Service(org.fourthline.cling.model.meta.Service) GetPositionInfo(org.fourthline.cling.support.avtransport.callback.GetPositionInfo) PositionInfo(org.fourthline.cling.support.model.PositionInfo) ControlPoint(org.fourthline.cling.controlpoint.ControlPoint) GetPositionInfo(org.fourthline.cling.support.avtransport.callback.GetPositionInfo)

Example 9 with ActionInvocation

use of org.fourthline.cling.model.action.ActionInvocation in project BeyondUPnP by kevinshine.

the class PlaybackCommand method getVolume.

public static void getVolume(final Handler handler) {
    Device device = SystemManager.getInstance().getSelectedDevice();
    //Check selected device
    if (device == null)
        return;
    Service rcService = device.findService(SystemManager.RENDERING_CONTROL_SERVICE);
    if (rcService != null) {
        ControlPoint cp = SystemManager.getInstance().getControlPoint();
        cp.execute(new GetVolume(rcService) {

            @Override
            public void received(ActionInvocation actionInvocation, int currentVolume) {
                //Send currentVolume to handler.
                Log.i(TAG, "GetVolume:" + currentVolume);
                Message msg = Message.obtain(handler, NowplayingFragment.GET_VOLUME_ACTION, currentVolume, 0);
                msg.sendToTarget();
            }

            @Override
            public void failure(ActionInvocation invocation, UpnpResponse operation, String defaultMsg) {
                Log.e(TAG, "GetVolume failed");
            }
        });
    }
}
Also used : GetVolume(org.fourthline.cling.support.renderingcontrol.callback.GetVolume) Message(android.os.Message) UpnpResponse(org.fourthline.cling.model.message.UpnpResponse) Device(org.fourthline.cling.model.meta.Device) ActionInvocation(org.fourthline.cling.model.action.ActionInvocation) Service(org.fourthline.cling.model.meta.Service) ControlPoint(org.fourthline.cling.controlpoint.ControlPoint) ControlPoint(org.fourthline.cling.controlpoint.ControlPoint)

Example 10 with ActionInvocation

use of org.fourthline.cling.model.action.ActionInvocation in project BeyondUPnP by kevinshine.

the class PlaybackCommand method pause.

public static void pause() {
    Device device = SystemManager.getInstance().getSelectedDevice();
    //Check selected device
    if (device == null)
        return;
    Service avtService = device.findService(SystemManager.AV_TRANSPORT_SERVICE);
    if (avtService != null) {
        ControlPoint cp = SystemManager.getInstance().getControlPoint();
        cp.execute(new Pause(avtService) {

            @Override
            public void success(ActionInvocation invocation) {
                Log.i(TAG, "Pause success.");
            }

            @Override
            public void failure(ActionInvocation arg0, UpnpResponse arg1, String arg2) {
                Log.e(TAG, "Pause failed");
            }
        });
    }
}
Also used : Pause(org.fourthline.cling.support.avtransport.callback.Pause) UpnpResponse(org.fourthline.cling.model.message.UpnpResponse) Device(org.fourthline.cling.model.meta.Device) ActionInvocation(org.fourthline.cling.model.action.ActionInvocation) Service(org.fourthline.cling.model.meta.Service) ControlPoint(org.fourthline.cling.controlpoint.ControlPoint)

Aggregations

ActionInvocation (org.fourthline.cling.model.action.ActionInvocation)13 UpnpResponse (org.fourthline.cling.model.message.UpnpResponse)13 Device (org.fourthline.cling.model.meta.Device)11 Service (org.fourthline.cling.model.meta.Service)11 ControlPoint (org.fourthline.cling.controlpoint.ControlPoint)10 Message (android.os.Message)4 Semaphore (java.util.concurrent.Semaphore)2 Play (org.fourthline.cling.support.avtransport.callback.Play)2 Stop (org.fourthline.cling.support.avtransport.callback.Stop)2 SystemManager (com.kevinshen.beyondupnp.core.SystemManager)1 UnknownHostException (java.net.UnknownHostException)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 UDN (org.fourthline.cling.model.types.UDN)1 GetMediaInfo (org.fourthline.cling.support.avtransport.callback.GetMediaInfo)1 GetPositionInfo (org.fourthline.cling.support.avtransport.callback.GetPositionInfo)1 GetTransportInfo (org.fourthline.cling.support.avtransport.callback.GetTransportInfo)1 Pause (org.fourthline.cling.support.avtransport.callback.Pause)1 Seek (org.fourthline.cling.support.avtransport.callback.Seek)1 SetAVTransportURI (org.fourthline.cling.support.avtransport.callback.SetAVTransportURI)1 Browse (org.fourthline.cling.support.contentdirectory.callback.Browse)1