-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathgetInfo.java
More file actions
70 lines (61 loc) · 2.09 KB
/
getInfo.java
File metadata and controls
70 lines (61 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import org.jaudiotagger.audio.exceptions.InvalidAudioFrameException;
import org.jaudiotagger.audio.exceptions.ReadOnlyFileException;
import org.jaudiotagger.audio.mp3.MP3AudioHeader;
import org.jaudiotagger.audio.mp3.MP3File;
import org.jaudiotagger.tag.FieldKey;
import org.jaudiotagger.tag.Tag;
import org.jaudiotagger.tag.TagException;
import org.jaudiotagger.tag.id3.AbstractID3v2Frame;
import org.jaudiotagger.tag.id3.AbstractID3v2Tag;
import org.jaudiotagger.tag.id3.framebody.FrameBodyAPIC;
public class getInfo {
MP3File mp3file;
String title, artist, album, year;
long time = 0 ;
public MP3File getMp3file() {
return mp3file;
}
public String getTitle() {
return title;
}
public String getArtist() {
return artist;
}
public String getAlbum() {
return album;
}
public String getYear() {
return year;
}
public long getTime(){
return time ;
}
public getInfo(File file) throws IOException, TagException,
ReadOnlyFileException, InvalidAudioFrameException {
mp3file = new MP3File(file);
Tag tag = mp3file.getTag();
artist = tag.getFirst(FieldKey.ARTIST);
album = tag.getFirst(FieldKey.ALBUM);
year = tag.getFirst(FieldKey.YEAR);
title = tag.getFirst(FieldKey.TITLE);
MP3AudioHeader audioHeader = (MP3AudioHeader)mp3file.getAudioHeader();
time = audioHeader.getTrackLength();
AbstractID3v2Tag tagid3v2 = mp3file.getID3v2Tag();
AbstractID3v2Frame frame = (AbstractID3v2Frame) tagid3v2.getFrame("APIC");
FrameBodyAPIC body = (FrameBodyAPIC) frame.getBody();
byte[] imageData = body.getImageData();
FileOutputStream fos = new FileOutputStream("drawable/picture/"+title+".jpg");
fos.write(imageData);
fos.close();
}
// public static void main(String[] args) throws IOException, TagException, ReadOnlyFileException, InvalidAudioFrameException {
// getInfo getinfo = new getInfo(new File("2.mp3")) ;
// System.out.println(getinfo.getTitle());
// System.out.println(getinfo.getArtist());
// System.out.println(getinfo.getAlbum());
// System.out.println(getinfo.getYear());
// }
}