Develop and Download Open Source Software

Browse Subversion Repository

Contents of /Unit1.pas

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5 - (show annotations) (download) (as text)
Sat Aug 1 00:50:22 2015 UTC (8 years, 7 months ago) by yamat0jp
File MIME type: text/x-pascal
File size: 6365 byte(s)
文鎮化ではありませんでした

とりあえずTrackBar2周辺を書き換えておきました
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.Play;
137 end;
138 MediaPlayer1.Play;
139 Action4.Text := 'Stop';
140 end;
141 end;
142
143 procedure TForm1.Action5Execute(Sender: TObject);
144 begin
145 if MediaPlayer1.CurrentTime < MediaTimeScale div 10000 then
146 if ListView1.ItemCount > 0 then
147 PlayMusic(ListView1.ItemIndex - 1)
148 else
149 begin
150 MediaPlayer1.Stop;
151 MediaPlayer1.CurrentTime := 0;
152 TrackBar2.Value := 0;
153 Action4.Text := 'Play';
154 end;
155 end;
156
157 procedure TForm1.Action6Execute(Sender: TObject);
158 var
159 i: integer;
160 begin
161 if ListView1.ItemIndex < ListView1.ItemCount - 1 then
162 begin
163 i := ListView1.ItemIndex + 1;
164 ListView1.ItemIndex := i;
165 PlayMusic(i);
166 end;
167 end;
168
169 procedure TForm1.FormDestroy(Sender: TObject);
170 begin
171 Action2Execute(Sender);
172 if th <> nil then
173 begin
174 th.Terminate;
175 th.WaitFor;
176 th.Free;
177 end;
178 end;
179
180 procedure TForm1.FormShow(Sender: TObject);
181 begin
182 if FileExists(TPath.GetHomePath + TPath.DirectorySeparatorChar + 'Path.txt') = true
183 then
184 Action3Execute(Sender)
185 else
186 Action1Execute(Sender);
187 end;
188
189 procedure TForm1.ListView1ItemClick(const Sender: TObject;
190 const AItem: TListViewItem);
191 begin
192 with MediaPlayer1 do
193 begin
194 if State = TMediaState.Playing then
195 Stop;
196 Clear;
197 if FileExists(AItem.Detail) = true then
198 FileName := AItem.Detail
199 else
200 begin
201 Action1Execute(Sender);
202 Exit;
203 end;
204 PlayMusic(ListView1.ItemIndex);
205 end;
206 end;
207
208 procedure TForm1.PlayMusic(Number: integer);
209 begin
210 ListView1.ItemIndex := Number;
211 MediaPlayer1.FileName := ListView1.Items[Number].Detail;
212 TrackBar2.Max := MediaPlayer1.Duration;
213 TrackBar2.Value := 0;
214 Action4.Text := 'Stop';
215 MediaPlayer1.Play;
216 end;
217
218 procedure TForm1.SpeedButton1Click(Sender: TObject);
219 begin
220 Form2.Show;
221 end;
222
223 procedure TForm1.Timer1Timer(Sender: TObject);
224 begin
225 if (ListView1.ItemIndex > -1) and
226 (Trunc(10000 * MediaPlayer1.Duration / MediaTimeScale) <=
227 Ceil(10000 * MediaPlayer1.CurrentTime / MediaTimeScale)) then
228 begin
229 if ListView1.ItemIndex < ListView1.Items.Count - 1 then
230 begin
231 ListView1.ItemIndex := ListView1.ItemIndex + 1;
232 with MediaPlayer1 do
233 begin
234 Stop;
235 Clear;
236 FileName := ListView1.Items[ListView1.ItemIndex].Detail;
237 Volume := TrackBar1.Value;
238 Play;
239 end;
240 end;
241 end;
242 if MediaPlayer1.State = TMediaState.Playing then
243 TrackBar2.Value := MediaPlayer1.CurrentTime;
244 end;
245
246 procedure TForm1.TrackBar1Change(Sender: TObject);
247 begin
248 MediaPlayer1.Volume := TrackBar1.Value;
249 end;
250
251 procedure TForm1.TrackBar2Change(Sender: TObject);
252 var
253 i: extended;
254 begin
255 if MediaPlayer1.CurrentTime - TrackBar1.Value > MediaTimeScale div 1500 then
256 MediaPlayer1.CurrentTime := Trunc(TrackBar2.Value);
257 end;
258
259 end.

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