Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.27 KB | None | 0 0
  1. package techmultlab01;
  2.  
  3. import java.io.FileInputStream;
  4. import java.io.FileNotFoundException;
  5. import java.io.IOException;
  6.  
  7. public class Mp3Reader_ID3 {
  8.    
  9.     String path = "C:\\Users\\User\\Documents\\mp3ToCheck.mp3";
  10.    
  11.     public void readOneByte() throws FileNotFoundException {
  12.         FileInputStream file = null;
  13.         int headerFounderT, headerFounderA, headerFounderG, fakeChar, founder, genre = 0;
  14.         boolean headerFound = false;
  15.         String title = "";
  16.         String artist = "";
  17.         String album = "";
  18.         String year = "";
  19.         String comments = "";
  20.        
  21.         try {
  22.           file = new FileInputStream(path);
  23.          
  24.           // dopóki nie znajdzie nagłówka szuka dalej
  25.           while(!headerFound) {
  26.               headerFounderT = file.read(); // szukanie po bajcie
  27.               if (headerFounderT == 84) { // jeżeli zmienna jest równa "T" to wchodzi w ifa
  28.                   headerFounderA = file.read(); // interesuje nas kolejny bajt, więc szukamy raz jeszcze i przechodzimy do kolejnego
  29.                   if (headerFounderA == 65) { // jeżeli zmienna jest równa "A" to wchodzi w ifa
  30.                       headerFounderG = file.read();
  31.                       if(headerFounderG == 71) { // jeżeli zmienna jest równa "G" to wchodzi w ifa
  32.                           fakeChar = file.read();
  33.                           if(fakeChar != 20) { // jeżeli zmienna nie jest równa jakiemuś gównoznakowi to wchodzi w ifa
  34.                               // musi znalezć kolejną ramkę po tej fałszywej
  35.                               founder = fakeChar;
  36.                               headerFound = true;
  37.                              
  38.                               for (int i = 0; i < 30; i++) { // pole "tytuł" ma wielkość 30 znaków
  39.                                   title += (char)founder; // dodaję do zmiennej "title" kolejne znaki, a następnie wypisuję to na ekran
  40.                                   founder = file.read();
  41.                               }
  42.                          
  43.                           System.out.println("Tytuł piosenki: " + title.trim());
  44.                          
  45.                           for (int i = 0; i < 30; i++) {
  46.                               artist += (char)founder;
  47.                               founder = file.read();
  48.                           }
  49.                          
  50.                           System.out.println("Wykonawca: " + artist.trim());
  51.                          
  52.                           for (int i = 0; i < 30; i++) {
  53.                               album += (char)founder;
  54.                               founder = file.read();
  55.                           }
  56.                          
  57.                           System.out.println("Album: " + album.trim());
  58.                          
  59.                           for (int i = 0; i < 4; i++) {
  60.                               year += (char)founder;
  61.                               founder = file.read();
  62.                           }
  63.                          
  64.                           System.out.println("Rok: " + year);
  65.                          
  66.                           for (int i = 0; i < 30; i++) { // w tej pętli zaczytywany jest o jeden bajt za dużo, ale przyda się
  67.                               comments += (char)founder;
  68.                               founder = file.read(); // ostatni zaczytany w pętli bajt jest już ostatnim w pliku i jest to gatunek
  69.                           }
  70.                          
  71.                           System.out.println("Komentarz: " + comments.trim());
  72.                          
  73.                           genre = founder;
  74.                           System.out.println("Gatunek: " + genre);
  75.                          
  76.                          
  77.                           }
  78.                       }
  79.                   }
  80.               }
  81.           }
  82.                          
  83.         } catch (FileNotFoundException f) {
  84.           throw f;
  85.         } catch (IOException i) {
  86.           i.printStackTrace();
  87.         } finally {
  88.           try {
  89.             if (file != null) {
  90.               file.close();
  91.             }
  92.           } catch (IOException e) {
  93.           }
  94.         }
  95.       }
  96.    
  97.    
  98.  
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement