audio - Fetching MP3-Tags while recording a stream using java -


i have code, records (mp3-)stream:

public class recorder {     private static final int buffer_size = 2048;      private thread thread;     private boolean running = false;      public recorder(url stream, file dest) {         thread = new thread(() -> {             try {                 urlconnection connection = stream.openconnection();                 inputstream instream = connection.getinputstream();                  outputstream outstream = new fileoutputstream(dest);                 byte[] buffer = new byte[buffer_size];                 int length;                  system.out.println("now recording " + stream.tostring());                  while ((length = instream.read(buffer)) > 0 && running) {                     outstream.write(buffer, 0, length);                 }                  outstream.close();             } catch (ioexception e) {                 e.printstacktrace();             }         });     }      public void start() {         running = true;         thread.start();     }      public void stop() {         running = false;         try {             thread.join();         } catch (interruptedexception e) {             e.printstacktrace();         }     } } 

how read mp3-tags (song title , artist name) stream properly? i've found few answers on how fetch mp3-tags files, not streaming audio.

thanks.

you can use mp3agic library.

a java library reading mp3 files , reading / manipulating id3 tags (id3v1 , id3v2.2 through id3v2.4).

if file has id3 tags can do:

mp3file mp3file = new mp3file("src/test/resources/v1andv23tagswithalbumimage.mp3");  if (mp3file.hasid3v1tag()) {    id3v1 id3v1tag = mp3file.getid3v1tag();    system.out.println("track: "   + id3v1tag.gettrack());    system.out.println("artist: "  + id3v1tag.getartist());    system.out.println("title: "   + id3v1tag.gettitle());    system.out.println("album: "   + id3v1tag.getalbum());    system.out.println("year: "    + id3v1tag.getyear());    system.out.println("genre: "   + id3v1tag.getgenre() + " (" + id3v1tag.getgenredescription() + ")");    system.out.println("comment: " + id3v1tag.getcomment()); } 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -