forked from HemulGM/Strato
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStrato.AudioData.pas
More file actions
105 lines (84 loc) · 2.33 KB
/
Strato.AudioData.pas
File metadata and controls
105 lines (84 loc) · 2.33 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
unit Strato.AudioData;
interface
uses
System.SysUtils, FMX.Graphics, ID3v2Library;
type
TAudioData = record
FileName: string;
Title: string;
Artist: string;
Album: string;
BitRate: string;
Year: string;
Number: string;
Genre: string;
Duration: Int64;
Cover: TBitmap;
end;
function GetAudioData(const FileName: string): TAudioData;
implementation
uses
System.Classes;
function GetAudioData(const FileName: string): TAudioData;
begin
var ID3v2Tag := TID3v2Tag.Create;
try
//* Load the ID3v2 Tag
var Error := ID3v2Tag.LoadFromFile(FileName);
if Error <> ID3V2LIBRARY_SUCCESS then
begin
raise Exception.Create('Error loading ID3v2 tag, error code: ' + IntToStr(Error) + #13#10 + ID3v2TagErrorCode2String(Error));
end;
ID3v2Tag.DeCompressAllFrames;
Result.FileName := FileName;
Result.Cover := nil;
//* Playtime
Result.Duration := Trunc(ID3v2Tag.PlayTime);
//* Bit rate
if ID3v2Tag.MPEGInfo.VBR then
Result.BitRate := 'VBR'
else
Result.BitRate := IntToStr(ID3v2Tag.BitRate) + ' kbps';
//* Get Title
Result.Title := ID3v2Tag.GetText('TIT2');
//* Get Artist
Result.Artist := ID3v2Tag.GetText('TPE1');
//* Get Album
Result.Album := ID3v2Tag.GetText('TALB');
//* Get Year
Result.Year := ID3v2Tag.GetText('TYER');
//* Get track no.
Result.Number := ID3v2Tag.GetText('TRCK');
//* Get Genre
Result.Genre := ID3v2DecodeGenre(ID3v2Tag.GetText('TCON'));
//* Load first cover picture
var PictureStream := TMemoryStream.Create;
try
var Index := ID3v2Tag.FrameExists('APIC');
if Index >= 0 then
begin
var PictureType: Integer;
var Success: Boolean;
var MIMEType: string;
var Description: string;
Success := ID3v2Tag.GetCoverPictureStream(Index, PictureStream, MIMEType, Description, PictureType);
//* APIC picture found
if Success and (PictureStream.Size > 0) then
begin
var Bitmap := TBitmap.Create;
try
Bitmap.LoadFromStream(PictureStream);
Result.Cover := Bitmap.CreateThumbnail(126, 126);
finally
Bitmap.Free;
end;
end;
end;
finally
PictureStream.Free;
end;
finally
ID3v2Tag.Free;
end;
end;
end.