1

私は Android で Cling upnp スタックのサンプル upnpBrowser に取り組んでおり、merdia サーバーのコンテンツを参照し、すべてのフォルダーにメディアのリストを表示できます。今、ビデオの URL を抽出して再生したいと考えています。プレーヤーですが、その URL を抽出する方法がブロックされています !!!

UDN serverUdn = ((UpnpControlApplication)getApplicationContext()).server_udn;
//Device server = ((UpnpControlApplication)getApplicationContext()).server;
Device server = upnpService.getRegistry().getDevice(serverUdn, true);
listAdapter.clear();
if(server == null)
{
    Toast.makeText(this, "pbm", Toast.LENGTH_LONG).show();
}
else
{
    if(server.findService(new UDAServiceType("ContentDirectory")) == null)
        Toast.makeText(this, "pbm", Toast.LENGTH_LONG).show();
    upnpService.getControlPoint().execute(new Browse(server.findService(new UDAServiceType("ContentDirectory")),id, BrowseFlag.DIRECT_CHILDREN)
    {
        @Override
        public void received(ActionInvocation actionInvocation, DIDLContent didl) {
            final List<Item> items = didl.getItems();
            String st=didl.getItems().get(0).getFirstResource().getValue();
4

2 に答える 2

1
public void browseServer(final String id)
{

    if(((UpnpControlApplication)getApplicationContext()).server_udn == null)
    {
        new AlertDialog.Builder(this)
        .setTitle("Bad")
        .setMessage("pas de serveur sélectionné, allez à la section LAN et cliquez sur Parcourir pour sélectionner le serveur!")
        .setPositiveButton("OK", new OnClickListener() {
            public void onClick(DialogInterface arg0, int arg1) {
                // Some stuff to do when ok got clicked
            }
        })
        .setNegativeButton("Annuler", new OnClickListener() {
            public void onClick(DialogInterface arg0, int arg1) {
                // Some stuff to do when cancel got clicked
            }
        })
        .show();
    }
    else
    {
        UDN serverUdn = ((UpnpControlApplication)getApplicationContext()).server_udn;
        //Device server = ((UpnpControlApplication)getApplicationContext()).server;
        Device server = upnpService.getRegistry().getDevice(serverUdn, true);
        listAdapter.clear();
        if(server == null)
        {
            Toast.makeText(this, "désolé", Toast.LENGTH_LONG).show();
        }
        else
        {
            if(server.findService(new UDAServiceType("ContentDirectory")) == null)
                Toast.makeText(this, "pbm", Toast.LENGTH_LONG).show();
            upnpService.getControlPoint().execute(new Browse(server.findService(new UDAServiceType("ContentDirectory")),id, BrowseFlag.DIRECT_CHILDREN)
            {

                @Override
                public void received(ActionInvocation actionInvocation, DIDLContent didl) {

                    final List<Item> items = didl.getItems();

                    //String st = items.getImportUri();
                    //String st=didl.getItems().get(0).getFirstResource().getValue(); 
                    //Log.d("URL IS",st); 
                    //Item item = didl.getItems().get(0);
                    //Item item = didl.getItems().get(0); 
                    //String url = item.getFirstResource().getValue();

                     //System.out.println(" this is the url of item" +item.getTitle()); 
                    // System.out.println(" this is the url of the media");

                     //System.out.println(url);

                    /*final DIDLContent b = didl;
                    String str1 = "bieda";
                    try
                    {
                        str1 = parser.generate(b);
                    }
                    catch(Exception e)
                    {
                        str1 = "smuta";
                    }
                    final String str=str1;
                    runOnUiThread(new Runnable()
                    {
                        public void run()
                        {

                            adb.setTitle("XML").setMessage(str).setPositiveButton("OK", new OnClickListener() {
                                public void onClick(DialogInterface arg0, int arg1) {
                                    // Some stuff to do when ok got clicked
                                }
                            }).show();

                        }
                    });*/

                    runOnUiThread(new Runnable(){
                        public void run()
                        {
                            listAdapter.insert(new ServerContentContainer(s.peek()), 0);
                        }
                    });

                    final List<Container> containers = didl.getContainers();

                    for(final Container c: containers)
                    {

                        runOnUiThread(new Runnable(){
                            public void run()
                            {
                                int pos = listAdapter.getPosition(new ServerContentContainer(c));
                                if(pos >= 0)
                                {
                                    listAdapter.remove(new ServerContentContainer(c));
                                    listAdapter.insert(new ServerContentContainer(c), pos);
                                    System.out.println("eulooooooooo");
                                }
                                else
                                    listAdapter.add(new ServerContentContainer(c));
                            }
                        });
                    }
                    for(final Item i: items)
                    {
                        runOnUiThread(new Runnable(){
                            public void run()
                            {
                                int pos = listAdapter.getPosition(new ServerContentItem(i));
                                if(pos >= 0)
                                {
                                    listAdapter.remove(new ServerContentItem(i));
                                    listAdapter.insert(new ServerContentItem(i), pos);
                                }
                                else
                                    listAdapter.add(new ServerContentItem(i));
                            }
                        });

                    }

                }

                @Override
                public void updateStatus(Status arg0) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void failure(ActionInvocation arg0, UpnpResponse arg1,
                        String arg2) {
                    // TODO Auto-generated method stub

                }

            });
        }
    }
}

これはクラス ServerContentItem です:

protected class ServerContentItem extends ServerContent
    {
        private Item i;

        public Item getItem()
        {
            return i;
        }

        ServerContentItem(Item i)
        {
            this.i = i;
        }

        public void select()
        {
            if(((UpnpControlApplication)getApplicationContext()).renderer_udn != null)
            {
                Device renderer = upnpService.getRegistry().getDevice(((UpnpControlApplication)getApplicationContext()).renderer_udn, false);
                final Service service = renderer.findService(new UDAServiceType("AVTransport"));
                upnpService.getControlPoint().execute(new SetAVTransportURI(service, i.getFirstResource().getValue()){
                    @Override
                    public void failure(ActionInvocation invocation, UpnpResponse operation, String defaultMsg) {
                        adb.setTitle("Bad").setMessage("No!")
                        .setPositiveButton("OK",new OnClickListener() {
                            public void onClick(DialogInterface arg0, int arg1) {
                                // Some stuff to do when ok got clicked
                            }
                        }).show();
                    }

                    @Override
                    public void success(ActionInvocation invocation)
                    {
                        upnpService.getControlPoint().execute(new Play(service){
                            @Override
                            public void failure(ActionInvocation invocation, UpnpResponse operation, String defaultMsg) {
                                adb.setTitle("Bad").setMessage("Non réussi!")
                                .setPositiveButton("OK",new OnClickListener() {
                                    public void onClick(DialogInterface arg0, int arg1) {
                                        // Some stuff to do when ok got clicked
                                    }
                                }).show();
                            }
                        });
                    }
                });

            }
            else
            {
                adb.setTitle("Bad")
                .setMessage("selection ! need a media player ")
                .setPositiveButton("OK",new OnClickListener() {
                    public void onClick(DialogInterface arg0, int arg1) {
                        // Some stuff to do when ok got clicked         
                        Log.e("bla","blablaa");


                        Intent intent = new Intent().setClass(BrowseServerActivity.this, Newactivity.class);
                        startActivity(intent);

                    }
                }).show();
            }
        }

        @Override
        public String toString()
        {
            return i.getTitle();
        }

        @Override 
        public boolean equals(Object o)
        {
            if(this == o)
                return true;
            if(getClass() != o.getClass())
                return false;
            return i.equals(((ServerContentItem)o).i);
        }
    }

コードが明確であることを願っています。どうも

于 2012-10-23T13:14:53.383 に答える