Develop and Download Open Source Software

Browse Subversion Repository

Diff of /Unit1.pas

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2 by yamat0jp, Tue Jul 28 08:41:38 2015 UTC revision 7 by yamat0jp, Sat Aug 15 03:06:09 2015 UTC
# Line 15  type Line 15  type
15      ActionList1: TActionList;      ActionList1: TActionList;
16      Action1: TAction;      Action1: TAction;
17      ListView1: TListView;      ListView1: TListView;
     Action2: TAction;  
18      Action3: TAction;      Action3: TAction;
     Panel1: TPanel;  
19      SpeedButton1: TSpeedButton;      SpeedButton1: TSpeedButton;
20      SpeedButton2: TSpeedButton;      SpeedButton2: TSpeedButton;
     ToolBar1: TToolBar;  
21      SpeedButton3: TSpeedButton;      SpeedButton3: TSpeedButton;
22      Timer1: TTimer;      Timer1: TTimer;
     ToolBar2: TToolBar;  
23      TrackBar1: TTrackBar;      TrackBar1: TTrackBar;
24      TrackBar2: TTrackBar;      TrackBar2: TTrackBar;
25      SpeedButton4: TSpeedButton;      SpeedButton4: TSpeedButton;
# Line 33  type Line 29  type
29      Action5: TAction;      Action5: TAction;
30      Action6: TAction;      Action6: TAction;
31      StatusBar1: TStatusBar;      StatusBar1: TStatusBar;
32        ToolBar1: TToolBar;
33        ToolBar2: TToolBar;
34      procedure Action1Execute(Sender: TObject);      procedure Action1Execute(Sender: TObject);
35      procedure ListView1ItemClick(const Sender: TObject;      procedure ListView1ItemClick(const Sender: TObject;
36        const AItem: TListViewItem);        const AItem: TListViewItem);
     procedure Action2Execute(Sender: TObject);  
37      procedure Action3Execute(Sender: TObject);      procedure Action3Execute(Sender: TObject);
38      procedure SpeedButton1Click(Sender: TObject);      procedure SpeedButton1Click(Sender: TObject);
39      procedure FormShow(Sender: TObject);      procedure FormShow(Sender: TObject);
# Line 46  type Line 43  type
43      procedure Action4Execute(Sender: TObject);      procedure Action4Execute(Sender: TObject);
44      procedure Action6Execute(Sender: TObject);      procedure Action6Execute(Sender: TObject);
45      procedure Action5Execute(Sender: TObject);      procedure Action5Execute(Sender: TObject);
46        procedure TrackBar2Change(Sender: TObject);
47        procedure FormCreate(Sender: TObject);
48    private    private
49      { private 宣言 }      { private 宣言 }
50    public    public
51      { public 宣言 }      { public 宣言 }
52      th: TThread;      th: TThread;
53        list: TStringList;
54        procedure PlayMusic(Number: integer);
55        procedure Id3Tag;
56    end;    end;
57    
58  var  var
# Line 61  implementation Line 63  implementation
63  {$R *.fmx}  {$R *.fmx}
64  {$R *.LgXhdpiTb.fmx ANDROID}  {$R *.LgXhdpiTb.fmx ANDROID}
65    
66  uses Unit2, Unit3, Unit4;  uses Unit2, Unit3, Unit4, Mp3FileUtils;
67    
68  procedure TForm1.Action1Execute(Sender: TObject);  procedure TForm1.Action1Execute(Sender: TObject);
69  begin  begin
# Line 69  begin Line 71  begin
71      MediaPlayer1.Stop;      MediaPlayer1.Stop;
72    ListView1.ClearItems;    ListView1.ClearItems;
73    Form3.Show;    Form3.Show;
74    if Assigned(th) = true then    if th <> nil then
75    begin    begin
76      th.Terminate;      th.Terminate;
77      th.WaitFor;      th.WaitFor;
78      th.Free;      FreeAndNil(th);
79    end;    end;
80    th := TSearchMP3.Create;    th := TSearchMP3.Create;
81  end;  end;
82    
 procedure TForm1.Action2Execute(Sender: TObject);  
 var  
   s: TStringList;  
   t: TListViewItem;  
 begin  
   s := TStringList.Create;  
   try  
     for t in ListView1.Items do  
       s.Add(t.Detail);  
     s.SaveToFile(TPath.GetHomePath + TPath.DirectorySeparatorChar + 'Path.txt');  
   finally  
     s.Free;  
   end;  
 end;  
   
83  procedure TForm1.Action3Execute(Sender: TObject);  procedure TForm1.Action3Execute(Sender: TObject);
84  var  var
85    s: TStringList;    s: TStringList;
86    t: string;    t: string;
87  begin  begin
88    ListView1.ClearItems;    ListView1.ClearItems;
89    s := TStringList.Create;    list.LoadFromFile(TPath.GetHomePath + TPath.DirectorySeparatorChar +
90    try      'Path.txt');
91      s.LoadFromFile(TPath.GetHomePath + TPath.DirectorySeparatorChar +    Id3Tag;
       'Path.txt');  
     for t in s do  
       if FileExists(t) = true then  
         with ListView1.Items.Add do  
         begin  
           Detail := t;  
           Text := ExtractFileName(t);  
         end;  
   finally  
     s.Free;  
   end;  
92  end;  end;
93    
94  procedure TForm1.Action4Execute(Sender: TObject);  procedure TForm1.Action4Execute(Sender: TObject);
# Line 122  begin Line 98  begin
98      MediaPlayer1.Stop;      MediaPlayer1.Stop;
99      Action4.Text := 'Play';      Action4.Text := 'Play';
100    end    end
101    else    else if ListView1.ItemCount > 0 then
102    begin    begin
103      if (ListView1.ItemCount > 0) and (ListView1.ItemIndex = -1) then      if ListView1.ItemIndex = -1 then
104          PlayMusic(0)
105        else
106      begin      begin
107        ListView1.ItemIndex := 0;        MediaPlayer1.FileName := ListView1.Items[ListView1.ItemIndex].Detail;
       MediaPlayer1.FileName := ListView1.Items[0].Detail;  
108        TrackBar2.Max := MediaPlayer1.Duration;        TrackBar2.Max := MediaPlayer1.Duration;
109        TrackBar2.Value := 0;        MediaPlayer1.CurrentTime := Trunc(TrackBar2.Value);
110          MediaPlayer1.Volume := TrackBar1.Value;
111          MediaPlayer1.Play;
112      end;      end;
113      MediaPlayer1.Play;      MediaPlayer1.Play;
114      Action4.Text := 'Stop';      Action4.Text := 'Stop';
# Line 138  end; Line 117  end;
117    
118  procedure TForm1.Action5Execute(Sender: TObject);  procedure TForm1.Action5Execute(Sender: TObject);
119  begin  begin
120    MediaPlayer1.CurrentTime := MediaPlayer1.CurrentTime -    if MediaPlayer1.CurrentTime / (MediaTimeScale div 10000) < 5 then
121      MediaTimeScale div 1000;    begin
122    TrackBar2.Value := MediaPlayer1.CurrentTime;      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;  end;
134    
135  procedure TForm1.Action6Execute(Sender: TObject);  procedure TForm1.Action6Execute(Sender: TObject);
136    var
137      i: integer;
138  begin  begin
139    MediaPlayer1.CurrentTime := MediaPlayer1.CurrentTime +    if ListView1.ItemIndex < ListView1.ItemCount - 1 then
140      MediaTimeScale div 1000;    begin
141    TrackBar2.Value := MediaPlayer1.CurrentTime;      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;  end;
151    
152  procedure TForm1.FormDestroy(Sender: TObject);  procedure TForm1.FormDestroy(Sender: TObject);
153    var
154      i: integer;
155  begin  begin
156    Action2Execute(Sender);    list.SaveToFile(TPath.GetHomePath + TPath.DirectorySeparatorChar +
157    if Assigned(th) = true then      'Path.txt');
158      list.Free;
159      if th <> nil then
160    begin    begin
161      th.Terminate;      th.Terminate;
162      th.WaitFor;      th.WaitFor;
# Line 170  begin Line 173  begin
173      Action1Execute(Sender);      Action1Execute(Sender);
174  end;  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;  procedure TForm1.ListView1ItemClick(const Sender: TObject;
206    const AItem: TListViewItem);    const AItem: TListViewItem);
207  begin  begin
208    with MediaPlayer1 do    if FileExists(ListView1.Items[ListView1.ItemIndex].Detail) = true then
209    begin      PlayMusic(ListView1.ItemIndex)
210      if State = TMediaState.Playing then    else
211        Stop;      Action1Execute(Sender);
212      Clear;  end;
213      if FileExists(AItem.Detail) = true then  
214        FileName := AItem.Detail  procedure TForm1.PlayMusic(Number: integer);
215      else  begin
216      begin    ListView1.ItemIndex := Number;
217        Action1Execute(Sender);    MediaPlayer1.Stop;
218        Exit;    MediaPlayer1.Clear;
219      end;    MediaPlayer1.FileName := ListView1.Items[Number].Detail;
220      Volume := TrackBar1.Value;    TrackBar2.Max := MediaPlayer1.Duration;
221      TrackBar2.Max := Duration;    TrackBar2.Value := 0;
222      TrackBar2.Value := 0;    Action4.Text := 'Stop';
223      Play;    MediaPlayer1.Volume := TrackBar1.Value;
224    end;    MediaPlayer1.Play;
225  end;  end;
226    
227  procedure TForm1.SpeedButton1Click(Sender: TObject);  procedure TForm1.SpeedButton1Click(Sender: TObject);
# Line 200  end; Line 232  end;
232  procedure TForm1.Timer1Timer(Sender: TObject);  procedure TForm1.Timer1Timer(Sender: TObject);
233  begin  begin
234    if (ListView1.ItemIndex > -1) and    if (ListView1.ItemIndex > -1) and
235      (Trunc(10000 * MediaPlayer1.Duration / MediaTimeScale) <=      ((MediaPlayer1.Duration - MediaPlayer1.CurrentTime) /
236      Ceil(10000 * MediaPlayer1.CurrentTime / MediaTimeScale)) then      (MediaTimeScale div 10000) < 1) then
237    begin    begin
238      if ListView1.ItemIndex < ListView1.Items.Count - 1 then      if ListView1.ItemIndex < ListView1.Items.Count - 1 then
239      begin        PlayMusic(ListView1.ItemIndex + 1);
240        ListView1.ItemIndex := ListView1.ItemIndex + 1;    end
241        with MediaPlayer1 do    else if MediaPlayer1.State = TMediaState.Playing then
       begin  
         Stop;  
         Clear;  
         FileName := ListView1.Items.Item[ListView1.ItemIndex].Detail;  
         Volume := TrackBar1.Value;  
         Play;  
       end;  
     end;  
   end;  
   if MediaPlayer1.State = TMediaState.Playing then  
242      TrackBar2.Value := MediaPlayer1.CurrentTime;      TrackBar2.Value := MediaPlayer1.CurrentTime;
243  end;  end;
244    
# Line 225  begin Line 247  begin
247    MediaPlayer1.Volume := TrackBar1.Value;    MediaPlayer1.Volume := TrackBar1.Value;
248  end;  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.  end.

Legend:
Removed from v.2  
changed lines
  Added in v.7

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