forked from pyscripter/python4delphi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWrapFmxMedia.pas
470 lines (391 loc) · 12.7 KB
/
WrapFmxMedia.pas
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
{$I ..\Definition.Inc}
unit WrapFmxMedia;
interface
uses
System.TypInfo, FMX.Media,
PythonEngine, WrapDelphi,
WrapFmxTypes, WrapFmxControls, WrapFmxActnList, WrapFmxStdActns;
type
TSampleBufferReadyEventHandler = class(TEventHandler)
protected
procedure DoEvent(Sender: TObject; const ATime: TMediaTime);
public
constructor Create(PyDelphiWrapper: TPyDelphiWrapper; Component: TObject;
PropertyInfo: PPropInfo; Callable: PPyObject); override;
class function GetTypeInfo: PTypeInfo; override;
end;
TPyDelphiCameraComponent = class(TPyDelphiFmxObject)
private
function GetDelphiObject: TCameraComponent;
procedure SetDelphiObject(const Value: TCameraComponent);
public
class function DelphiObjectClass: TClass; override;
class procedure RegisterGetSets(PythonType: TPythonType); override;
class procedure RegisterMethods(PythonType: TPythonType); override;
public
property DelphiObject: TCameraComponent read GetDelphiObject
write SetDelphiObject;
end;
//Media player wrappers
TPyDelphiCustomMediaCodec = class(TPyDelphiObject)
private
function GetDelphiObject: TCustomMediaCodec;
procedure SetDelphiObject(const Value: TCustomMediaCodec);
public
class function DelphiObjectClass: TClass; override;
public
property DelphiObject: TCustomMediaCodec read GetDelphiObject
write SetDelphiObject;
end;
TPyDelphiMedia = class(TPyDelphiObject)
private
function GetDelphiObject: TMedia;
procedure SetDelphiObject(const Value: TMedia);
public
class function DelphiObjectClass: TClass; override;
public
property DelphiObject: TMedia read GetDelphiObject
write SetDelphiObject;
end;
TPyDelphiMediaPlayerControl = class(TPyDelphiControl)
private
function GetDelphiObject: TMediaPlayerControl;
procedure SetDelphiObject(const Value: TMediaPlayerControl);
public
class function DelphiObjectClass: TClass; override;
public
property DelphiObject: TMediaPlayerControl read GetDelphiObject
write SetDelphiObject;
end;
TPyDelphiMediaPlayer = class(TPyDelphiFmxObject)
private
function GetDelphiObject: TMediaPlayer;
procedure SetDelphiObject(const Value: TMediaPlayer);
public
class function DelphiObjectClass: TClass; override;
public
property DelphiObject: TMediaPlayer read GetDelphiObject
write SetDelphiObject;
end;
TPyDelphiCustomMediaPlayerAction = class(TPyDelphiCustomAction)
private
function GetDelphiObject: TCustomMediaPlayerAction;
procedure SetDelphiObject(const Value: TCustomMediaPlayerAction);
public
class function DelphiObjectClass: TClass; override;
public
property DelphiObject: TCustomMediaPlayerAction read GetDelphiObject
write SetDelphiObject;
end;
TPyDelphiMediaPlayerStart = class(TPyDelphiCustomMediaPlayerAction)
private
function GetDelphiObject: TMediaPlayerStart;
procedure SetDelphiObject(const Value: TMediaPlayerStart);
public
class function DelphiObjectClass: TClass; override;
public
property DelphiObject: TMediaPlayerStart read GetDelphiObject
write SetDelphiObject;
end;
TPyDelphiMediaPlayerStop = class(TPyDelphiCustomMediaPlayerAction)
private
function GetDelphiObject: TMediaPlayerStop;
procedure SetDelphiObject(const Value: TMediaPlayerStop);
public
class function DelphiObjectClass: TClass; override;
public
property DelphiObject: TMediaPlayerStop read GetDelphiObject
write SetDelphiObject;
end;
TPyDelphiMediaPlayerPause = class(TPyDelphiCustomMediaPlayerAction)
private
function GetDelphiObject: TMediaPlayerPlayPause;
procedure SetDelphiObject(const Value: TMediaPlayerPlayPause);
public
class function DelphiObjectClass: TClass; override;
public
property DelphiObject: TMediaPlayerPlayPause read GetDelphiObject
write SetDelphiObject;
end;
TPyDelphiMediaPlayerValue = class(TPyDelphiCustomValueRangeAction)
private
function GetDelphiObject: TMediaPlayerValue;
procedure SetDelphiObject(const Value: TMediaPlayerValue);
public
class function DelphiObjectClass: TClass; override;
public
property DelphiObject: TMediaPlayerValue read GetDelphiObject
write SetDelphiObject;
end;
TPyDelphiMediaPlayerCurrentTime = class(TPyDelphiMediaPlayerValue)
private
function GetDelphiObject: TMediaPlayerCurrentTime;
procedure SetDelphiObject(const Value: TMediaPlayerCurrentTime);
public
class function DelphiObjectClass: TClass; override;
public
property DelphiObject: TMediaPlayerCurrentTime read GetDelphiObject
write SetDelphiObject;
end;
TPyDelphiMediaPlayerVolume = class(TPyDelphiMediaPlayerValue)
private
function GetDelphiObject: TMediaPlayerVolume;
procedure SetDelphiObject(const Value: TMediaPlayerVolume);
public
class function DelphiObjectClass: TClass; override;
public
property DelphiObject: TMediaPlayerVolume read GetDelphiObject
write SetDelphiObject;
end;
implementation
type
TFMXMediaRegistration = class(TRegisteredUnit)
public
function Name: string; override;
procedure RegisterWrappers(APyDelphiWrapper: TPyDelphiWrapper); override;
procedure DefineVars(APyDelphiWrapper: TPyDelphiWrapper); override;
end;
{ TFMXMediaRegistration }
function TFMXMediaRegistration.Name: string;
begin
Result := 'Media';
end;
procedure TFMXMediaRegistration.DefineVars(APyDelphiWrapper: TPyDelphiWrapper);
begin
inherited;
end;
procedure TFMXMediaRegistration.RegisterWrappers(APyDelphiWrapper
: TPyDelphiWrapper);
begin
inherited;
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiCameraComponent);
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiCustomMediaCodec);
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiMediaPlayerControl);
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiMediaPlayer);
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiMedia);
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiCustomMediaPlayerAction);
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiMediaPlayerStart);
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiMediaPlayerStop);
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiMediaPlayerPause);
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiMediaPlayerValue);
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiMediaPlayerCurrentTime);
APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiMediaPlayerVolume);
APyDelphiWrapper.EventHandlers.RegisterHandler(TSampleBufferReadyEventHandler);
end;
{ TSampleBufferReadyEventHandler }
constructor TSampleBufferReadyEventHandler.Create(PyDelphiWrapper
: TPyDelphiWrapper; Component: TObject; PropertyInfo: PPropInfo;
Callable: PPyObject);
var
Method : TMethod;
begin
inherited;
Method.Code := @TSampleBufferReadyEventHandler.DoEvent;
Method.Data := Self;
SetMethodProp(Component, PropertyInfo, Method);
end;
procedure TSampleBufferReadyEventHandler.DoEvent(Sender: TObject;
const ATime: TMediaTime);
var
PySender, PyTuple, PyResult, PyTime : PPyObject;
begin
Assert(Assigned(PyDelphiWrapper));
if Assigned(Callable) and PythonOK then
with GetPythonEngine do begin
PySender := PyDelphiWrapper.Wrap(Sender);
PyTime := PyLong_FromLong(ATime);
PyTuple := PyTuple_New(2);
GetPythonEngine.PyTuple_SetItem(PyTuple, 0, PySender);
GetPythonEngine.PyTuple_SetItem(PyTuple, 1, PyTime);
try
PyResult := PyObject_CallObject(Callable, PyTuple);
Py_XDECREF(PyResult);
finally
Py_DECREF(PyTuple);
end;
CheckError;
end;
end;
class function TSampleBufferReadyEventHandler.GetTypeInfo: PTypeInfo;
begin
Result := System.TypeInfo(TSampleBufferReadyEvent);
end;
{ TPyDelphiCameraComponent }
class function TPyDelphiCameraComponent.DelphiObjectClass: TClass;
begin
Result := TCameraComponent;
end;
class procedure TPyDelphiCameraComponent.RegisterGetSets
(PythonType: TPythonType);
begin
inherited;
end;
class procedure TPyDelphiCameraComponent.RegisterMethods
(PythonType: TPythonType);
begin
inherited;
end;
function TPyDelphiCameraComponent.GetDelphiObject: TCameraComponent;
begin
Result := TCameraComponent(inherited DelphiObject);
end;
procedure TPyDelphiCameraComponent.SetDelphiObject
(const Value: TCameraComponent);
begin
inherited DelphiObject := Value;
end;
{ TPyDelphiCustomMediaCodec }
class function TPyDelphiCustomMediaCodec.DelphiObjectClass: TClass;
begin
Result := TCustomMediaCodec;
end;
function TPyDelphiCustomMediaCodec.GetDelphiObject: TCustomMediaCodec;
begin
Result := TCustomMediaCodec(inherited DelphiObject);
end;
procedure TPyDelphiCustomMediaCodec.SetDelphiObject(
const Value: TCustomMediaCodec);
begin
inherited DelphiObject := Value;
end;
{ TPyDelphiMedia }
class function TPyDelphiMedia.DelphiObjectClass: TClass;
begin
Result := TMedia;
end;
function TPyDelphiMedia.GetDelphiObject: TMedia;
begin
Result := TMedia(inherited DelphiObject);
end;
procedure TPyDelphiMedia.SetDelphiObject(const Value: TMedia);
begin
inherited DelphiObject := Value;
end;
{ TPyDelphiMediaPlayerControl }
class function TPyDelphiMediaPlayerControl.DelphiObjectClass: TClass;
begin
Result := TMediaPlayerControl;
end;
function TPyDelphiMediaPlayerControl.GetDelphiObject: TMediaPlayerControl;
begin
Result := TMediaPlayerControl(inherited DelphiObject);
end;
procedure TPyDelphiMediaPlayerControl.SetDelphiObject(
const Value: TMediaPlayerControl);
begin
inherited DelphiObject := Value;
end;
{ TPyDelphiMediaPlayer }
class function TPyDelphiMediaPlayer.DelphiObjectClass: TClass;
begin
Result := TMediaPlayer;
end;
function TPyDelphiMediaPlayer.GetDelphiObject: TMediaPlayer;
begin
Result := TMediaPlayer(inherited DelphiObject);
end;
procedure TPyDelphiMediaPlayer.SetDelphiObject(const Value: TMediaPlayer);
begin
inherited DelphiObject := Value;
end;
{ TPyDelphiCustomMediaPlayerAction }
class function TPyDelphiCustomMediaPlayerAction.DelphiObjectClass: TClass;
begin
Result := TCustomMediaPlayerAction;
end;
function TPyDelphiCustomMediaPlayerAction.GetDelphiObject: TCustomMediaPlayerAction;
begin
Result := TCustomMediaPlayerAction(inherited DelphiObject);
end;
procedure TPyDelphiCustomMediaPlayerAction.SetDelphiObject(
const Value: TCustomMediaPlayerAction);
begin
inherited DelphiObject := Value;
end;
{ TPyDelphiMediaPlayerStart }
class function TPyDelphiMediaPlayerStart.DelphiObjectClass: TClass;
begin
Result := TMediaPlayerStart;
end;
function TPyDelphiMediaPlayerStart.GetDelphiObject: TMediaPlayerStart;
begin
Result := TMediaPlayerStart(inherited DelphiObject);
end;
procedure TPyDelphiMediaPlayerStart.SetDelphiObject(
const Value: TMediaPlayerStart);
begin
inherited DelphiObject := Value;
end;
{ TPyDelphiMediaPlayerStop }
class function TPyDelphiMediaPlayerStop.DelphiObjectClass: TClass;
begin
Result := TMediaPlayerStop;
end;
function TPyDelphiMediaPlayerStop.GetDelphiObject: TMediaPlayerStop;
begin
Result := TMediaPlayerStop(inherited DelphiObject);
end;
procedure TPyDelphiMediaPlayerStop.SetDelphiObject(
const Value: TMediaPlayerStop);
begin
inherited DelphiObject := Value;
end;
{ TPyDelphiMediaPlayerPause }
class function TPyDelphiMediaPlayerPause.DelphiObjectClass: TClass;
begin
Result := TMediaPlayerPlayPause;
end;
function TPyDelphiMediaPlayerPause.GetDelphiObject: TMediaPlayerPlayPause;
begin
Result := TMediaPlayerPlayPause(inherited DelphiObject);
end;
procedure TPyDelphiMediaPlayerPause.SetDelphiObject(
const Value: TMediaPlayerPlayPause);
begin
inherited DelphiObject := Value;
end;
{ TPyDelphiMediaPlayerValue }
class function TPyDelphiMediaPlayerValue.DelphiObjectClass: TClass;
begin
Result := TMediaPlayerValue;
end;
function TPyDelphiMediaPlayerValue.GetDelphiObject: TMediaPlayerValue;
begin
Result := TMediaPlayerValue(inherited DelphiObject);
end;
procedure TPyDelphiMediaPlayerValue.SetDelphiObject(
const Value: TMediaPlayerValue);
begin
inherited DelphiObject := Value;
end;
{ TPyDelphiMediaPlayerCurrentTime }
class function TPyDelphiMediaPlayerCurrentTime.DelphiObjectClass: TClass;
begin
Result := TMediaPlayerCurrentTime;
end;
function TPyDelphiMediaPlayerCurrentTime.GetDelphiObject: TMediaPlayerCurrentTime;
begin
Result := TMediaPlayerCurrentTime(inherited DelphiObject);
end;
procedure TPyDelphiMediaPlayerCurrentTime.SetDelphiObject(
const Value: TMediaPlayerCurrentTime);
begin
inherited DelphiObject := Value;
end;
{ TPyDelphiMediaPlayerVolume }
class function TPyDelphiMediaPlayerVolume.DelphiObjectClass: TClass;
begin
Result := TMediaPlayerVolume;
end;
function TPyDelphiMediaPlayerVolume.GetDelphiObject: TMediaPlayerVolume;
begin
Result := TMediaPlayerVolume(inherited DelphiObject);
end;
procedure TPyDelphiMediaPlayerVolume.SetDelphiObject(
const Value: TMediaPlayerVolume);
begin
inherited DelphiObject := Value;
end;
initialization
RegisteredUnits.Add(TFMXMediaRegistration.Create());
end.