如何使用get方法从Linked列表中获取元素

时间:2014-02-06 05:50:04

标签: java android parsing linked-list

我正在android中开发一个无线电流媒体应用程序,我的链表中有一个url,它是一个来自.pls文件链接的解析内容,我需要的是解析我需要获取的url中的内容使用get(position)方法从我的链表中的元素。可以在这里有任何建议我需要帮助。

以下是代码段,我想使用链接列表中的网址player=MediaPlayer.create(this,Uri.parse("//Url from linked list"));

我在链接列表中有来自.pls文件链接的解析网址,我只需要从链接列表中获取元素 链接列表对象

LinkedList<String> urls;

private LinkedList<String> fGetPlayableUrl( String mPls) {
        GetStreamingUrl oGetStreamingUrl = new GetStreamingUrl(MainActivity.this);
        urls=new LinkedList<String>();
        urls = oGetStreamingUrl.getStreamingUrl(mPls);


        return urls;
    }

private void initializeMediaPlayer() throws IOException {
        player = new MediaPlayer();


        //int i ;
       /* for (i=0;i<='\0';i++)
        {

        }*/
       //URL=urls.get(2).toString();
        try {
     player=MediaPlayer.create(this,Uri.parse("//url here"));

            player.setDataSource(URL);
            //player.prepareAsync();
            //player.start();

        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (IllegalStateException e) {
            e.printStackTrace();
        }

        player.setOnBufferingUpdateListener(new OnBufferingUpdateListener() {

            public void onBufferingUpdate(MediaPlayer mp, int percent) {
                playSeekBar.setSecondaryProgress(percent);
                Log.i("Buffering", "" + percent);
            }
        });
    }

1 个答案:

答案 0 :(得分:0)

为什么不尝试将player=MediaPlayer.create(this,Uri.parse("//url here"));放入链接列表的循环中,如下所示:

  LinkedList<String> urls;



     // Just make this method void. 
     //Anyways your LinkedList is still accessible globally 
     //and you are instantiating your linkedlist inside this method;
    private void fGetPlayableUrl( String mPls) {
            GetStreamingUrl oGetStreamingUrl = new GetStreamingUrl(MainActivity.this);
            urls=new LinkedList<String>();
            urls = oGetStreamingUrl.getStreamingUrl(mPls);
        }

    private void initializeMediaPlayer() throws IOException {
            player = new MediaPlayer();


            //int i ;
           /* for (i=0;i<='\0';i++)
            {

            }*/
           //URL=urls.get(2).toString();

    fGetPlayableUrl(url String here);

         for(String url:urls){
             try {

         player=MediaPlayer.create(this,Uri.parse(url));

                player.setDataSource(URL);
                //player.prepareAsync();
                //player.start();

            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            } catch (IllegalStateException e) {
                e.printStackTrace();
            }

            player.setOnBufferingUpdateListener(new OnBufferingUpdateListener() {

                public void onBufferingUpdate(MediaPlayer mp, int percent) {
                    playSeekBar.setSecondaryProgress(percent);
                    Log.i("Buffering", "" + percent);
                }
            });
        }


        }