0

我正在尝试从特定 URL 中的音频文件中获取 ID3Tag 信息,经过此主题后,我找到了以下代码,它有助于从 mp3 文件中检索 ID3Tag 信息。但我的问题是我需要如何应用以下代码,该代码将从特定 URL 返回 ID3Tag 信息。

Mp3File mp3file = new Mp3File("SomeMp3File.mp3");
if (mp3file.hasId3v2Tag()) {
  ID3v2 id3v2Tag = mp3file.getId3v2Tag();
  System.out.println("Track: " + id3v2Tag.getTrack());
  System.out.println("Artist: " + id3v2Tag.getArtist());
  System.out.println("Title: " + id3v2Tag.getTitle());
  System.out.println("Album: " + id3v2Tag.getAlbum());
  System.out.println("Year: " + id3v2Tag.getYear());
  System.out.println("Genre: " + id3v2Tag.getGenre() + " (" + id3v2Tag.getGenreDescription() + ")");
  System.out.println("Comment: " + id3v2Tag.getComment());
  System.out.println("Composer: " + id3v2Tag.getComposer());
  System.out.println("Publisher: " + id3v2Tag.getPublisher());
  System.out.println("Original artist: " + id3v2Tag.getOriginalArtist());
  System.out.println("Album artist: " + id3v2Tag.getAlbumArtist());
  System.out.println("Copyright: " + id3v2Tag.getCopyright());
  System.out.println("URL: " + id3v2Tag.getUrl());
  System.out.println("Encoder: " + id3v2Tag.getEncoder());
  byte[] albumImageData = id3v2Tag.getAlbumImage();
  if (albumImageData != null) {
    System.out.println("Have album image data, length: " + albumImageData.length + " bytes");
    System.out.println("Album image mime type: " + id3v2Tag.getAlbumImageMimeType());
  }
}

但我的问题是我需要如何应用以下代码,该代码将从特定 URL 返回 ID3Tag 信息:http://podcastdownload.npr.org/anon.npr-podcasts/podcast/510184/223365607/npr_223365607.mp3?_kip_ipx =1453569924-1421846382 ?

4

1 回答 1

0

您可以将其写入本地的 mp3 文件,然后阅读它,希望此代码对您有所帮助

    URLConnection conn = new URL("http://podcastdownload.npr.org/anon.npr-podcasts/podcast/510184/223365607/npr_223365607.mp3").openConnection();
    InputStream is = conn.getInputStream();
    OutputStream outstream = new FileOutputStream(new File("D:/tmp/SomeMp3File.mp3"));
    byte[] buffer = new byte[4096];
    int len;
    while ((len = is.read(buffer)) > 0) {
        outstream.write(buffer, 0, len);
    }
    outstream.close();
    Mp3File mp3file = new Mp3File("SomeMp3File.mp3");
//and your reading code follows
于 2015-01-22T07:15:55.690 回答