Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package techmultlab01;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- public class Mp3Reader_ID3 {
- String path = "C:\\Users\\User\\Documents\\mp3ToCheck.mp3";
- public void readOneByte() throws FileNotFoundException {
- FileInputStream file = null;
- int headerFounderT, headerFounderA, headerFounderG, fakeChar, founder, genre = 0;
- boolean headerFound = false;
- String title = "";
- String artist = "";
- String album = "";
- String year = "";
- String comments = "";
- try {
- file = new FileInputStream(path);
- // dopóki nie znajdzie nagłówka szuka dalej
- while(!headerFound) {
- headerFounderT = file.read(); // szukanie po bajcie
- if (headerFounderT == 84) { // jeżeli zmienna jest równa "T" to wchodzi w ifa
- headerFounderA = file.read(); // interesuje nas kolejny bajt, więc szukamy raz jeszcze i przechodzimy do kolejnego
- if (headerFounderA == 65) { // jeżeli zmienna jest równa "A" to wchodzi w ifa
- headerFounderG = file.read();
- if(headerFounderG == 71) { // jeżeli zmienna jest równa "G" to wchodzi w ifa
- fakeChar = file.read();
- if(fakeChar != 20) { // jeżeli zmienna nie jest równa jakiemuś gównoznakowi to wchodzi w ifa
- // musi znalezć kolejną ramkę po tej fałszywej
- founder = fakeChar;
- headerFound = true;
- for (int i = 0; i < 30; i++) { // pole "tytuł" ma wielkość 30 znaków
- title += (char)founder; // dodaję do zmiennej "title" kolejne znaki, a następnie wypisuję to na ekran
- founder = file.read();
- }
- System.out.println("Tytuł piosenki: " + title.trim());
- for (int i = 0; i < 30; i++) {
- artist += (char)founder;
- founder = file.read();
- }
- System.out.println("Wykonawca: " + artist.trim());
- for (int i = 0; i < 30; i++) {
- album += (char)founder;
- founder = file.read();
- }
- System.out.println("Album: " + album.trim());
- for (int i = 0; i < 4; i++) {
- year += (char)founder;
- founder = file.read();
- }
- System.out.println("Rok: " + year);
- for (int i = 0; i < 30; i++) { // w tej pętli zaczytywany jest o jeden bajt za dużo, ale przyda się
- comments += (char)founder;
- founder = file.read(); // ostatni zaczytany w pętli bajt jest już ostatnim w pliku i jest to gatunek
- }
- System.out.println("Komentarz: " + comments.trim());
- genre = founder;
- System.out.println("Gatunek: " + genre);
- }
- }
- }
- }
- }
- } catch (FileNotFoundException f) {
- throw f;
- } catch (IOException i) {
- i.printStackTrace();
- } finally {
- try {
- if (file != null) {
- file.close();
- }
- } catch (IOException e) {
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement