-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMainPlayer1.pas
More file actions
259 lines (229 loc) · 5.92 KB
/
MainPlayer1.pas
File metadata and controls
259 lines (229 loc) · 5.92 KB
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
254
255
256
257
258
259
unit MainPlayer1;
interface
uses
classes, graphics, ExtCtrls, StdCtrls, ComCtrls, SysUtils,
MyXAudioPlayer1, MyTypes ;
Type
TStatusChangeEvent = procedure(Sender:TObject; TheStatus : TItemStatus) of object;
TMainPlayer = Class(TComponent)
private
// FHDPlayer : TAudioPlayer;
FHDPlayer : TMyXAudioPlayer;
FCDPlayer : TMyXAudioPlayer; // TCDPlayer;
FFileName : String;
FPlayInfo : TPlayInfo;
FMixCalled : Boolean;
FBusy : Boolean;
FStatus : TItemStatus;
FSimpleUnload : Boolean;
FOnChangeStatus : TStatusChangeEvent;
FHasError : Boolean;
FErrorString : String;
Function LoadHardDisc:Boolean;
function LoadCD:Boolean;
procedure SetPosition(Position : LongInt);
Function GetPosition : LongInt;
Function GetDuration : LongInt;
protected
procedure XOnStateChange(Sender :TObject);
public
constructor Create(AOwner:TComponent); override;
destructor Destroy; override;
function Load : Boolean;
procedure Play;
procedure Pause;
procedure Stop;
procedure Unload;
procedure UnloadOnly;
procedure PlayFadeOut(delay:LongInt);
published
property FileName : String read FFileName write FFileName;
property SimpleUnload : Boolean Read FSimpleUnload Write FSimpleUnload;
property Busy : Boolean read FBusy;
property PlayInfo : TPlayInfo read FPlayInfo write FPlayInfo;
property MixCalled : Boolean Read FMixCalled write FMixCalled;
property Duration : LongInt read GetDuration;
property HasError : Boolean read FHasError write FHasError;
property ErrorString : String read FErrorString write FErrorString;
property Position : Longint read GetPosition write SetPosition;
property OnChangeStatus : TStatusChangeEvent read FOnChangeStatus write FOnChangeStatus;
end;
implementation
uses
MainForm1, MyLibrary, dialogs;
constructor TMainPlayer.Create(AOwner:TComponent);
begin
inherited create(AOwner);
with FPlayInfo do
begin
Length := 0;
PlayStart := 0;
MixPos := 0;
end;
FStatus := isUnloaded;
FCDPlayer := nil;
FHDPlayer := nil;
FBusy := False;
end;
destructor TMainPlayer.Destroy;
begin
if FHDPlayer <> nil then
begin
FHDPlayer := nil;
end;
if FCDPlayer <> nil then
begin
FCDPlayer := Nil;
end;
inherited Destroy;
end;
function TMainPlayer.Load : Boolean;
begin
Result := False;
FMixCalled := False;
FSimpleUnload := False;
FHasError := False;
FBusy := LoadHardDisc;
{ case FPlayItem.Kind of
pkHD : FBusy := LoadHardDisc;
pkCD : FBusy := LoadCD;
end; }
if FBusy then
FStatus := isLoading
else
FStatus := isUnloaded;
Result := FBusy;
if Assigned(FOnChangeStatus) then
FOnChangeStatus(Self, FStatus);
end;
Function TMainPlayer.LoadHardDisc:Boolean;
begin
Result := False;
if FHDPlayer = nil then
begin
FHDPlayer := Form1.FindFreeAudioPlayer;
if FHDPlayer <> nil then
with FHDPlayer do
Begin
if Open(FFileName) then
Begin
OnStateChange := XOnStateChange;
Result := True;
Tag := 1;
SelectionStart := FPlayInfo.PlayStart;
SelectionEnd := FPlayInfo.Length;
FadeIn := FPlayInfo.FadeIn;
FadeOut := FPlayInfo.FadeOut;
MixPos := FPlayInfo.MixPos;
Volume := FPlayInfo.Volume;
end
else
Begin
OnStateChange := nil;
FHDPlayer.Tag := 0;
FHDPlayer := nil;
end;
end;
end;
end;
Function TMainPlayer.LoadCD:Boolean;
begin
Result := False;
end;
procedure TMainPlayer.XOnStateChange(Sender : TObject);
Begin
if (FHDPlayer = nil) or (Sender <> FHDPlayer) then
Exit;
Case FHDPlayer.PlayerState of
stLoading : FStatus := isLoading;
stOpened : FStatus := isReadyPlay;
stPlaying :
Begin
FHDPlayer.Tag := 2;
FStatus := isPlaying;
end;
stPaused : FStatus := isPaused;
stStoped : FStatus := isReadyPlay;
stClosed :
begin
FStatus := isDelete;
FHDPlayer.Tag := 0;
FHDPlayer.OnStateChange := nil;
FHDPlayer := nil;
FCDPlayer := nil;
FBusy := False;
end;
stEOF : FStatus := isEnded;
stError :
Begin
FHasError := True;
//FErrorString := (Sender as TAudioPlayer).ErrorStr;
FErrorString := (Sender as TMyXAudioPlayer).ErrorStr;
FStatus := isEnded;
FSimpleUnload := False;
end;
stFadingIn, stFadingOut : FStatus := isFadePlay;
stSeeking : ;
end;
if Assigned(FOnChangeStatus) then
FOnChangeStatus(Self, FStatus);
end;
procedure TMainPlayer.Play;
begin
FHDPlayer.Play;
{ case FPlayItem.Kind of
pkHD :
begin
FHDPlayer.Play;
end;
end; }
end;
procedure TMainPlayer.Pause;
begin
FHDPlayer.Pause;
{ case FPlayItem.Kind of
pkHD : FHDPlayer.Pause;
pkCD : FCDPlayer.Pause;
end; }
end;
procedure TMainPlayer.Stop;
begin
FHDPlayer.Stop;
{ case FPlayItem.Kind of
pkHD : FHDPlayer.Stop;
pkCD : FCDPlayer.Stop;
end; }
end;
procedure TMainPlayer.PlayFadeOut(delay:LongInt);
begin
FHDPlayer.PlayFadeOut(delay);
end;
procedure TMainPlayer.UnloadOnly;
begin
FSimpleUnload := True;
Unload;
end;
procedure TMainPlayer.Unload;
begin
FStatus := isUnLoading; // to change button color to busy
if Assigned(FOnChangeStatus) then
FOnChangeStatus(Self, FStatus);
FHDPlayer.Unload;
{ case FPlayItem.Kind of
pkHD : FHDPlayer.Unload;
pkCD : FCDPlayer.Unload;
end; }
end;
procedure TMainPlayer.SetPosition(Position : LongInt);
begin
FHDPlayer.CurrentPosition := Position;
end;
Function TMainPlayer.GetPosition : LongInt;
Begin
Result := FHDPlayer.CurrentPosition;
end;
Function TMAinPlayer.GetDuration : LongInt;
Begin
Result := FHDPlayer.Duration;
end;
end.