如何获取特定 URL 中音频文件的 ID3Tags 信息?
Posted
技术标签:
【中文标题】如何获取特定 URL 中音频文件的 ID3Tags 信息?【英文标题】:How to get ID3Tags information of a audio file in a specific URL? 【发布时间】:2015-01-22 07:03:50 【问题描述】:我正在尝试从特定 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?
【问题讨论】:
【参考方案1】:您可以将其写入本地的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
【讨论】:
以上是关于如何获取特定 URL 中音频文件的 ID3Tags 信息?的主要内容,如果未能解决你的问题,请参考以下文章