0

我最近在做一个 ShoutCast 广播项目。通过使用streamscrapper 库,我可以获得当前歌曲名称和当前艺术家。这是问题所在。一旦我打开应用程序,它会获取歌曲名称和艺术家姓名,但是从那以后它不会更新它。我试图用计时器来做,但无法弄清楚。

这是我获取当前歌曲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();
    }
}
4

2 回答 2

0

也许像一个可运行的东西:

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);
    }
};

在您离开之前,请确保停止任务:

handler.removeCallbacksAndMessages(null);
于 2013-07-22T10:45:44.600 回答
0

使用 aHandler更新它,

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);
于 2013-07-22T10:45:58.810 回答