Android Studio:如何使用streamscraper来获取shoutcast元数据

问题描述 投票:0回答:1

我是Android开发的新手。我想从Shoutcast Server获取元数据,并发现streamscraper是最容易使用的。但我的问题是,我不知道如何使用它。主页本身只显示如何使用它:

import java.net.URI;
import java.util.List;
import net.moraleboost.streamscraper.Stream;
import net.moraleboost.streamscraper.Scraper;
import net.moraleboost.streamscraper.scraper.IceCastScraper;

    public class Harvester {
     public static void main(String[] args) throws Exception {
      Scraper scraper = new IceCastScraper();
      List streams = scraper.scrape(new URI("http://host:port/"));
      for (Stream stream: streams) {
       System.out.println("Song Title: " + stream.getCurrentSong());
       System.out.println("URI: " + stream.getUri());
      }
     }
    }

在任何地方搜索,没有找到如何使用它的项目样本。我希望你们中的一个人可以发布如何使用它的代码,或者为它做一个教程。

android audio-streaming shoutcast icecast internet-radio
1个回答
-2
投票

无需使用外部库。以下页面为您提供:

Current song:     http://yourstream:port/currentsong?sid=#
Last 20 songs:    http://yourstream:port/played.html?sid#
Next songs:       http://yourstream:port/nextsongs?sid=#

打印当前歌曲的Android java类:

import java.io.BufferedReader;
import java.io.InputStreamReader;    
import java.net.URL;

public class NowPlaying {

    public void CurrentSong() {

        try
        {
            URL url = new URL("http://www.mofosounds.com:8000/currentsong?sid=#");
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));

            String inputLine;

            while ((inputLine = in.readLine()) != null)
                System.out.println(inputLine);

            in.close();
        }
        catch(Exception e)
        {
            System.out.println(e.toString());
        }
    }
}

注意:流的播放器必须支持nextsongs?sid=#feature。

© www.soinside.com 2019 - 2024. All rights reserved.