Search in sources :

Example 1 with ActionInvocation

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

the class ContentContainerActivity method loadContent.

private void loadContent() {
    SystemManager systemManager = SystemManager.getInstance();
    Device device = null;
    try {
        device = systemManager.getRegistry().getDevice(new UDN(mIdentifierString), false);
    } catch (NullPointerException e) {
        Log.e(TAG, "Get device error.");
    }
    if (device != null) {
        //Get cds to browse children directories.
        Service contentDeviceService = device.findService(SystemManager.CONTENT_DIRECTORY_SERVICE);
        //Execute Browse action and init list view
        systemManager.getControlPoint().execute(new Browse(contentDeviceService, mObjectId, BrowseFlag.DIRECT_CHILDREN, "*", 0, null, new SortCriterion(true, "dc:title")) {

            @Override
            public void received(ActionInvocation actionInvocation, DIDLContent didl) {
                Message msg = Message.obtain(handler, ADD_OBJECTS, didl);
                msg.sendToTarget();
            }

            @Override
            public void updateStatus(Status status) {
            }

            @Override
            public void failure(ActionInvocation invocation, UpnpResponse operation, String defaultMsg) {
            }
        });
    }
}
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) SystemManager(com.kevinshen.beyondupnp.core.SystemManager) Service(org.fourthline.cling.model.meta.Service) DIDLContent(org.fourthline.cling.support.model.DIDLContent) Browse(org.fourthline.cling.support.contentdirectory.callback.Browse) SortCriterion(org.fourthline.cling.support.model.SortCriterion) UDN(org.fourthline.cling.model.types.UDN)

Example 2 with ActionInvocation

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

the class PlaybackCommand method stop.

public static void stop() {
    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 Stop(avtService) {

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

            @Override
            public void failure(ActionInvocation arg0, UpnpResponse arg1, String arg2) {
                Log.e(TAG, "Stop failed");
            }
        });
    }
}
Also used : UpnpResponse(org.fourthline.cling.model.message.UpnpResponse) Stop(org.fourthline.cling.support.avtransport.callback.Stop) 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 3 with ActionInvocation

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

the class PlaybackCommand method getMediaInfo.

public static void getMediaInfo(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 GetMediaInfo(avtService) {

            @Override
            public void received(ActionInvocation invocation, MediaInfo mediaInfo) {
                Message msg = Message.obtain(handler, NowplayingFragment.GET_MEDIA_INFO_ACTION);
                msg.obj = mediaInfo;
                msg.sendToTarget();
            }

            @Override
            public void failure(ActionInvocation invocation, UpnpResponse operation, String defaultMsg) {
                Log.e(TAG, "GetMediaInfo failed");
            }
        });
    }
}
Also used : GetMediaInfo(org.fourthline.cling.support.avtransport.callback.GetMediaInfo) MediaInfo(org.fourthline.cling.support.model.MediaInfo) GetMediaInfo(org.fourthline.cling.support.avtransport.callback.GetMediaInfo) 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)

Example 4 with ActionInvocation

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

the class PlaybackCommand method playNewItem.

public static void playNewItem(final String uri, final String metadata) {
    Device device = SystemManager.getInstance().getSelectedDevice();
    //Check selected device
    if (device == null)
        return;
    final Service avtService = device.findService(SystemManager.AV_TRANSPORT_SERVICE);
    if (avtService != null) {
        final ControlPoint cp = SystemManager.getInstance().getControlPoint();
        cp.execute(new Stop(avtService) {

            @Override
            public void success(ActionInvocation invocation) {
                cp.execute(new SetAVTransportURI(avtService, uri, metadata) {

                    @Override
                    public void success(ActionInvocation invocation) {
                        //Second,Set Play command.
                        cp.execute(new Play(avtService) {

                            @Override
                            public void success(ActionInvocation invocation) {
                                Log.i(TAG, "PlayNewItem success:" + uri);
                            }

                            @Override
                            public void failure(ActionInvocation arg0, UpnpResponse arg1, String arg2) {
                                Log.e(TAG, "playNewItem failed");
                            }
                        });
                    }

                    @Override
                    public void failure(ActionInvocation invocation, UpnpResponse operation, String defaultMsg) {
                    }
                });
            }

            @Override
            public void failure(ActionInvocation invocation, UpnpResponse operation, String defaultMsg) {
            }
        });
    }
}
Also used : Play(org.fourthline.cling.support.avtransport.callback.Play) UpnpResponse(org.fourthline.cling.model.message.UpnpResponse) Stop(org.fourthline.cling.support.avtransport.callback.Stop) 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) SetAVTransportURI(org.fourthline.cling.support.avtransport.callback.SetAVTransportURI)

Example 5 with ActionInvocation

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

the class PlaybackCommand method getTransportInfo.

public static void getTransportInfo(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 GetTransportInfo(avtService) {

            @Override
            public void received(ActionInvocation invocation, TransportInfo transportInfo) {
                TransportState ts = transportInfo.getCurrentTransportState();
                Log.i(TAG, "TransportState:" + ts.getValue());
                if (TransportState.PLAYING == ts) {
                    handler.sendEmptyMessage(NowplayingFragment.PLAY_ACTION);
                } else if (TransportState.PAUSED_PLAYBACK == ts) {
                    handler.sendEmptyMessage(NowplayingFragment.PAUSE_ACTION);
                } else if (TransportState.STOPPED == ts) {
                    handler.sendEmptyMessage(NowplayingFragment.STOP_ACTION);
                }
            }

            @Override
            public void failure(ActionInvocation invocation, UpnpResponse operation, String defaultMsg) {
                Log.e(TAG, "GetTransportInfo failed");
            }
        });
    }
}
Also used : GetTransportInfo(org.fourthline.cling.support.avtransport.callback.GetTransportInfo) TransportInfo(org.fourthline.cling.support.model.TransportInfo) 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) GetTransportInfo(org.fourthline.cling.support.avtransport.callback.GetTransportInfo) ControlPoint(org.fourthline.cling.controlpoint.ControlPoint) TransportState(org.fourthline.cling.support.model.TransportState)

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