| 1 |
unit Unit1; |
| 2 |
|
| 3 |
interface |
| 4 |
|
| 5 |
uses |
| 6 |
System.SysUtils, System.Types, System.UITypes, System.Classes, |
| 7 |
System.Variants, System.IOUtils, System.Math, |
| 8 |
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Media, |
| 9 |
System.Actions, FMX.ActnList, FMX.Layouts, FMX.ListBox, FMX.StdCtrls, |
| 10 |
FMX.ListView.Types, FMX.ListView; |
| 11 |
|
| 12 |
type |
| 13 |
TForm1 = class(TForm) |
| 14 |
MediaPlayer1: TMediaPlayer; |
| 15 |
ActionList1: TActionList; |
| 16 |
Action1: TAction; |
| 17 |
ListView1: TListView; |
| 18 |
Action3: TAction; |
| 19 |
SpeedButton1: TSpeedButton; |
| 20 |
SpeedButton2: TSpeedButton; |
| 21 |
SpeedButton3: TSpeedButton; |
| 22 |
Timer1: TTimer; |
| 23 |
TrackBar1: TTrackBar; |
| 24 |
TrackBar2: TTrackBar; |
| 25 |
SpeedButton4: TSpeedButton; |
| 26 |
SpeedButton5: TSpeedButton; |
| 27 |
SpeedButton6: TSpeedButton; |
| 28 |
Action4: TAction; |
| 29 |
Action5: TAction; |
| 30 |
Action6: TAction; |
| 31 |
StatusBar1: TStatusBar; |
| 32 |
ToolBar1: TToolBar; |
| 33 |
ToolBar2: TToolBar; |
| 34 |
procedure Action1Execute(Sender: TObject); |
| 35 |
procedure ListView1ItemClick(const Sender: TObject; |
| 36 |
const AItem: TListViewItem); |
| 37 |
procedure Action3Execute(Sender: TObject); |
| 38 |
procedure SpeedButton1Click(Sender: TObject); |
| 39 |
procedure FormShow(Sender: TObject); |
| 40 |
procedure FormDestroy(Sender: TObject); |
| 41 |
procedure Timer1Timer(Sender: TObject); |
| 42 |
procedure TrackBar1Change(Sender: TObject); |
| 43 |
procedure Action4Execute(Sender: TObject); |
| 44 |
procedure Action6Execute(Sender: TObject); |
| 45 |
procedure Action5Execute(Sender: TObject); |
| 46 |
procedure TrackBar2Change(Sender: TObject); |
| 47 |
procedure FormCreate(Sender: TObject); |
| 48 |
private |
| 49 |
{ private ���� } |
| 50 |
public |
| 51 |
{ public ���� } |
| 52 |
th: TThread; |
| 53 |
list: TStringList; |
| 54 |
procedure PlayMusic(Number: integer); |
| 55 |
procedure Id3Tag; |
| 56 |
end; |
| 57 |
|
| 58 |
var |
| 59 |
Form1: TForm1; |
| 60 |
|
| 61 |
implementation |
| 62 |
|
| 63 |
{$R *.fmx} |
| 64 |
{$R *.LgXhdpiTb.fmx ANDROID} |
| 65 |
|
| 66 |
uses Unit2, Unit3, Unit4, Mp3FileUtils; |
| 67 |
|
| 68 |
procedure TForm1.Action1Execute(Sender: TObject); |
| 69 |
begin |
| 70 |
if MediaPlayer1.State = TMediaState.Playing then |
| 71 |
MediaPlayer1.Stop; |
| 72 |
ListView1.ClearItems; |
| 73 |
Form3.Show; |
| 74 |
if th <> nil then |
| 75 |
begin |
| 76 |
th.Terminate; |
| 77 |
th.WaitFor; |
| 78 |
FreeAndNil(th); |
| 79 |
end; |
| 80 |
th := TSearchMP3.Create; |
| 81 |
end; |
| 82 |
|
| 83 |
procedure TForm1.Action3Execute(Sender: TObject); |
| 84 |
var |
| 85 |
s: TStringList; |
| 86 |
t: string; |
| 87 |
begin |
| 88 |
ListView1.ClearItems; |
| 89 |
list.LoadFromFile(TPath.GetHomePath + TPath.DirectorySeparatorChar + |
| 90 |
'Path.txt'); |
| 91 |
Id3Tag; |
| 92 |
end; |
| 93 |
|
| 94 |
procedure TForm1.Action4Execute(Sender: TObject); |
| 95 |
begin |
| 96 |
if MediaPlayer1.State = TMediaState.Playing then |
| 97 |
begin |
| 98 |
MediaPlayer1.Stop; |
| 99 |
Action4.Text := 'Play'; |
| 100 |
end |
| 101 |
else if ListView1.ItemCount > 0 then |
| 102 |
begin |
| 103 |
if ListView1.ItemIndex = -1 then |
| 104 |
PlayMusic(0) |
| 105 |
else |
| 106 |
begin |
| 107 |
MediaPlayer1.FileName := ListView1.Items[ListView1.ItemIndex].Detail; |
| 108 |
TrackBar2.Max := MediaPlayer1.Duration; |
| 109 |
MediaPlayer1.CurrentTime := Trunc(TrackBar2.Value); |
| 110 |
MediaPlayer1.Volume := TrackBar1.Value; |
| 111 |
MediaPlayer1.Play; |
| 112 |
end; |
| 113 |
MediaPlayer1.Play; |
| 114 |
Action4.Text := 'Stop'; |
| 115 |
end; |
| 116 |
end; |
| 117 |
|
| 118 |
procedure TForm1.Action5Execute(Sender: TObject); |
| 119 |
begin |
| 120 |
if MediaPlayer1.CurrentTime / (MediaTimeScale div 10000) < 5 then |
| 121 |
begin |
| 122 |
if ListView1.ItemIndex > 0 then |
| 123 |
PlayMusic(ListView1.ItemIndex - 1); |
| 124 |
end |
| 125 |
else |
| 126 |
begin |
| 127 |
MediaPlayer1.Stop; |
| 128 |
MediaPlayer1.CurrentTime := 0; |
| 129 |
TrackBar2.Value := 0; |
| 130 |
Action4.Text := 'Stop'; |
| 131 |
MediaPlayer1.Play; |
| 132 |
end; |
| 133 |
end; |
| 134 |
|
| 135 |
procedure TForm1.Action6Execute(Sender: TObject); |
| 136 |
var |
| 137 |
i: integer; |
| 138 |
begin |
| 139 |
if ListView1.ItemIndex < ListView1.ItemCount - 1 then |
| 140 |
begin |
| 141 |
i := ListView1.ItemIndex + 1; |
| 142 |
ListView1.ItemIndex := i; |
| 143 |
PlayMusic(i); |
| 144 |
end; |
| 145 |
end; |
| 146 |
|
| 147 |
procedure TForm1.FormCreate(Sender: TObject); |
| 148 |
begin |
| 149 |
list := TStringList.Create; |
| 150 |
end; |
| 151 |
|
| 152 |
procedure TForm1.FormDestroy(Sender: TObject); |
| 153 |
var |
| 154 |
i: integer; |
| 155 |
begin |
| 156 |
list.SaveToFile(TPath.GetHomePath + TPath.DirectorySeparatorChar + |
| 157 |
'Path.txt'); |
| 158 |
list.Free; |
| 159 |
if th <> nil then |
| 160 |
begin |
| 161 |
th.Terminate; |
| 162 |
th.WaitFor; |
| 163 |
th.Free; |
| 164 |
end; |
| 165 |
end; |
| 166 |
|
| 167 |
procedure TForm1.FormShow(Sender: TObject); |
| 168 |
begin |
| 169 |
if FileExists(TPath.GetHomePath + TPath.DirectorySeparatorChar + 'Path.txt') = true |
| 170 |
then |
| 171 |
Action3Execute(Sender) |
| 172 |
else |
| 173 |
Action1Execute(Sender); |
| 174 |
end; |
| 175 |
|
| 176 |
procedure TForm1.Id3Tag; |
| 177 |
var |
| 178 |
s: string; |
| 179 |
Id3v2Tag: TId3v2Tag; |
| 180 |
m: TMemoryStream; |
| 181 |
begin |
| 182 |
for s in list do |
| 183 |
begin |
| 184 |
Id3v2Tag := TId3v2Tag.Create; |
| 185 |
m := TMemoryStream.Create; |
| 186 |
try |
| 187 |
Id3v2Tag.ReadFromFile(s); |
| 188 |
Id3v2Tag.GetPicture(m, '*'); |
| 189 |
with ListView1.Items.Add do |
| 190 |
begin |
| 191 |
Bitmap.LoadFromStream(m); |
| 192 |
Text := Id3v2Tag.Title; |
| 193 |
Detail := s; |
| 194 |
end; |
| 195 |
finally |
| 196 |
Id3v2Tag.Free; |
| 197 |
m.Free; |
| 198 |
end; |
| 199 |
end; |
| 200 |
Form3.Hide; |
| 201 |
list.SaveToFile(TPath.GetHomePath + TPath.DirectorySeparatorChar + |
| 202 |
'Path.txt'); |
| 203 |
end; |
| 204 |
|
| 205 |
procedure TForm1.ListView1ItemClick(const Sender: TObject; |
| 206 |
const AItem: TListViewItem); |
| 207 |
begin |
| 208 |
if FileExists(ListView1.Items[ListView1.ItemIndex].Detail) = true then |
| 209 |
PlayMusic(ListView1.ItemIndex) |
| 210 |
else |
| 211 |
Action1Execute(Sender); |
| 212 |
end; |
| 213 |
|
| 214 |
procedure TForm1.PlayMusic(Number: integer); |
| 215 |
begin |
| 216 |
ListView1.ItemIndex := Number; |
| 217 |
MediaPlayer1.Stop; |
| 218 |
MediaPlayer1.Clear; |
| 219 |
MediaPlayer1.FileName := ListView1.Items[Number].Detail; |
| 220 |
TrackBar2.Max := MediaPlayer1.Duration; |
| 221 |
TrackBar2.Value := 0; |
| 222 |
Action4.Text := 'Stop'; |
| 223 |
MediaPlayer1.Volume := TrackBar1.Value; |
| 224 |
MediaPlayer1.Play; |
| 225 |
end; |
| 226 |
|
| 227 |
procedure TForm1.SpeedButton1Click(Sender: TObject); |
| 228 |
begin |
| 229 |
Form2.Show; |
| 230 |
end; |
| 231 |
|
| 232 |
procedure TForm1.Timer1Timer(Sender: TObject); |
| 233 |
begin |
| 234 |
if (ListView1.ItemIndex > -1) and |
| 235 |
((MediaPlayer1.Duration - MediaPlayer1.CurrentTime) / |
| 236 |
(MediaTimeScale div 10000) < 1) then |
| 237 |
begin |
| 238 |
if ListView1.ItemIndex < ListView1.Items.Count - 1 then |
| 239 |
PlayMusic(ListView1.ItemIndex + 1); |
| 240 |
end |
| 241 |
else if MediaPlayer1.State = TMediaState.Playing then |
| 242 |
TrackBar2.Value := MediaPlayer1.CurrentTime; |
| 243 |
end; |
| 244 |
|
| 245 |
procedure TForm1.TrackBar1Change(Sender: TObject); |
| 246 |
begin |
| 247 |
MediaPlayer1.Volume := TrackBar1.Value; |
| 248 |
end; |
| 249 |
|
| 250 |
procedure TForm1.TrackBar2Change(Sender: TObject); |
| 251 |
begin |
| 252 |
if Abs(TrackBar2.Value - MediaPlayer1.CurrentTime) > MediaTimeScale div 5000 |
| 253 |
then |
| 254 |
MediaPlayer1.CurrentTime := Trunc(TrackBar2.Value); |
| 255 |
end; |
| 256 |
|
| 257 |
end. |