Implementing of Cling to search and play media on a UPnP renderer

Posted By Shubham Saxena | 24-Dec-2014

In the previous blog, I briefly described about the cling and its configuration. Here I am pasting a part of my code that I have implemented to search a cling UPnP renderer and and used its AVTransport service to play a video on it. For the purpose of testing, you can take any renderer device which is WiFi enabled like any Smart TV or SoftDMA(although it is slow).  

It starts with making a thread.

Thread clientThread = new Thread(new notMain());



Search Devices:
In run function, I called the search function with the type of service i want to search for. For instance, here I am sreaching for "AVTransport" service that is a service provided by a renderer.

public void run() {

        System.out.println("run method started");

        try {

            upnpService = new UpnpServiceImpl(new MyUpnpServiceConfiguration());


            UDAServiceType udaType = new UDAServiceType("AVTransport");

            upnpService.getControlPoint().search(new UDAServiceTypeHeader(udaType));

            System.out.println("new STAllHeader() "+ new UDAServiceTypeHeader(udaType));

            System.out.println("upnpService " + upnpService);

        } catch (Exception ex) {

            System.err.println("Exception occured: " + ex);




Call the function that play video:
Then to play a video on any of the searched renderer, you can override the deviceAdded function. Here in the code below, I get the device UUID which id the universal id. Then I checked the deviceUuid(the code is not included but deviceUuid is just a string type variable)  if it get matched with the searched devices then from all the services of that renderer device, AVTransport service is set to be executed with the setContent function call. 

public void deviceAdded(Registry registry, Device device) {

        super.deviceAdded(registry, device);

        System.out.println("test "+device.getIdentity().getUdn().toString().contains(deviceUuid));

        if (device.getIdentity().getUdn().toString().contains(deviceUuid)) {

            Service[] services = device.findServices();

            for (Service service : services) {                

                if ("AVTransport".equals(service.getServiceType().getType())) {

                    System.out.println("device.getDisplayString(): "

                            + device.getDisplayString());






Play function:
In the setContent function, I have provided the service that we have passed in the last function, the videoURL and the metaData for the video to be played in the AVTransport class object.

Note: The metaData that I have mentioned is very much compatible with the devices like smart TV.

public void setContent(final Service service) {

        System.out.println("setContent started");

        ActionCallback setAVTransportURIAction = new SetAVTransportURI(



                "<DIDL-Lite xmlns='urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/' xmlns:dc='' xmlns:upnp='urn:schemas-upnp-org:metadata-1-0/upnp/' xmlns:dlna='urn:schemas-dlna-org:metadata-1-0/'><item id='sample' parentID='0' restricted='0'><dc:title>"+videoTitle+"</dc:title><dc:creator>Mohit</dc:creator><upnp:genre>No Genre</upnp:genre><res protocolInfo='http-get:*:video/mpeg:DLNA.ORG_FLAGS=01700000000000000000000000000000;DLNA.ORG_CI=0;DLNA.ORG_OP=01'>"+videoURL+"</res><upnp:class>object.item.videoItem</upnp:class></item></DIDL-Lite>") {


            public void failure(ActionInvocation invocation,

                    UpnpResponse operation, String defaultMsg) {

                System.out.println(" " + defaultMsg);



            public void success(ActionInvocation invocation) {
                ActionCallback playAction = getPlayAction(service);

Hope the description would help you in some way else 2 user manuals can help you in implementing the cling are:


Related Tags

Related Blogs

An Introduction About Non Functional Testing
Neha Saini | 23-May-2018
Here Is An Overview About Specflow
Smita Gupta | 18-Jun-2018
Explain Fluent Wait In Selenium Webdriver
Mohd Sheemal | 13-Jun-2018
Overview of Behavior Data Driven
Smita Gupta | 22-May-2018
What is API And What is Rest And Soap API
Himanshu Shukla | 22-May-2018
What is Agile Delivery
Anjali Pandey | 31-May-2018
An Introduction About Spike Testing
Neha Saini | 11-Jun-2018
Logging Infrastructure in Python
Rohitesh Rawat | 29-Jun-2018
Roles And Responsibilities Of A QA Leader
Suraj Mishra | 31-May-2018
Structure Based Testing Techniques
Divya Varnwal | 26-May-2018
Hikvision DVR Desktop Application View With Hikconnet ID
Shiv Shankar | 31-May-2018
Request for Proposal

Recaptcha is required.

Sending message..