Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Simple code sample for beginner

Anonymous
2012-05-26
2013-05-02

  • Anonymous
    2012-05-26

    Hi,
    I discovered Cyberlink for Java while exploring about UPnP AV.
    Although the standards mentioned at upnp.org are self-explanatory, the CLink for Java library is not.
    There are very few comments/remarks on http://www.cybergarage.org/doxygen/clinkjava/.

    I would like to contribute to the project by providing well laid out samples once I get started myself.
    Any pointers/links to basic upnp av source code for beginners?

    It would be great if someone can attach Java example code for very basic scenario like playing a music/movie(located on a server) file on a TV.

    Thanks in anticipation,

     

  • Anonymous
    2012-05-26

    To be more specific, I m trying to make the following code work:

    public class DlnaTest implements DeviceChangeListener, SearchResponseListener 
    {
        private  volatile List<Device> mediaServers;
        private List<Device> mediaRenderers;
        private ControlPoint point;
    
        public DlnaTest()
        {
            this.mediaServers = new ArrayList<Device>();
            this.mediaRenderers = new ArrayList<Device>();
            point = new ControlPoint(30900,40900); 
            point.start();
            log("point started");
            point.addDeviceChangeListener(this);
            point.search("upnp:rootdevice");
        }
    
        public void play()
        {
            log("playing starts");
            Device tv = this.mediaRenderers.get(0);
            // ----- unable to figure out the order or actions to be called and parameters to be supplied 
            Action playAction = tv.getAction("SetAVTransportURI");
            playAction.setArgumentValue("CurrentURI", "?????  http://172.16.3.13:30888/__contentStream/5dee2b801c046ee68b8a341eea6b8edd/TVMOBiLi/s0-1481y5z1311799106.mp3");
            playAction.setArgumentValue("InstanceID", "?????");
            playAction.postControlAction();
    
            playAction = tv.getAction("Play");
            playAction.setArgumentValue("InstanceID", "urn:upnp-org:serviceId:AVTransport");
            playAction.setArgumentValue("Speed", "0");
            playAction.postControlAction();
            log("played");
        }
    
        @Override
        public void deviceAdded(Device device)
        {
            if(device.getDeviceType().contains("urn:schemas-upnp-org:device:MediaServer:1") )
            {
                log("adding server" +device.getFriendlyName());
                this.mediaServers.add(device);
            }
        }
    
        @Override
        public void deviceRemoved(Device device) 
        {
            if(device.getDeviceType().contains("urn:schemas-upnp-org:device:MediaServer:1"))
            {
                log("removing server" +device.getFriendlyName());
                this.mediaServers.remove(device);
            }
        }
    
        @Override
        public void deviceSearchResponseReceived(SSDPPacket arg0) {
        ......  
        }
        public static void main(String[] args) throws InterruptedException, InvalidDescriptionException 
        {
    
            DlnaTest test = new DlnaTest();
            Device renderer = new Device("C:\\Users\\Paragon\\Desktop\\SamsungMRDesc.xml");
            test.mediaRenderers.add(renderer);
            log("tv added ");
            Thread.sleep(6000);
            test.play();
            test.point.stop();
        }
    
    }