Èñõîäíèêè è ëèñòèíãè ::: Delphi ::: MediaPlayer source

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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
  unit mainunit;
  interface
  uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, StdCtrls, ExtCtrls, MPlayer, XPMan, ComCtrls;
  type
    Tmainform = class(TForm)
      Panel1: TPanel;
      Button1: TButton;
      Button2: TButton;
      Button3: TButton;
      Button4: TButton;
      Button5: TButton;
      Button6: TButton;
      Label1: TLabel;
      filepathedit: TEdit;
      Button7: TButton;
      MediaPlayer: TMediaPlayer;
      Panel2: TPanel;
      TrackBar: TTrackBar;
      Timer: TTimer;
      procedure Button1Click(Sender: TObject);
      procedure FormCreate(Sender: TObject);
      procedure Button7Click(Sender: TObject);
      procedure Button2Click(Sender: TObject);
      procedure Button3Click(Sender: TObject);
      procedure Button4Click(Sender: TObject);
      procedure Button5Click(Sender: TObject);
      procedure Button6Click(Sender: TObject);
      procedure TimerTimer(Sender: TObject);
      procedure TrackBarEnter(Sender: TObject);
    private
    public
    end;
  var
    mainform: Tmainform;
    playlistshown, videoformshown, usrchange: boolean;
    k, track: integer;
  implementation
  uses playlistunit, movieunit;
  {$R *.dfm}
  procedure Tmainform.Button1Click(Sender: TObject);
  begin
   if playlistshown = false then
   begin
    playlistshown := true;
    playlist.Show;
   end else
   begin
    playlistshown := false;
    playlist.Close;
   end;
  end;
  procedure Tmainform.FormCreate(Sender: TObject);
  begin
   playlistshown := false;
   videoformshown := false;
  end;
  procedure Tmainform.Button7Click(Sender: TObject);
  begin
   if videoformshown = false then
   begin
    videoform.Show;
    videoformshown := true;
   end else
   begin
    videoformshown := false;
    videoform.Close;
   end;
  end;
  procedure Tmainform.Button2Click(Sender: TObject);
  begin
   if filepathedit.Text <> '' then
   begin
  &nbsp;&nbsp;if (playlist.plslistbox.Items.Count > -1) then
  &nbsp;&nbsp;begin
  &nbsp;&nbsp; track := playlist.plslistbox.ItemIndex;
  &nbsp;&nbsp; mediaplayer.FileName := filepathedit.Text;
  &nbsp;&nbsp; mediaplayer.Open;
  &nbsp;&nbsp; mediaplayer.Play;
  &nbsp;&nbsp; videoform.moviepanel.Width := mediaplayer.DisplayRect.Right;
  &nbsp;&nbsp; videoform.moviepanel.Height := mediaplayer.DisplayRect.Bottom;
  &nbsp;&nbsp; videoform.Width := videoform.moviepanel.Width+20;
  &nbsp;&nbsp; videoform.Height := videoform.moviepanel.Height+40;
  &nbsp;&nbsp;end;
   end;
  end;
  procedure Tmainform.Button3Click(Sender: TObject);
  begin
   mediaplayer.Pause;
  end;
  procedure Tmainform.Button4Click(Sender: TObject);
  begin
   videoform.moviepanel.Width := 369;
   videoform.moviepanel.Height := 185;
   videoform.Width := 394;
   videoform.Height := 235;
   mediaplayer.Stop;
   mediaplayer.Close;
  end;
  procedure Tmainform.Button5Click(Sender: TObject);
  begin
   if playlist.plslistbox.Items.Count > -1 then
   begin
  &nbsp;&nbsp;if track > 0 then
  &nbsp;&nbsp;dec (track) else track := playlist.plslistbox.Items.Count - 1;
  &nbsp;&nbsp;filepathedit.Text := playlist.plslistbox.Items.Strings[track];
  &nbsp;&nbsp;mediaplayer.FileName := filepathedit.Text;
  &nbsp;&nbsp;mediaplayer.Open;
  &nbsp;&nbsp;mediaplayer.Play;
   end;
  end;
  procedure Tmainform.Button6Click(Sender: TObject);
  begin
   if playlist.plslistbox.Items.Count > -1 then
   begin
  &nbsp;&nbsp;if track < (playlist.plslistbox.Items.Count - 1) then
  &nbsp;&nbsp;inc (track) else track := 0;
  &nbsp;&nbsp;filepathedit.Text := playlist.plslistbox.Items.Strings[track];
  &nbsp;&nbsp;mediaplayer.FileName := filepathedit.Text;
  &nbsp;&nbsp;mediaplayer.Open;
  &nbsp;&nbsp;mediaplayer.Play;
   end;
  end;
  procedure Tmainform.TimerTimer(Sender: TObject);
  begin
   if (mediaplayer.Mode = mpPlaying) or (mediaplayer.Mode = mpPaused) then
   begin
  &nbsp;&nbsp;if usrchange = true then
  &nbsp;&nbsp;begin
  &nbsp;&nbsp; timer.Enabled := false;
  &nbsp;&nbsp; usrchange := false;
  &nbsp;&nbsp; mediaplayer.Stop;
  &nbsp;&nbsp; mediaplayer.StartPos := (mediaplayer.TrackLength[0] div 100)*trackbar.Position;
  &nbsp;&nbsp; mediaplayer.Play;
  &nbsp;&nbsp; timer.Enabled := true;
  &nbsp;&nbsp;end else
  &nbsp;&nbsp;trackbar.Position := (mediaplayer.Position) div (mediaplayer.Length div 100);
   end;
  end;
  procedure Tmainform.TrackBarEnter(Sender: TObject);
  begin
   usrchange := true;
   button2.SetFocus;
  end;
  end.
  unit movieunit;
  interface
  uses
  &nbsp;&nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  &nbsp;&nbsp;Dialogs, ExtCtrls;
  type
  &nbsp;&nbsp;Tvideoform = class(TForm)
  &nbsp;&nbsp;&nbsp;&nbsp;moviepanel: TPanel;
  &nbsp;&nbsp;&nbsp;&nbsp;procedure FormClose(Sender: TObject; var Action: TCloseAction);
  &nbsp;&nbsp;private
  &nbsp;&nbsp;public
  &nbsp;&nbsp;end;
  var
  &nbsp;&nbsp;videoform: Tvideoform;
  implementation
  uses mainunit, playlistunit;
  {$R *.dfm}
  procedure Tvideoform.FormClose(Sender: TObject; var Action: TCloseAction);
  begin
   videoformshown := false;
  end;
  end.
  unit playlistunit;
  interface
  uses
  &nbsp;&nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  &nbsp;&nbsp;Dialogs, StdCtrls;
  type
  &nbsp;&nbsp;Tplaylist = class(TForm)
  &nbsp;&nbsp;&nbsp;&nbsp;plslistbox: TListBox;
  &nbsp;&nbsp;&nbsp;&nbsp;Button1: TButton;
  &nbsp;&nbsp;&nbsp;&nbsp;Button2: TButton;
  &nbsp;&nbsp;&nbsp;&nbsp;Button3: TButton;
  &nbsp;&nbsp;&nbsp;&nbsp;OpenDialog: TOpenDialog;
  &nbsp;&nbsp;&nbsp;&nbsp;procedure Button1Click(Sender: TObject);
  &nbsp;&nbsp;&nbsp;&nbsp;procedure Button2Click(Sender: TObject);
  &nbsp;&nbsp;&nbsp;&nbsp;procedure Button3Click(Sender: TObject);
  &nbsp;&nbsp;&nbsp;&nbsp;procedure FormClose(Sender: TObject; var Action: TCloseAction);
  &nbsp;&nbsp;&nbsp;&nbsp;procedure plslistboxClick(Sender: TObject);
  &nbsp;&nbsp;&nbsp;&nbsp;procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  &nbsp;&nbsp;private
  &nbsp;&nbsp;public