Develop and Download Open Source Software

Browse Subversion Repository

Contents of /Unit1.pas

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6 - (show annotations) (download) (as text)
Sat Aug 1 04:45:13 2015 UTC (8 years, 7 months ago) by yamat0jp
File MIME type: text/x-pascal
File size: 6426 byte(s)
数々の間違いを訂正
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 Action2: TAction;
19 Action3: TAction;
20 Panel1: TPanel;
21 SpeedButton1: TSpeedButton;
22 SpeedButton2: TSpeedButton;
23 ToolBar1: TToolBar;
24 SpeedButton3: TSpeedButton;
25 Timer1: TTimer;
26 ToolBar2: TToolBar;
27 TrackBar1: TTrackBar;
28 TrackBar2: TTrackBar;
29 SpeedButton4: TSpeedButton;
30 SpeedButton5: TSpeedButton;
31 SpeedButton6: TSpeedButton;
32 Action4: TAction;
33 Action5: TAction;
34 Action6: TAction;
35 StatusBar1: TStatusBar;
36 procedure Action1Execute(Sender: TObject);
37 procedure ListView1ItemClick(const Sender: TObject;
38 const AItem: TListViewItem);
39 procedure Action2Execute(Sender: TObject);
40 procedure Action3Execute(Sender: TObject);
41 procedure SpeedButton1Click(Sender: TObject);
42 procedure FormShow(Sender: TObject);
43 procedure FormDestroy(Sender: TObject);
44 procedure Timer1Timer(Sender: TObject);
45 procedure TrackBar1Change(Sender: TObject);
46 procedure Action4Execute(Sender: TObject);
47 procedure Action6Execute(Sender: TObject);
48 procedure Action5Execute(Sender: TObject);
49 procedure TrackBar2Change(Sender: TObject);
50 private
51 { private ���� }
52 public
53 { public ���� }
54 th: TThread;
55 procedure PlayMusic(Number: integer);
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;
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.Action2Execute(Sender: TObject);
84 var
85 s: TStringList;
86 t: TListViewItem;
87 begin
88 s := TStringList.Create;
89 try
90 for t in ListView1.Items do
91 s.Add(t.Detail);
92 s.SaveToFile(TPath.GetHomePath + TPath.DirectorySeparatorChar + 'Path.txt');
93 finally
94 s.Free;
95 end;
96 end;
97
98 procedure TForm1.Action3Execute(Sender: TObject);
99 var
100 s: TStringList;
101 t: string;
102 begin
103 ListView1.ClearItems;
104 s := TStringList.Create;
105 try
106 s.LoadFromFile(TPath.GetHomePath + TPath.DirectorySeparatorChar +
107 'Path.txt');
108 for t in s do
109 if FileExists(t) = true then
110 with ListView1.Items.Add do
111 begin
112 Detail := t;
113 Text := ExtractFileName(t);
114 end;
115 finally
116 s.Free;
117 end;
118 end;
119
120 procedure TForm1.Action4Execute(Sender: TObject);
121 begin
122 if MediaPlayer1.State = TMediaState.Playing then
123 begin
124 MediaPlayer1.Stop;
125 Action4.Text := 'Play';
126 end
127 else if ListView1.ItemCount > 0 then
128 begin
129 if ListView1.ItemIndex = -1 then
130 PlayMusic(0)
131 else
132 begin
133 MediaPlayer1.FileName := ListView1.Items[ListView1.ItemIndex].Detail;
134 TrackBar2.Max := MediaPlayer1.Duration;
135 MediaPlayer1.CurrentTime := Trunc(TrackBar2.Value);
136 MediaPlayer1.Volume:=TrackBar1.Value;
137 MediaPlayer1.Play;
138 end;
139 MediaPlayer1.Play;
140 Action4.Text := 'Stop';
141 end;
142 end;
143
144 procedure TForm1.Action5Execute(Sender: TObject);
145 begin
146 if MediaPlayer1.CurrentTime / (MediaTimeScale div 10000) < 5 then
147 begin
148 if ListView1.ItemIndex > 0 then
149 PlayMusic(ListView1.ItemIndex - 1);
150 end
151 else
152 begin
153 MediaPlayer1.Stop;
154 MediaPlayer1.CurrentTime := 0;
155 TrackBar2.Value := 0;
156 Action4.Text := 'Play';
157 end;
158 end;
159
160 procedure TForm1.Action6Execute(Sender: TObject);
161 var
162 i: integer;
163 begin
164 if ListView1.ItemIndex < ListView1.ItemCount - 1 then
165 begin
166 i := ListView1.ItemIndex + 1;
167 ListView1.ItemIndex := i;
168 PlayMusic(i);
169 end;
170 end;
171
172 procedure TForm1.FormDestroy(Sender: TObject);
173 begin
174 Action2Execute(Sender);
175 if th <> nil then
176 begin
177 th.Terminate;
178 th.WaitFor;
179 th.Free;
180 end;
181 end;
182
183 procedure TForm1.FormShow(Sender: TObject);
184 begin
185 if FileExists(TPath.GetHomePath + TPath.DirectorySeparatorChar + 'Path.txt') = true
186 then
187 Action3Execute(Sender)
188 else
189 Action1Execute(Sender);
190 end;
191
192 procedure TForm1.ListView1ItemClick(const Sender: TObject;
193 const AItem: TListViewItem);
194 begin
195 with MediaPlayer1 do
196 begin
197 if State = TMediaState.Playing then
198 Stop;
199 Clear;
200 if FileExists(AItem.Detail) = true then
201 FileName := AItem.Detail
202 else
203 begin
204 Action1Execute(Sender);
205 Exit;
206 end;
207 PlayMusic(ListView1.ItemIndex);
208 end;
209 end;
210
211 procedure TForm1.PlayMusic(Number: integer);
212 begin
213 ListView1.ItemIndex := Number;
214 MediaPlayer1.FileName := ListView1.Items[Number].Detail;
215 TrackBar2.Max := MediaPlayer1.Duration;
216 TrackBar2.Value := 0;
217 Action4.Text := 'Stop';
218 MediaPlayer1.Volume := TrackBar1.Value;
219 MediaPlayer1.Play;
220 end;
221
222 procedure TForm1.SpeedButton1Click(Sender: TObject);
223 begin
224 Form2.Show;
225 end;
226
227 procedure TForm1.Timer1Timer(Sender: TObject);
228 begin
229 if (ListView1.ItemIndex > -1) and
230 (Trunc(10000 * MediaPlayer1.Duration / MediaTimeScale) <=
231 Ceil(10000 * MediaPlayer1.CurrentTime / MediaTimeScale)) then
232 begin
233 if ListView1.ItemIndex < ListView1.Items.Count - 1 then
234 begin
235 ListView1.ItemIndex := ListView1.ItemIndex + 1;
236 with MediaPlayer1 do
237 begin
238 Stop;
239 Clear;
240 FileName := ListView1.Items[ListView1.ItemIndex].Detail;
241 Volume := TrackBar1.Value;
242 Play;
243 end;
244 end;
245 end;
246 if MediaPlayer1.State = TMediaState.Playing then
247 TrackBar2.Value := MediaPlayer1.CurrentTime;
248 end;
249
250 procedure TForm1.TrackBar1Change(Sender: TObject);
251 begin
252 MediaPlayer1.Volume := TrackBar1.Value;
253 end;
254
255 procedure TForm1.TrackBar2Change(Sender: TObject);
256 begin
257 if Abs(TrackBar2.Value - MediaPlayer1.CurrentTime) > 200 then
258 MediaPlayer1.CurrentTime := Trunc(TrackBar2.Value);
259 end;
260
261 end.

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26