0

I'm recently working on a ShoutCast radio project. By using streamscrapper library I'm able to get the current song name and the current artist. Here is the problem. Once I open the app, it gets the song name and the artist name, however since then it does not update it. I tried to do it with timer but couldn't figure out.

And here is the method which I get the current song id:

private void initializeMediaPlayer() {

    player = new AACPlayer();
    scraper = new ShoutCastScraper();
    try {
        streams = scraper.scrape(new URI("http://sunucu2.radyolarburada.com:5000/"));
        String str = "asd";
        for (Stream stream: streams) {
            str = stream.getCurrentSong();
            currPlayView.setText("Now Playing: " + str);
        }
    } catch (ScrapeException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (URISyntaxException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Vipul
  • 27,808
  • 7
  • 60
  • 75
user2604150
  • 379
  • 5
  • 18

2 Answers2

0

Maybe something like a runnable:

private Handler handler = new Handler();

handler.postAtTime(timeTask, SystemClock.uptimeMillis() + 500);

private Runnable timeTask = new Runnable() {
    public void run() {
        //do stuff here

        //do it again soon
        handler.postAtTime(timeTask, SystemClock.uptimeMillis() + 500);
    }
};

Before you leave make sure to stop the tasks:

handler.removeCallbacksAndMessages(null);
Scott Helme
  • 4,786
  • 2
  • 23
  • 35
0

use a Handler to update it ,

Handler handler=new Handler();
int FREQ=5000; // the update frequency
handler.postDelayed(new Runnable()
        {
            public void run() 
            {                                 
                try 
                {
                      String currStr;     // get your next song name
                      currPlayView.setText(currStr);    
                } 
                finally 
                {
                    handler.postDelayed(this, FREQ);
                }
            }
        }, FREQ);
Onur A.
  • 3,007
  • 3
  • 22
  • 37