forked from rofl0r/KOL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
KOLMediaPlayer.pas
2145 lines (2028 loc) · 69.9 KB
/
KOLMediaPlayer.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
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit KOLMediaPlayer;
interface
uses
Windows, MMSystem, KOL;
{#If not[OBJECTS]}
{#Replace[= object(][= class(]}
{#Replace[@Self][Self]}
{#Replace[@ Self][Self]}
{#End not[OBJECTS]}
{ -- MultiMedia player object -- }
type
{#If not[OBJECTS]}
{++}(*TMediaPlayer = class;*){--}
PMediaPlayer = {-}^{+}TMediaPlayer;
TMPState = ( mpNotReady, mpStopped, mpPlaying, mpRecording, mpSeeking,
mpPaused, mpOpen );
{* Available states of TMediaPlayer. }
TMPDeviceType = ( mmAutoSelect, mmVCR, mmVideodisc, mmOverlay, mmCDAudio, mmDAT,
mmScanner, mmAVIVideo, mmDigitalVideo, mmOther, mmWaveAudio,
mmSequencer );
{* Available device types of TMediaPlayer. }
TMPTimeFormat = ( tfMilliseconds, tfHMS, tfMSF, tfFrames, tfSMPTE24, tfSMPTE25,
tfSMPTE30, tfSMPTE30Drop, tfBytes, tfSamples, tfTMSF );
{* Available time formats, used with properties Length and Position. }
TMPNotifyValue = (nvSuccessful, nvSuperseded, nvAborted, nvFailure);
{* Available notification flags, which can be passed to TMediaPlayer.OnNotify
event handler (if it is set). }
TMPOnNotify = procedure( Sender: PMediaPlayer; NotifyValue: TMPNotifyValue ) of object;
{* Event type for TMediaPlayer.OnNotify event. }
TSoundChannel = ( chLeft, chRight );
{* Available sound channels. }
TSoundChannels = set of TSoundChannel;
{* Set of available sound channels. }
{ ----------------------------------------------------------------------
TMediaPlayer object
----------------------------------------------------------------------- }
TMediaPlayer = object( TObj )
{* MediaPlayer incapsulation object. Can open and play any supported
by system multimedia file. (To play wave only, it is possible to
use functions PlaySound..., which can also play it from memory and
from resource).
|<br>
Please note, that while debugging, You can get application exception
therefore standalone application is working fine. (Such results took
place for huge video). )
}
private
FWait: Boolean;
FDeviceID: Integer;
FError: Integer;
FTrack: Integer;
FDisplay: HWnd;
FFileName: String;
FOnNotify: TMPOnNotify;
FDeviceType: TMPDeviceType;
FHeight: Integer;
FWidth: Integer;
FTimeFormat: TMPTimeFormat;
FBaseKeyCDAudio: HKey;
FoldKeyValCDData: DWORD;
FoldKeyValCDAudio: String;
FAutoRestore: procedure of object;
FAudioOff: array[ TSoundChannel ] of Boolean;
FVideoOff: Boolean;
FAlias: String;
function GetErrorMessage: String;
function GetState: TMPState;
procedure SetPause(const Value: Boolean);
procedure SetTrack(Value: Integer);
function GetCapability( const Index: Integer ): Boolean;
function GetICapability( const Index: Integer ): Integer;
procedure SetDisplay(const Value: HWND);
function GetDisplayRect: TRect;
function GetDeviceType: TMPDeviceType;
procedure SetFileName(const Value: String);
function GetBState( const Index: Integer ): Boolean;
function GetIState( const Index: Integer ): Integer;
function GetPosition: Integer;
procedure SetPosition(Value: Integer);
function GetTimeFormat: TMPTimeFormat;
procedure SetTimeFormat(const Value: TMPTimeFormat);
procedure SetDisplayRect(const Value: TRect);
function GetPause: Boolean;
function GetAudioOn(Chn: TSoundChannels): Boolean;
procedure SetAudioOn(Chn: TSoundChannels; const Value: Boolean);
function GetVideoOn: Boolean;
procedure SetVideoOn(const Value: Boolean);
function DGVGetSpeed: Integer;
procedure DGVSetSpeed(const Value: Integer);
protected
{++}(*public*){--}
destructor Destroy; {-}virtual;{+}{++}(*override;*){--}
{* Please remember, that if CDAudio (e.g.) is playing, it is not stop
playing when TMediaPlayer object destroying unless performing command
! Pause := True; }
{#End not[OBJECTS]}
public
property FileName: String read FFileName write SetFileName;
{* Name of file, containing multimedia, if any (some multimedia devices
do not require file, corresponding to device rather then file. Such as
mmCDAudio, mmScanner, etc. Use in that case DeviceType property to
assign to desired type of multimedia and then open it using Open method).
When new string is assigned to a FileName, previous media is closed
and another one is opened automatically. }
property DeviceType: TMPDeviceType read GetDeviceType write FDeviceType;
{* Type of multimedia. For opened media, real type is returned. If no
multimedia (device or file) opened, it is possible to set DeviceType to
desired type before opening multimedia. Use such way for opening
devices rather then for opening multimedia, stored in files. }
property DeviceID: Integer read FDeviceID;
{* Returns DeviceID, corresponded to opened multimedia (0 is returned
if no media opened. }
property TimeFormat: TMPTimeFormat read GetTimeFormat write SetTimeFormat;
{* Time format, used to set/retrieve information about Length or Position.
Please note, that not all formats are supported by all multimedia devices.
Only tfMilliseconds (is set by default) supported by all devices. Following
table shows what devices are supporting certain time formats:
|<table>
|&L=<tr><td>%0</td><td>
|&E=</td></tr>
<L tfMilliseconds> All multimedia device types. <E>
<L tfBytes> mmWaveAudio <E>
<L tfFrames> mmDigitalVideo <E>
<L tfHMS (hours, minutes, seconds)> mmVCR (video cassete recorder), mmVideodisc.
It is necessary to parse retrieved Length or Position or to prepare
value before assigning it to Position using typecast to THMS. <E>
<L tfMSF (minutes, seconds, frames)> mmCDAudio, mmVCR. It is necessary to
parse value retrieved from Length or Position properties or value to
assign to property Position using typecast to TMSF type. <E>
<L tfSamples> mmWaveAudio <E>
<L tfSMPTE24, tfSMPTE25, tfSMPTE30, tfSMPTE30DROP (Society of Motion Picture
and Television Engineers)> mmVCR, mmSequencer. <E>
<L tfTMSF (tracks, minutes, seconds, frames)> mmVCR <E>
|</table> }
property Position: Integer //index MCI_STATUS_POSITION read GetIState
read GetPosition write SetPosition;
{* Current position in milliseconds. Even if device contains several tracks,
this is the position from starting of first track. To determine position
in current Track, subtract TrackStartPosition. }
property Track: Integer read FTrack write SetTrack;
{* Current track (from 1 to TrackCount). Has no sence, if tracks are not
supported by opened multimedia device, or no tracks present. }
property TrackCount: Integer index MCI_STATUS_NUMBER_OF_TRACKS read GetIState;
{* Count of tracks for opened multimedia device. If device does not support
tracks, or tracks not present (e.g. there are no tracks found on CD),
value 1 is returned by system (but this not a rule to determine if
tracks are available). }
property Length: Integer index MCI_STATUS_LENGTH read GetIState;
{* Length of multimedia in milliseconds. Even if device has tracks,
this the length of entire multimedia. }
property Display: HWnd read FDisplay write SetDisplay;
{* Window to represent animation. It is recommended to create neutral
control (e.g. label, or paint box, and assign its TControl.Handle to
this property). Has no sense for multimedia, which HasVideo = False
(no animation presented). }
property DisplayRect: TRect read GetDisplayRect write SetDisplayRect;
{* Rectangle in Display window, where animation is shown while playing
animation. To restore default value, pass Bottom = Top = 0 and Right =
Left = 0. }
property Error: Integer read FError;
{* Error code. Is set after every operation. If 0, no errors detected. It
is also possible to retrieve description string for error using
property ErrorMessage. }
property ErrorMessage: String read GetErrorMessage;
{* Brief description of Error. }
property State: TMPState read GetState;
{* Current state of multimedia. }
property Pause: Boolean read GetPause write SetPause;
{* True, if multimedia currently not playing (or not open). Set this property
to True to pause playing, and to False to resume. }
property Wait: Boolean read FWait write FWait;
{* True, if operations will be performed synchronously (i.e. execution will
be continued only after completing operation). If Wait is False (default),
control is returned immediately to application, without waiting of completing
of operation. It is possible in that case to get notification about finishing
of previous operation in OnNotify event handler (if any has been set). }
property TrackStartPosition: Integer index $80000000 or MCI_STATUS_POSITION
read GetIState;
{* Returns given track starting position (in units, specisied by TimeFormat
property. E.g., if TimeFormat is set to (default) tfMilliseconds, in
milliseconds). }
property TrackLength: Integer index $80000000 or MCI_STATUS_LENGTH read GetIState;
{* Returns given track length (in units, specified by TimeFormat property). }
property OnNotify: TMPOnNotify read FOnNotify write FOnNotify;
{* Called when asynchronous operation completed. (By default property Wait is
set to False, so all operations are performed asynchronously, i.e. control
is returned to application ithout of waiting of completion operation).
Please note, that syatem can make several notifications while performing
operation. To determine if operation completed, check State property.
E.g., to find where playing is finished, check in OnNotify event handler
if State <> mpPlaying.
|<br>Though TMediaPlayer works fine with the most of multimedia formats
(at least it is tested for WAV, MID, RMI, AVI (video and sound), MP3 (soound),
MPG (video and sound) ),
there are some problems with getting notifications about finishing MP3
playing: when OnNotify is called, State returned is mpPlaying yet. For
that case I can advice to check also playing time and compare it with
Length of multimedia. }
property Width: Integer read FWidth;
{* Default width of video display (for multimedia, having video animation). }
property Height: Integer read FHeight;
{* Default height of video display (for multimedia, having video animation). }
function Open: Boolean;
{* Call this method to open device, which is not correspondent to file. For
multimedia, stored in file, Open is called automatically when FileName
property is changed.
|<br>
Multimedia is always trying to be open shareable first. If it is not
possible, second attempt is made to open multimedia without sharing. }
property Alias: String read FAlias write FAlias;
{* Alias for opened device. Must be set before opening (before changing
FileName). }
function Play( StartPos, PlayLength: Integer ): Boolean;
{* Call this method to play multimedia. StartPos is relative to
starting position of opened multimedia, even if it has tracks. If value
passed for StartPos is -1, current position is used to start from.
If -1 passed as PlayLength, multimedia is playing to the end of media.
Note, that after some operation (including Play) current position is
moved and it is necessary to pass 0 as StartPos to play multimedia
from its starting position again. To provide playing the same
multimedia several times, call:
! with MyMediaPlayer do
! Play( 0, -1 );
To Play single track, call:
! with MyMediaPlayer do
! begin
! Track := N; // set track to desired number
! Play( TrackStartPosition, TrackLength );
! end; }
procedure Close;
{* Closes multimedia. Later it can be reopened using Open method. Please
remember, that if CDAudio (e.g.) is playing, it is not stop playing
when Close is called. To stop playing, first perform command
! Pause := True; }
procedure Eject;
{* Ejects media from device. It is possible to check first, if this operation
is supported by the device - see CanEject. }
procedure DoorClose;
{* Backward operation to Eject - inserts media to device. This operation is
very easy and does not take in consideration if CD data / audio is playing
automatically when media is inserted. To prevent launching CD player or
application, defined in autostart.inf file in rootof CD, use Insert method
instead. }
procedure DisableAutoPlay;
{* Be careful when using this method - this affects user settings such as 'Autoplay
CD audio disk' and 'Autorun CD Data disk'. At least do not forget to restore
settings later, using RestoreAutoPlay method. When You use Insert method
to insert CD into device, DisableAutoPlay also is called, but in that case
restoring is made automatically at least when TMediaPlayer object is
destroying. }
procedure RestoreAutoPlay;
{* Restores settings CD autoplay settings, changed by calling DisableAutoPlay
method (which must be called earlier to save settings and change it to
disable CD autoplay feature). It is not necessary to call RestoreAutoPlay
only in case, when method Insert was used to insert CD into device (but
calling it restores settings therefore - so it is possible to restore
settings not only when object TMediaPlayer destroyed, but earlier. }
procedure Insert;
{* Does the same as DoorClose, but first disables auto play settings, preventing
system from running application defined in Autorun.inf (in CD root) or
launching CD player application. Such settings will be restored at least
when TMediaPlayer object is destroyed, but it is possible to call
RestoreAutoPlay earlier (but there is no sence to call it immediately
after performing Insert method - at least wait several seconds or start
playing track first). }
function Save( const aFileName: String ): Boolean;
{* Saves multimedia to a file. Check first, if this operation is supported
by device. }
property Ready: Boolean index MCI_STATUS_READY read GetBState;
{* True if Device is ready. }
function StartRecording( FromPos, ToPos: Integer ): Boolean;
{* Starts recording. If FromPos is passed -1, recording is starting from
current position. If ToPos is passed -1, recording is continuing up
to the end of media. }
function Stop: Boolean;
{* Stops playing back or recording. }
property IsCompoundDevice: Boolean index MCI_GETDEVCAPS_COMPOUND_DEVICE read GetCapability;
{* True, if device is compound. }
property HasVideo: Boolean index MCI_GETDEVCAPS_HAS_VIDEO read GetCapability;
{* True, if multimedia has videoanimation. }
property HasAudio: Boolean index MCI_GETDEVCAPS_HAS_AUDIO read GetCapability;
{* True, if multimedia contains audio. }
property CanEject: Boolean index MCI_GETDEVCAPS_CAN_EJECT read GetCapability;
{* True, if device supports "open door" and "close door" operations. }
property CanPlay: Boolean index MCI_GETDEVCAPS_CAN_PLAY read GetCapability;
{* True, if multimedia can be played (some of deviceces are only for recording,
not for playing). }
property CanRecord: Boolean index MCI_GETDEVCAPS_CAN_RECORD read GetCapability;
{* True, if multimedia can be used to record (video or/and audio). }
property CanSave: Boolean index MCI_GETDEVCAPS_CAN_SAVE read GetCapability;
{* True, if multimedia device supports saving to a file. }
property Present: Boolean index MCI_STATUS_MEDIA_PRESENT read GetBState;
{* True, if CD or videodisc inserted into device. }
property AudioOn[ Chn: TSoundChannels ]: Boolean read GetAudioOn write SetAudioOn;
{* Returns True, if given audio channels (both if [chLeft,chRight], any if [])
are "on". This property also allows to turn desired channels on and off. }
property VideoOn: Boolean read GetVideoOn write SetVideoOn;
{* Returns True, if video is "on". Allows to turn video signal on and off. }
//-- for "CDAudio" only:
property CDTrackNotAudio: Boolean index $80000000 or MCI_CDA_STATUS_TYPE_TRACK read GetBState;
{* True, if current Track is not audio. }
//-- for "digitalvideo":
property DGV_CanFreeze: Boolean index $4002 {MCI_DGV_GETDEVCAPS_CAN_FREEZE} read GetCapability;
{* True, if can freeze. }
property DGV_CanLock: Boolean index $4000 {MCI_DGV_GETDEVCAPS_CAN_LOCK} read GetCapability;
{* True, if can lock. }
property DGV_CanReverse: Boolean index $4004 {MCI_DGV_GETDEVCAPS_CAN_REVERSE} read GetCapability;
{* True, if can reverse playing. }
property DGV_CanStretchInput: Boolean index $4008 {MCI_DGV_GETDEVCAPS_CAN_STR_IN} read GetCapability;
{* True, if can stretch input. }
property DGV_CanStretch: Boolean index $4001 {MCI_DGV_GETDEVCAPS_CAN_STRETCH} read GetCapability;
{* True, if can stretch output. }
property DGV_CanTest: Boolean index $4009 {MCI_DGV_GETDEVCAPS_CAN_TEST} read GetCapability;
{* True, if supports Test. }
property DGV_HasStill: Boolean index $4005 {MCI_DGV_GETDEVCAPS_HAS_STILL} read GetCapability;
{* True, if has still images in video. }
property DGV_MaxWindows: Integer index $4003 {MCI_DGV_GETDEVCAPS_MAX_WINDOWS} read GetICapability;
{* Returns maximum windows supported. }
property DGV_MaxRate: Integer index $400A {MCI_DGV_GETDEVCAPS_MAXIMUM_RATE} read GetICapability;
{* Returns maximum possible rate (frames/sec). }
property DGV_MinRate: Integer index $400B {MCI_DGV_GETDEVCAPS_MINIMUM_RATE} read GetICapability;
{* Returns minimum possible rate (frames/sec). }
property DGV_Speed: Integer read DGVGetSpeed write DGVSetSpeed;
{* Returns speed of digital video as a ratio between the nominal frame
rate and the desired frame rate where the nominal frame rate is designated
as 1000. Half speed is 500 and double speed is 2000. The allowable speed
range is dependent on the device and possibly the file, too. }
//-- for AVI only (mmDigitalVideo, AVI-format):
property AVI_AudioBreaks: Integer index $8003 {MCI_AVI_STATUS_AUDIO_BREAKS} read GetIState;
{* Returns the number of times that the audio definitely broke up.
(We count one for every time we're about to write some audio data
to the driver, and we notice that it's already played all of the
data we have). }
property AVI_FramesSkipped: Integer index $8001 {MCI_AVI_STATUS_FRAMES_SKIPPED} read GetIState;
{* Returns number of frames not drawn during last play. If this number
is more than a small fraction of the number of frames that should have
been displayed, things aren't looking good. }
property AVI_LastPlaySpeed: Integer index $8002 {MCI_AVI_STATUS_LAST_PLAY_SPEED} read GetIState;
{* Returns a number representing how well the last AVI play worked.
A result of 1000 indicates that the AVI sequence took the amount
of time to play that it should have; a result of 2000, for instance,
would indicate that a 5-second AVI sequence took 10 seconds to play,
implying that the audio and video were badly broken up. }
//-- for "vcr" (video cassete recorder):
property VCR_ClockIncrementRate: Integer index $401C {MCI_VCR_GETDEVCAPS_CLOCK_INCREMENT_RATE} read GetICapability;
{* }
property VCR_CanDetectLength: Boolean index $4001 {MCI_VCR_GETDEVCAPS_CAN_DETECT_LENGTH} read GetCapability;
{* True, if can detect Length. }
property VCR_CanFreeze: Boolean index $401B {MCI_VCR_GETDEVCAPS_CAN_FREEZE} read GetCapability;
{* True, if supports command "freeze". }
property VCR_CanMonitorSources: Boolean index $4009 {MCI_VCR_GETDEVCAPS_CAN_MONITOR_SOURCES} read GetCapability;
{* True, if can monitor sources. }
property VCR_CanPreRoll: Boolean index $4007 {MCI_VCR_GETDEVCAPS_CAN_PREROLL} read GetCapability;
{* True, if can preroll. }
property VCR_CanPreview: Boolean index $4008 {MCI_VCR_GETDEVCAPS_CAN_PREVIEW} read GetCapability;
{* True, if can preview. }
property VCR_CanReverse: Boolean index $4004 {MCI_VCR_GETDEVCAPS_CAN_REVERSE} read GetCapability;
{* True, if can play in reverse direction. }
property VCR_CanTest: Boolean index $4006 {MCI_VCR_GETDEVCAPS_CAN_TEST} read GetCapability;
{* True, if can test. }
property VCR_HasClock: Boolean index $4003 {MCI_VCR_GETDEVCAPS_HAS_CLOCK} read GetCapability;
{* True, if has clock. }
property VCR_HasTimeCode: Boolean index $400A {MCI_VCR_GETDEVCAPS_HAS_TIMECODE} read GetCapability;
{* True, if has time code. }
property VCR_NumberOfMarks: Integer index $4005 {MCI_VCR_GETDEVCAPS_NUMBER_OF_MARKS} read GetICapability;
{* Returns number of marks. }
property VCR_SeekAccuracy: Integer index $4002 {MCI_VCR_GETDEVCAPS_SEEK_ACCURACY} read GetICapability;
{* Returns seek accuracy. }
//-- for mmWaveAudio:
property Wave_AvgBytesPerSecond: Integer index $4004 {MCI_WAVE_STATUS_AVGBYTESPERSEC} read GetIState;
{* Returns current bytes per second used for playing, recording, and saving. }
property Wave_BitsPerSample: Integer index $4006 {MCI_WAVE_STATUS_BITSPERSAMPLE} read GetIState;
{* Returns current bits per sample used for playing, recording, and saving PCM formatted data. }
property Wave_SamplesPerSecond: Integer index $4003 {MCI_WAVE_STATUS_SAMPLESPERSEC} read GetIState;
{* Returns current samples per second used for playing, recording, and saving. }
function SendCommand( Cmd, Flags: Integer; Buffer: Pointer ): Integer;
{* Low level access to a device. To get knoq how to use it, see sources. }
{$IFNDEF _FPC}
function asmSendCommand( Flags, Cmd: Integer {;var Buffer in stack} ): Integer;
{* Assembler version of SendCommand - only for advanced programmers. It
can be called from assembler only, and last parameter (but without
first member of the structure, dwCallback) must be placed
to stack just before calling asmSendCommand. Also, @Self must be
placed already in EBX, second parameter (Cmd) in EDX, and third (Flags)
in EAX. This method also retirns error code (0, if success), and
additionally ZF flag set if success. }
{$ENDIF}
{$IFDEF USE_CONSTRUCTORS}
constructor CreateMediaPlayer( const AFileName: String; AWindow: HWND );
{$ENDIF USE_CONSTRUCTORS}
end;
var MediaPlayers: PList;
function NewMediaPlayer( const FileName: String; Window: HWND ): PMediaPlayer;
{* Creates TMediaPlayer instance. If FileName is not empty string, file is opening
immediately. }
type
TPlayOption = ( poLoop, poWait, poNoStopAnotherSound, poNotImportant );
{* Options to play sound. poLoop, when sound is playing back repeatedly until
PlaySoundStop called. poWait, if sound is playing synchronously (i.e. control
returns to application after the sound event completed). poNoStopAnotherSound
means that another sound playing can not be stopped to free resources needed to
play requested sound. poNotImportant means that if driver busy, function
will return immediately returning False (with no sound playing). }
TPlayOptions = set of TPlayOption;
{* Options, available to play sound from memory or resource or to play standard
sound event using PlaySoundMemory, PlaySoundResourceID, PlaySoundResourceName,
PlaySoundEvent. }
function PlaySoundMemory( Memory: Pointer; Options: TPlayOptions ): Boolean;
{* Call it to play sound already stored in memory. (It is possible to preload
sound from resource (e.g., using Resurce2Stream function) or to load sound from
file. }
function PlaySoundResourceID( Inst, ResID: Integer; Options: TPlayOptions ): Boolean;
{* Call it to play sound, stored in resource. It is also possible to stop playing
certain sound, asynchronously playing from a resource, using PlaySoundStopResID.
|<br>
In this implementation, sound is played from memory and always with poWait
option turned on (i.e. synchronously). }
function PlaySoundResourceName( Inst: Integer; const ResName: String; Options: TPlayOptions ): Boolean;
{* Call it to play sound, stored in (named) resource. It is also possible to stop
playing certain sound, asynchronously playing from a resource, using
PlaySoundStopResName.
|<br>
In this implementation, sound is played from memory and always with poWait
option turned on (i.e. synchronously). }
function PlaySoundEvent( const EventName: String; Options: TPlayOptions ): Boolean;
{* Call it to play standard event sound. E.g., 'SystemAsterisk', 'SystemExclamation',
'SystemExit', 'SystemHand', 'SystemQuestion', 'SystemStart' sounds are defined
for all Win32 implementations. }
function PlaySoundFile( const FileName: String; Options: TPlayOptions ): Boolean;
{* Call it to play waveform audio file. (This also can be done using
TMediaPlayer, but for wide set of audio and video formats). }
function PlaySoundStop: Boolean;
{* Call it to stop playing sounds, which are yet playing (after calling
PlaySountXXXXX functions above to play sounds asynchronously). }
function WaveOutChannels( DevID: Integer ): TSoundChannels;
{* Returns available sound output channels for given wave out device. Pass
-1 (or WAVE_MAPPER) to get channels for wave mapper. If only mono
output available, [ chLeft ] is returned. }
function WaveOutVolume( DevID: Integer; Chn: TSoundChannel; NewValue: Integer ): Word;
{* Sets volume for given channel. If NewValue = -1 passed, new value is not set.
Always returns current volume level for a channel (if successful). Volume varies
in diapason 0..65535. If passed value > 65535, low word of NewValue is used
to set both chLeft and chRight channels. }
implementation
type
{++}(*TControl1 = class;*){--}
PControl1 = {-}^{+}TControl1;
TControl1 = object( TControl )
end;
{$G+}
////////////////////////////////////////////////////////////////////////
//
//
// M P L A Y E R
//
//
////////////////////////////////////////////////////////////////////////
{ -- TMediaPlayer -- }
{$IFDEF USE_CONSTRUCTORS}
function NewMediaPlayer( const FileName: String; Window: HWND ): PMediaPlayer;
begin
new( Result, CreateMediaPlayer( FileName, Window ) );
end;
{$ELSE not_USE_CONSTRUCTORS}
{$IFDEF ASM_VERSION}
function _NewMediaPlayer: PMediaPlayer;
begin
New( Result, Create );
end;
function NewMediaPlayer( const FileName: String; Window: HWND ): PMediaPlayer;
asm
PUSH EBX
PUSH EDX
PUSH EAX
CALL _NewMediaPlayer
XCHG EBX, EAX
MOV ECX, [MediaPlayers]
INC ECX
LOOP @@ListCreated
CALL NewList
MOV [MediaPlayers], EAX
XCHG ECX, EAX
@@ListCreated:
XCHG EAX, ECX
MOV EDX, EBX
CALL TList.Add
POP EDX
MOV EAX, EBX
CALL TMediaPlayer.SetFileName
POP ECX
MOV EDX, [EBX].TMediaPlayer.FError
TEST EDX, EDX
JNZ @@exit
PUSH ECX
MOV EAX, EBX
MOV DL, MCI_GETDEVCAPS_HAS_VIDEO //$3
CALL TMediaPlayer.GetCapability
TEST AL, AL
JZ @@noVideo
POP EDX
PUSH EDX
MOV EAX, EBX
CALL TMediaPlayer.SetDisplay
@@noVideo:
POP [EBX].TMediaPlayer.FDisplay
@@exit:
XCHG EAX, EBX
POP EBX
end;
{$ELSE ASM_VERSION} //Pascal
function NewMediaPlayer( const FileName: String; Window: HWND ): PMediaPlayer;
begin
{#If not[OBJECTS]}
{-}
New( Result, Create );
{+}{++}(*Result := PMediaPlayer.Create;*){--}
{#End not[OBJECTS]}
if MediaPlayers = nil then
MediaPlayers := NewList;
MediaPlayers.Add( Result );
//Result.FTimeFormat := tfMilliseconds; //by default...
Result.FileName := FileName;
if Result.FError <> 0 then
//MsgOK( 'Error #' + Int2Str( Result.Error ) + ' when opening multimedia:'#13 +
// Result.ErrorMessage )
else
begin
if Result.HasVideo then
Result.Display := Window;
Result.FDisplay := Window;
end;
end;
{$ENDIF ASM_VERSION}
{$ENDIF USE_CONSTRUCTORS}
{$IFDEF ASM_VERSION}
procedure MMNotifyProc( var Msg: TMsg );
asm
PUSH EBX
XCHG EBX, EAX
PUSH ESI
PUSH EDI
MOV EDX, [MediaPlayers]
TEST EDX, EDX
JZ @@fin
MOV ECX, [EDX].TList.FCount
MOV ESI, [EDX].TList.FItems
MOV EDI, [EBX].TMsg.lParam
@@loo:
LODSD
CMP [EAX].TMediaPlayer.FDeviceID, EDI
JNZ @@nxt
MOV ECX, [EAX].TMediaPlayer.fOnNotify.TMethod.Code
JECXZ @@fin
MOV EDI, ECX
XCHG EDX, EAX
MOV EAX, [EDX].TMediaPlayer.fOnNotify.TMethod.Data
MOV ECX, [EBX].TMsg.wParam
DEC ECX
CALL EDI
JMP @@fin
@@nxt:
LOOP @@loo
@@fin:
POP EDI
POP ESI
POP EBX
end;
{$ELSE ASM_VERSION} //Pascal
procedure MMNotifyProc( var Msg: TMsg );
var I: Integer;
MP: PMediaPlayer;
begin
if MediaPlayers <> nil then
for I := 0 to MediaPlayers.Count - 1 do
begin
MP := MediaPlayers.Items[ I ];
if MP.FDeviceID = Msg.lParam then
begin
if Assigned( MP.fOnNotify ) then
MP.FOnNotify( MP, TMPNotifyValue( Msg.wParam - 1 ) );
break;
end;
end;
end;
{$ENDIF ASM_VERSION}
{ TMediaPlayer }
{$IFDEF ASM_VERSION}
procedure TMediaPlayer.Close;
asm
MOV ECX, [EAX].FDeviceID
JECXZ @@exit
PUSH EBX
XCHG EBX, EAX
//PUSH EAX
XOR EAX, EAX
INC EAX // EAX = MCI_NOTIFY
CDQ
MOV DX, MCI_CLOSE
CALL asmSendCommand
//TEST EAX, EAX
JNZ @@1
MOV [EBX].FDeviceID, EAX
@@1:
//POP ECX
POP EBX
@@exit:
end;
{$ELSE ASM_VERSION} //Pascal
procedure TMediaPlayer.Close;
var GenParm: TMCI_Generic_Parms;
begin
if FDeviceID = 0 then Exit;
GenParm.dwCallback := 0;
//if SendCommand( MCI_CLOSE, MCI_NOTIFY, @GenParm ) = 0 then
if SendCommand( MCI_CLOSE, MCI_WAIT, @GenParm ) = 0 then
FDeviceID := 0;
end;
{$ENDIF ASM_VERSION}
{$IFDEF ASM_noVERSION}
destructor TMediaPlayer.Destroy;
asm
PUSH EBX
MOV EBX, EAX
MOV [EBX].FWait, 1
XOR EDX, EDX
MOV [EBX].FOnNotify.TMethod.Code, EDX
CALL Close
MOV EAX, [MediaPlayers]
PUSH EAX
MOV EDX, EBX
CALL TList.IndexOf
XCHG EDX, EAX
POP EAX
PUSH EAX
PUSH [EAX].TList.fCount
CALL TList.Delete
POP ECX
POP EAX
LOOP @@1
MOV [MediaPlayers], ECX
CALL TObj.Free
@@1:
MOV ECX, [EBX].FAutoRestore.TMethod.Code
JECXZ @@2
MOV EAX, EBX
CALL ECX
@@2:
LEA EAX, [EBX].FFileName
CALL System.@LStrClr
LEA EAX, [EBX].FoldKeyValCDAudio
CALL System.@LStrClr
XCHG EAX, EBX
CALL TObj.Destroy
POP EBX
end;
{$ELSE ASM_VERSION} //Pascal
destructor TMediaPlayer.Destroy;
var I: Integer;
begin
FWait := True;
FOnNotify := nil;
I := MediaPlayers.IndexOf( @Self );
if I >= 0 then
begin
Close;
MediaPlayers.Delete( I );
end;
if MediaPlayers.Count = 0 then
begin
MediaPlayers.Free;
MediaPlayers := nil;
end;
if Assigned( FAutoRestore ) then
FAutoRestore;
FFileName := '';
FoldKeyValCDAudio := '';
inherited;
end;
{$ENDIF ASM_VERSION}
{$IFDEF ASM_VERSION}
procedure TMediaPlayer.DoorClose;
asm
PUSH EBX
XCHG EBX, EAX
PUSH ECX // dwAudio
PUSH ECX // dwTimeFormat
//PUSH ECX // dwCallback
XOR EAX, EAX
MOV AX, MCI_SET_DOOR_CLOSED or MCI_NOTIFY // $201
CDQ
MOV DX, MCI_SET // $80D
CALL asmSendCommand
//POP ECX
POP ECX
POP ECX
POP EBX
end;
{$ELSE ASM_VERSION} //Pascal
procedure TMediaPlayer.DoorClose;
var SetParm: TMCI_Set_Parms;
begin
Assert( (FDeviceID = 0) or CanEject, 'Device not support door close operation' );
SendCommand( MCI_SET, MCI_SET_DOOR_CLOSED or MCI_NOTIFY, @SetParm );
end;
{$ENDIF ASM_VERSION}
{$IFDEF ASM_VERSION}
procedure TMediaPlayer.Eject;
asm
PUSH EBX
XCHG EBX, EAX
PUSH ECX // dwAudio
PUSH ECX // dwTimeFormat
//PUSH ECX // dwCallback
XOR EAX, EAX
MOV AX, MCI_SET_DOOR_OPEN or MCI_NOTIFY // $101
CDQ
MOV DX, MCI_SET // $80D
CALL asmSendCommand
//POP ECX
POP ECX
POP ECX
POP EBX
end;
{$ELSE ASM_VERSION} //Pascal
procedure TMediaPlayer.Eject;
var SetParm: TMCI_Set_Parms;
begin
Assert( (FDeviceID = 0) or CanEject, 'Device not support eject' );
SendCommand( MCI_SET, MCI_SET_DOOR_OPEN or MCI_NOTIFY, @SetParm );
end;
{$ENDIF ASM_VERSION}
{$IFDEF ASM_VERSION}
function TMediaPlayer.GetCapability( const Index: Integer ): Boolean;
asm
CALL GetICapability
{$IFDEF PARANOIA}
DB $24, $01
{$ELSE}
AND AL, 1
{$ENDIF}
end;
{$ELSE ASM_VERSION} //Pascal
function TMediaPlayer.GetCapability( const Index: Integer ): Boolean;
begin
Result := Boolean( GetICapability( Index ) );
end;
{$ENDIF ASM_VERSION}
{$IFDEF ASM_VERSION}
function TMediaPlayer.GetICapability(const Index: Integer): Integer;
asm
PUSH EBX
XCHG EBX, EAX
MOV EAX, [EBX].FDeviceID
TEST EAX, EAX
JZ @@exit
PUSH EDX // dwItem := Index
PUSH ECX // dwReturn
//PUSH ECX // dwCallback
XOR EAX, EAX
MOV AX, MCI_WAIT or MCI_GETDEVCAPS_ITEM // $102
CDQ
MOV DX, MCI_GETDEVCAPS // $80B
CALL asmSendCommand
//POP ECX // dwCallback
POP EDX // dwReturn
POP ECX // dwItem
//TEST EAX, EAX
JZ @@retEDX
XOR EDX, EDX
@@retEDX:
XCHG EAX, EDX // Result := dwRetirn
@@exit:
POP EBX
end;
{$ELSE ASM_VERSION} //Pascal
function TMediaPlayer.GetICapability(const Index: Integer): Integer;
var DevCapParm: TMCI_GetDevCaps_Parms;
begin
Result := 0;
if FDeviceID <> 0 then
begin
DevCapParm.dwItem := Index;
if SendCommand( MCI_GETDEVCAPS, MCI_WAIT or MCI_GETDEVCAPS_ITEM, @DevCapParm ) = 0 then
Result := DevCapParm.dwReturn;
end;
end;
{$ENDIF ASM_VERSION}
{$IFDEF ASM_VERSION}
function TMediaPlayer.GetDeviceType: TMPDeviceType;
asm
XOR EDX, EDX
MOV DL, MCI_GETDEVCAPS_DEVICE_TYPE // $4
CALL GetICapability
end;
{$ELSE ASM_VERSION} //Pascal
function TMediaPlayer.GetDeviceType: TMPDeviceType;
begin
Result := TMPDeviceType( GetICapability( MCI_GETDEVCAPS_DEVICE_TYPE ) { - 512 } );
end;
{$ENDIF ASM_VERSION}
{$IFDEF ASM_VERSION}
function TMediaPlayer.GetDisplayRect: TRect;
asm
PUSH EBX
XCHG EBX, EAX
PUSH EDI
MOV EDI, EDX
MOV EAX, MCI_ANIM_WHERE_DESTINATION // $40000
CDQ
PUSH EDX
PUSH EDX
PUSH EDX
PUSH EDX // rc = (0,0,0,0)
//PUSH ECX // dwCallback
MOV DX, MCI_WHERE or MCI_WAIT // $843
CALL asmSendCommand
//POP ECX // dwCallback
JZ @@success
MOV EDI, ESP
@@success:
POP [EDI].TRect.Left
POP [EDI].TRect.Top
POP [EDI].TRect.Right
POP [EDI].TRect.Bottom
POP EDI
POP EBX
end;
{$ELSE ASM_VERSION} //Pascal
function TMediaPlayer.GetDisplayRect: TRect;
var RectParms: TMCI_Anim_Rect_Parms;
begin
Result := MakeRect( 0, 0, 0, 0 );
//if HasVideo then
if SendCommand( MCI_WHERE, MCI_ANIM_WHERE_DESTINATION or MCI_WAIT, @RectParms ) = 0 then
Result := RectParms.rc;
end;
{$ENDIF ASM_VERSION}
{$IFDEF ASM_VERSION}
procedure TMediaPlayer.SetDisplayRect(const Value: TRect);
asm
PUSH EBX
XCHG EBX, EAX
MOV ECX, [EDX].TRect.Right
OR ECX, [EDX].TRect.Bottom
JNZ @@passValue
MOV EAX, [EBX].FHeight
ADD EAX, [EDX].TRect.Top
PUSH EAX // rc.Bottom
MOV EAX, [EBX].FWidth
ADD EAX, [EDX].TRect.Left
PUSH EAX // rc.Right
JMP @@1
@@passValue:
PUSH [EDX].TRect.Bottom
PUSH [EDX].TRect.Right
@@1:
PUSH [EDX].TRect.Top
PUSH [EDX].TRect.Left
//PUSH ECX // dwCallback
MOV EAX, MCI_ANIM_RECT or MCI_ANIM_PUT_DESTINATION or MCI_WAIT
CDQ
MOV DX, MCI_PUT
CALL asmSendCommand
ADD ESP, 16
POP EBX
end;
{$ELSE ASM_VERSION} //Pascal
procedure TMediaPlayer.SetDisplayRect(const Value: TRect);
var RectParms: TMCI_Anim_Rect_Parms;
begin
if (Value.Bottom = 0) and (Value.Right = 0) then
begin
{special case, use default width and height}
with Value do
RectParms.rc := MakeRect(Left, Top, Left+FWidth, Top+FHeight);
end
else RectParms.rc := Value;
SendCommand( MCI_PUT, MCI_ANIM_RECT or MCI_ANIM_PUT_DESTINATION or MCI_WAIT,
@RectParms );
end;
{$ENDIF ASM_VERSION}
{$IFDEF ASM_VERSION}
function TMediaPlayer.GetErrorMessage: String;
asm
ADD ESP, -1024
MOV ECX, ESP
PUSH EDX
PUSH 1024
PUSH ECX
PUSH [EAX].FError
CALL mciGetErrorString
POP EDX // EDX = @Result
TEST EAX, EAX
JNZ @@1
POP ECX
PUSH EAX
@@1:
XCHG EAX, EDX
MOV EDX, ESP
CALL System.@LStrFromPChar
ADD ESP, 1024
end;
{$ELSE ASM_VERSION} //Pascal
function TMediaPlayer.GetErrorMessage: String;
var
ErrMsg: array[0..1023{129 - in win32.hlp, 128 bytes are always sufficient, but...}] of Char;
begin
if not mciGetErrorString(FError, ErrMsg, SizeOf(ErrMsg)) then
ErrMsg[ 0 ] := #0;
Result := ErrMsg;
end;
{$ENDIF ASM_VERSION}
{$IFDEF ASM_VERSION}
function TMediaPlayer.GetState: TMPState;
asm
XOR EDX, EDX
MOV DL, MCI_STATUS_MODE // $4
CALL GetIState
{$IFDEF PARANOIA}
DB $2C, $0C
{$ELSE}
SUB AL, 12
{$ENDIF}
end;
{$ELSE ASM_VERSION} //Pascal
function TMediaPlayer.GetState: TMPState;
begin
Result := TMPState( GetIState( MCI_STATUS_MODE ) - 524 );
end;
{$ENDIF ASM_VERSION}
{$IFDEF ASM_noVERSION} //alias
function TMediaPlayer.Open: Boolean;
asm
MOV [FMMNotify], offset[MMNotifyProc]
PUSH EBX
PUSH ESI
XCHG EBX, EAX
MOV ECX, [EBX].FDeviceID