-
Notifications
You must be signed in to change notification settings - Fork 14
/
FmxPasLibVlcPlayerUnit.pas
3815 lines (3291 loc) · 114 KB
/
FmxPasLibVlcPlayerUnit.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
(*
*******************************************************************************
* FmxPasLibVlcPlayerUnit.pas - FMX component for VideoLAN libvlc 3.0.5
*
* See copyright notice below.
*
* Last modified: 2019.03.24
*
* author: Robert Jędrzejczyk
* e-mail: [email protected]
* www: http://prog.olsztyn.pl/paslibvlc
*
*
* See FmxPasLibVlcPlayerUnit.txt for change log
*
*******************************************************************************
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Any non-GPL usage of this software or parts of this software is strictly
* forbidden.
*
* The "appropriate copyright message" mentioned in section 2c of the GPLv2
* must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
*
*******************************************************************************
*
* libvlc is part of project VideoLAN
*
* Copyright (c) 1996-2018 VideoLAN Team
*
* For more information about VideoLAN
*
* please visit http://www.videolan.org
*
*)
{$I compiler.inc}
unit FmxPasLibVlcPlayerUnit;
{$IFDEF DELPHI_XE7_UP}
{$ENDIF}
interface
uses
{$IFDEF UNIX} Unix, {$ENDIF}
{$IFDEF MSWINDOWS}Windows, {$ENDIF}
Classes, SysUtils, SyncObjs, FMX.Types, FMX.Objects, FMX.Graphics,
System.UITypes, PasLibVlcClassUnit, PasLibVlcUnit;
type
TFmxPasLibVlcPlayerState = (plvPlayer_NothingSpecial, plvPlayer_Opening, plvPlayer_Buffering, plvPlayer_Playing, plvPlayer_Paused, plvPlayer_Stopped, plvPlayer_Ended, plvPlayer_Error);
type
TNotifySeekableChanged = procedure(Sender: TObject; val: Boolean) of object;
TNotifyPausableChanged = procedure(Sender: TObject; val: Boolean) of object;
TNotifyTitleChanged = procedure(Sender: TObject; title: Integer) of object;
TNotifySnapshotTaken = procedure(Sender: TObject; fileName: string) of object;
TNotifyTimeChanged = procedure(Sender: TObject; time: Int64) of object;
TNotifyLengthChanged = procedure(Sender: TObject; time: Int64) of object;
TNotifyPositionChanged = procedure(Sender: TObject; position: Single) of object;
TNotifyMediaChanged = procedure(Sender: TObject; mrl: string) of object;
TNotifyVideoOutChanged = procedure(Sender: TObject; video_out: Integer) of object;
TNotifyScrambledChanged = procedure(Sender: TObject; scrambled: Integer) of object;
TNotifyPlayerEvent = procedure(p_event: libvlc_event_t_ptr; data: Pointer) of object;
TNotifyAudioVolumeChanged = procedure(Sender: TObject; volume: Single) of object;
TNotifyVideoSizeChanged = procedure(Sender: TObject; view_w, video_h, video_w_a32, video_h_a32: LongWord) of object;
TNotifyMediaPlayerEsAdded = procedure(Sender: TObject; i_type: libvlc_track_type_t; i_id: Integer) of object;
TNotifyMediaPlayerEsDeleted = procedure(Sender: TObject; i_type: libvlc_track_type_t; i_id: Integer) of object;
TNotifyMediaPlayerEsSelected = procedure(Sender: TObject; i_type: libvlc_track_type_t; i_id: Integer) of object;
TNotifyMediaPlayerAudioDevice = procedure(Sender: TObject; audio_device: string) of object;
TNotifyMediaPlayerChapterChanged = procedure(Sender: TObject; chapter: Integer) of object;
TNotifyRendererDiscoveredItemAdded = procedure(Sender: TObject; item: libvlc_renderer_item_t_ptr) of object;
TNotifyRendererDiscoveredItemDeleted = procedure(Sender: TObject; item: libvlc_renderer_item_t_ptr) of object;
type
TFmxPasLibVlcVideoCbCtx = class
vctx: TVideoCbCtx;
view: FMX.Objects.TImage;
frame_buff: Pointer;
frame_lock: TCriticalSection;
frame_pixel_format: TPixelFormat;
ForceAspectRatio: Single;
public
constructor Create(AView: FMX.Objects.TImage; aWidth: Integer = 320; aHeight: Integer = 160);
destructor Destroy; override;
end;
type
[ComponentPlatformsAttribute(pidWin32 or pidWin64 or pidOSX32)] // or pidiOSSimulator or pidAndroid or pidLinux32 or pidiOSDevice
TFmxPasLibVlcPlayer = class(FMX.Objects.TImage)
private
FVLC: TPasLibVlc;
p_mi: libvlc_media_player_t_ptr;
p_mi_ev_mgr: libvlc_event_manager_t_ptr;
FVideoCbCtx: TFmxPasLibVlcVideoCbCtx;
//
FError: string;
FMute: Boolean;
FVideoOutput: TVideoOutput;
FAudioOutput: TAudioOutput;
FTitleShow: Boolean;
FTitleShowPos: TPasLibVlcTitlePosition;
FTitleShowTimeOut: LongWord;
FSnapshotFmt: string;
FSnapshotPrv: Boolean;
FSpuShow: Boolean;
FOsdShow: Boolean;
FViewTeleText: Boolean;
FDeinterlaceFilter: TDeinterlaceFilter;
FDeinterlaceMode: TDeinterlaceMode;
FLastAudioOutput: WideString;
FLastAudioOutputDeviceId: WideString;
// events handlers
FOnMediaPlayerMediaChanged: TNotifyMediaChanged;
FOnMediaPlayerNothingSpecial: TNotifyEvent;
FOnMediaPlayerOpening: TNotifyEvent;
FOnMediaPlayerBuffering: TNotifyEvent;
FOnMediaPlayerPlaying: TNotifyEvent;
FOnMediaPlayerPaused: TNotifyEvent;
FOnMediaPlayerStopped: TNotifyEvent;
FOnMediaPlayerForward: TNotifyEvent;
FOnMediaPlayerBackward: TNotifyEvent;
FOnMediaPlayerEndReached: TNotifyEvent;
FOnMediaPlayerEncounteredError: TNotifyEvent;
FOnMediaPlayerTimeChanged: TNotifyTimeChanged;
FOnMediaPlayerPositionChanged: TNotifyPositionChanged;
FOnMediaPlayerSeekableChanged: TNotifySeekableChanged;
FOnMediaPlayerPausableChanged: TNotifyPausableChanged;
FOnMediaPlayerTitleChanged: TNotifyTitleChanged;
FOnMediaPlayerSnapshotTaken: TNotifySnapshotTaken;
FOnMediaPlayerLengthChanged: TNotifyLengthChanged;
FOnMediaPlayerVideoOutChanged: TNotifyVideoOutChanged;
FOnMediaPlayerScrambledChanged: TNotifyScrambledChanged;
FOnMediaPlayerEvent: TNotifyPlayerEvent;
FOnMediaPlayerCorked: TNotifyEvent;
FOnMediaPlayerUnCorked: TNotifyEvent;
FOnMediaPlayerMuted: TNotifyEvent;
FOnMediaPlayerUnMuted: TNotifyEvent;
FOnMediaPlayerAudioVolumeChanged: TNotifyAudioVolumeChanged;
FOnMediaPlayerVideoSizeChanged: TNotifyVideoSizeChanged;
FOnMediaPlayerEsAdded: TNotifyMediaPlayerEsAdded;
FOnMediaPlayerEsDeleted: TNotifyMediaPlayerEsDeleted;
FOnMediaPlayerEsSelected: TNotifyMediaPlayerEsSelected;
FOnMediaPlayerAudioDevice: TNotifyMediaPlayerAudioDevice;
FOnMediaPlayerChapterChanged: TNotifyMediaPlayerChapterChanged;
FOnRendererDiscoveredItemAdded: TNotifyRendererDiscoveredItemAdded;
FOnRendererDiscoveredItemDeleted: TNotifyRendererDiscoveredItemDeleted;
FUseEvents: boolean;
FStartOptions: TStringList;
FOnMediaPlayerSwitchPlay: TNotifyEvent;
FForceAspectRatio: Single;
function GetVlcInstance(): TPasLibVlc;
procedure SetStartOptions(Value: TStringList);
procedure SetSnapshotFmt(aFormat: string);
procedure SetSnapshotPrv(aValue: Boolean);
procedure SetSpuShow(aValue: Boolean);
procedure SetOsdShow(aValue: Boolean);
procedure SetViewTeleText(aValue: Boolean);
procedure SetTitleShow(aValue: Boolean);
procedure SetTitleShowPos(aValue: TPasLibVlcTitlePosition);
procedure SetTitleShowTimeOut(aValue: LongWord);
procedure SetDeinterlaceFilter(aValue: TDeinterlaceFilter);
procedure SetDeinterlaceMode(aValue: TDeinterlaceMode);
function GetDeinterlaceModeName(): WideString;
procedure InternalHandleEvent_MediaChanged(p_md: libvlc_media_t_ptr);
procedure InternalHandleEvent_NothingSpecial();
procedure InternalHandleEvent_Opening();
procedure InternalHandleEvent_Buffering();
procedure InternalHandleEvent_Playing();
procedure InternalHandleEvent_Paused();
procedure InternalHandleEvent_Stopped();
procedure InternalHandleEvent_Forward();
procedure InternalHandleEvent_Backward();
procedure InternalHandleEvent_EndReached();
procedure InternalHandleEvent_EncounteredError();
procedure InternalHandleEvent_TimeChanged(new_time: libvlc_time_t);
procedure InternalHandleEvent_PositionChanged(new_position: Single);
procedure InternalHandleEvent_SeekableChanged(new_seekable: Integer);
procedure InternalHandleEvent_PausableChanged(new_pausable: Integer);
procedure InternalHandleEvent_TitleChanged(new_title: Integer);
procedure InternalHandleEvent_SnapshotTaken(psz_filename: PAnsiChar);
procedure InternalHandleEvent_LengthChanged(new_length: libvlc_time_t);
procedure InternalHandleEvent_VOutChanged(new_count: Integer);
procedure InternalHandleEvent_ScrambledChanged(new_scrambled: Integer);
procedure InternalHandleEvent_Corked();
procedure InternalHandleEvent_UnCorked();
procedure InternalHandleEvent_Muted();
procedure InternalHandleEvent_UnMuted();
procedure InternalHandleEvent_AudioVolumeChanged(volume: Single);
procedure InternalHandleEvent_VideoSizeChanged(video_w, video_h, video_w_a32, video_h_a32: LongWord);
procedure InternalHandleEvent_MediaPlayerEsAdded(i_type: libvlc_track_type_t; i_id: Integer);
procedure InternalHandleEvent_MediaPlayerEsDeleted(i_type: libvlc_track_type_t; i_id: Integer);
procedure InternalHandleEvent_MediaPlayerEsSelected(i_type: libvlc_track_type_t; i_id: Integer);
procedure InternalHandleEvent_MediaPlayerAudioDevice(audio_device: PAnsiChar);
procedure InternalHandleEvent_MediaPlayerChapterChanged(chapter: Integer);
procedure InternalHandleEvent_RendererDiscoveredItemAdded(item: libvlc_renderer_item_t_ptr);
procedure InternalHandleEvent_RendererDiscoveredItemDeleted(item: libvlc_renderer_item_t_ptr);
procedure SetForceAspectRatio(const Value: Single);
function GetIsStopped: Boolean;
function GetIsEnded: Boolean;
protected
procedure DestroyPlayer();
procedure Paint; override;
procedure PlayContinue(audioOutput: WideString = ''; audioOutputDeviceId: WideString = ''; audioSetTimeOut: Cardinal = 1000); overload;
procedure PlayContinue(mediaOptions: array of WideString; audioOutput: WideString = ''; audioOutputDeviceId: WideString = ''; audioSetTimeOut: Cardinal = 1000); overload;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function GetPlayerHandle(): libvlc_media_player_t_ptr;
procedure Play(var media: TPasLibVlcMedia; audioOutput: WideString = ''; audioOutputDeviceId: WideString = ''; audioSetTimeOut: Cardinal = 1000); overload;
procedure Play(mrl: WideString; mediaOptions: array of WideString; audioOutput: WideString = ''; audioOutputDeviceId: WideString = ''; audioSetTimeOut: Cardinal = 1000); overload;
procedure Play(stm: TStream; mediaOptions: array of WideString; audioOutput: WideString = ''; audioOutputDeviceId: WideString = ''; audioSetTimeOut: Cardinal = 1000); overload;
procedure PlayNormal(mrl: WideString; mediaOptions: array of WideString; audioOutput: WideString = ''; audioOutputDeviceId: WideString = ''; audioSetTimeOut: Cardinal = 1000); overload;
procedure OpenNormal(mrl: WideString; audioOutput: WideString = ''; audioOutputDeviceId: WideString = ''; audioSetTimeOut: Cardinal = 1000); overload;
procedure PlayYoutube(mrl: WideString; mediaOptions: array of WideString; audioOutput: WideString = ''; audioOutputDeviceId: WideString = ''; audioSetTimeOut: Cardinal = 1000; youtubeTimeout: Cardinal = 10000); overload;
procedure Play(mrl: WideString; audioOutput: WideString = ''; audioOutputDeviceId: WideString = ''; audioSetTimeOut: Cardinal = 1000); overload;
procedure Play(stm: TStream; audioOutput: WideString = ''; audioOutputDeviceId: WideString = ''; audioSetTimeOut: Cardinal = 1000); overload;
procedure PlayNormal(mrl: WideString; audioOutput: WideString = ''; audioOutputDeviceId: WideString = ''; audioSetTimeOut: Cardinal = 1000); overload;
procedure PlayYoutube(mrl: WideString; audioOutput: WideString = ''; audioOutputDeviceId: WideString = ''; audioSetTimeOut: Cardinal = 1000; youtubeTimeout: Cardinal = 10000); overload;
function GetMediaMrl(): string;
procedure Pause();
procedure Resume();
function IsPlay(): Boolean;
function IsPause(): Boolean;
procedure Stop(const stopTimeOut: Cardinal = 1000);
function GetState(): TFmxPasLibVlcPlayerState;
function GetStateName(): string;
function CanPlay(): Boolean;
function CanPause(): Boolean;
function CanSeek(): Boolean;
function HasVout(): Boolean;
function IsScrambled(): Boolean;
function Snapshot(fileName: WideString): Boolean; overload;
function Snapshot(fileName: WideString; width, height: LongWord): Boolean; overload;
procedure NextFrame();
procedure SetPlayRate(rate: Integer);
function GetPlayRate(): Integer;
function GetVideoWidth(): LongInt;
function GetVideoHeight(): LongInt;
function GetVideoDimension(var width, height: LongWord): Boolean;
function GetVideoScaleInPercent(): Single;
function GetVideoAspectRatio(): string;
function GetVideoSampleAspectRatio(var sar_num, sar_den: Longword): Boolean; overload;
function GetVideoSampleAspectRatio(): Single; overload;
procedure SetVideoScaleInPercent(newScaleInPercent: Single);
procedure SetVideoAspectRatio(newAspectRatio: string);
function GetVideoLenInMs(): Int64;
function GetVideoPosInMs(): Int64;
function GetVideoPosInPercent(): Single;
function GetVideoFps(): Single;
procedure SetVideoPosInMs(newPos: Int64);
procedure SetVideoPosInPercent(newPos: Single);
function GetVideoLenStr(fmt: string = 'hh:mm:ss'): string;
function GetVideoPosStr(fmt: string = 'hh:mm:ss'): string;
procedure SetTeleText(page: Integer);
function GetTeleText(): Integer;
function ShowTeleText(): Boolean;
function HideTeleText(): Boolean;
function GetAudioMute(): Boolean;
procedure SetAudioMute(mute: Boolean);
function GetAudioVolume(): Integer;
procedure SetAudioVolume(volumeLevel: Integer);
function GetAudioChannel(): libvlc_audio_output_channel_t;
procedure SetAudioChannel(chanel: libvlc_audio_output_channel_t);
function GetAudioDelay(): Int64;
procedure SetAudioDelay(delay: Int64);
function GetAudioFilterList(return_name_type: Integer = 0): TStringList;
function GetVideoFilterList(return_name_type: Integer = 0): TStringList;
function GetAudioTrackList(): TStringList;
function GetAudioTrackCount(): Integer;
function GetAudioTrackId(): Integer;
procedure SetAudioTrackById(const track_id: Integer);
function GetAudioTrackNo(): Integer;
procedure SetAudioTrackByNo(track_no: Integer);
function GetAudioTrackDescriptionById(const track_id: Integer): WideString;
function GetAudioTrackDescriptionByNo(track_no: Integer): WideString;
function GetAudioOutputList(withDescription: Boolean = FALSE; separator: string = '|'): TStringList;
function GetAudioOutputDeviceList(aOut: WideString; withDescription: Boolean = FALSE; separator: string = '|'): TStringList;
function GetAudioOutputDeviceEnum(withDescription: Boolean = FALSE; separator: string = '|'): TStringList;
function SetAudioOutput(aOut: WideString): Boolean;
procedure SetAudioOutputDevice(aOut: WideString; aOutDeviceId: WideString); overload;
procedure SetAudioOutputDevice(aOutDeviceId: WideString); overload;
{$IFDEF USE_VLC_DEPRECATED_API}
function GetAudioOutputDeviceCount(aOut: WideString): Integer;
function GetAudioOutputDeviceId(aOut: WideString; deviceIdx: Integer): WideString;
function GetAudioOutputDeviceName(aOut: WideString; deviceIdx: Integer): WideString;
{$ENDIF}
function EqualizerGetPresetList(): TStringList;
function EqualizerGetBandCount(): unsigned_t;
function EqualizerGetBandFrequency(bandIndex: unsigned_t): Single;
function EqualizerCreate(APreset: unsigned_t = $FFFF): TPasLibVlcEqualizer;
procedure EqualizerApply(AEqualizer: TPasLibVlcEqualizer);
procedure EqualizerSetPreset(APreset: unsigned_t = $FFFF);
procedure SetVideoAdjustEnable(value: Boolean);
function GetVideoAdjustEnable(): Boolean;
procedure SetVideoAdjustContrast(value: Single = 1);
function GetVideoAdjustContrast(): Single;
procedure SetVideoAdjustBrightness(value: Single = 1);
function GetVideoAdjustBrightness(): Single;
procedure SetVideoAdjustHue(value: Integer = 0);
function GetVideoAdjustHue(): Integer;
procedure SetVideoAdjustSaturation(value: Single = 1);
function GetVideoAdjustSaturation(): Single;
procedure SetVideoAdjustGamma(value: Single = 1);
function GetVideoAdjustGamma(): Single;
function GetVideoChapter(): Integer;
procedure SetVideoChapter(newChapter: Integer);
function GetVideoChapterCount(): Integer;
function GetVideoChapterCountByTitleId(const title_id: Integer): Integer;
function GetVideoSubtitleList(): TStringList;
function GetVideoSubtitleCount(): Integer;
function GetVideoSubtitleId(): Integer;
procedure SetVideoSubtitleById(const subtitle_id: Integer);
function GetVideoSubtitleNo(): Integer;
procedure SetVideoSubtitleByNo(subtitle_no: Integer);
function GetVideoSubtitleDescriptionById(const subtitle_id: Integer): WideString;
function GetVideoSubtitleDescriptionByNo(subtitle_no: Integer): WideString;
procedure SetVideoSubtitleFile(subtitle_file: WideString);
function GetVideoTitleList(): TStringList;
function GetVideoTitleCount(): Integer;
function GetVideoTitleId(): Integer;
procedure SetVideoTitleById(const title_id: Integer);
function GetVideoTitleNo(): Integer;
procedure SetVideoTitleByNo(title_no: Integer);
function GetVideoTitleDescriptionById(const track_id: Integer): WideString;
function GetVideoTitleDescriptionByNo(title_no: Integer): WideString;
// https://wiki.videolan.org/Documentation:Modules/logo/
procedure LogoSetFile(file_name: WideString);
procedure LogoSetFiles(file_names: array of WideString; delay_ms: Integer = 1000; loop: Boolean = TRUE);
procedure LogoSetPosition(position_x, position_y: Integer); overload;
procedure LogoSetPosition(position: libvlc_position_t); overload;
procedure LogoSetOpacity(opacity: libvlc_opacity_t);
procedure LogoSetDelay(delay_ms: Integer = 1000); // delay before show next logo file, default 1000
procedure LogoSetRepeat(loop: boolean = TRUE);
procedure LogoSetEnable(enable: Integer);
procedure LogoShowFile(file_name: WideString; position_x, position_y: Integer; opacity: libvlc_opacity_t = libvlc_opacity_full); overload;
procedure LogoShowFile(file_name: WideString; position: libvlc_position_t = libvlc_position_top; opacity: libvlc_opacity_t = libvlc_opacity_full); overload;
procedure LogoShowFiles(file_names: array of WideString; position_x, position_y: Integer; opacity: libvlc_opacity_t = libvlc_opacity_full; delay_ms: Integer = 1000; loop: Boolean = TRUE); overload;
procedure LogoShowFiles(file_names: array of WideString; position: libvlc_position_t = libvlc_position_top; opacity: libvlc_opacity_t = libvlc_opacity_full; delay_ms: Integer = 1000; loop: Boolean = TRUE); overload;
procedure LogoHide();
// https://wiki.videolan.org/Documentation:Modules/marq/
procedure MarqueeSetText(marquee_text: WideString);
procedure MarqueeSetPosition(position_x, position_y: Integer); overload;
procedure MarqueeSetPosition(position: libvlc_position_t); overload;
procedure MarqueeSetColor(color: libvlc_video_marquee_color_t);
procedure MarqueeSetFontSize(font_size: Integer);
procedure MarqueeSetOpacity(opacity: libvlc_opacity_t);
procedure MarqueeSetTimeOut(time_out_ms: Integer);
procedure MarqueeSetRefresh(refresh_after_ms: Integer);
procedure MarqueeSetEnable(enable: Integer);
procedure MarqueeShowText(marquee_text: WideString; position_x, position_y: Integer; color: libvlc_video_marquee_color_t = libvlc_video_marquee_color_White; font_size: Integer = libvlc_video_marquee_default_font_size; opacity: libvlc_opacity_t = libvlc_opacity_full; time_out_ms: Integer = 0); overload;
procedure MarqueeShowText(marquee_text: WideString; position: libvlc_position_t = libvlc_position_bottom; color: libvlc_video_marquee_color_t = libvlc_video_marquee_color_White; font_size: Integer = libvlc_video_marquee_default_font_size; opacity: libvlc_opacity_t = libvlc_opacity_full; time_out_ms: Integer = 0); overload;
procedure MarqueeHide();
procedure EventsDisable();
procedure EventsEnable();
procedure UpdateDeInterlace();
procedure UpdateTitleShow();
procedure SwitchPlay();
property VLC: TPasLibVlc read GetVlcInstance;
property Volume: Integer read GetAudioVolume write SetAudioVolume;
property Mute: Boolean read GetAudioMute write SetAudioMute;
property ForceAspectRatio: Single read FForceAspectRatio write SetForceAspectRatio;
property IsStopped: Boolean read GetIsStopped;
property IsEnded: Boolean read GetIsEnded;
published
property Align;
property PopupMenu;
property ShowHint;
property Visible;
property OnClick;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEnter;
property OnExit;
property OnMouseDown;
property OnMouseEnter;
property OnMouseLeave;
property OnMouseMove;
property OnMouseUp;
property OnResize;
property SpuShow: Boolean read FSpuShow write SetSpuShow default TRUE;
property OsdShow: Boolean read FOsdShow write SetOsdShow default TRUE;
property TitleShow: Boolean read FTitleShow write SetTitleShow default FALSE;
property TitleShowPos: TPasLibVlcTitlePosition read FTitleShowPos write SetTitleShowPos default plvPosCenter;
property TitleShowTimeOut: LongWord read FTitleShowTimeOut write SetTitleShowTimeOut default 2000;
property AudioOutput: TAudioOutput read FAudioOutput write FAudioOutput default aoDefault;
property VideoOutput: TVideoOutput read FVideoOutput write FVideoOutput default voDefault;
property SnapShotFmt: string read FSnapShotFmt write SetSnapshotFmt;
property SnapshotPrv: Boolean read FSnapShotPrv write SetSnapshotPrv default FALSE;
property DeinterlaceFilter: TDeinterlaceFilter read FDeinterlaceFilter write SetDeinterlaceFilter default deOFF;
property DeinterlaceModeName: WideString read GetDeinterlaceModeName;
property DeinterlaceMode: TDeinterlaceMode read FDeinterlaceMode write SetDeinterlaceMode default dmDISCARD;
property ViewTeletext: Boolean read FViewTeleText write SetViewTeleText default FALSE;
property LastError: string read FError write FError;
property StartOptions: TStringList read FStartOptions write SetStartOptions;
property OnMediaPlayerEvent: TNotifyPlayerEvent read FOnMediaPlayerEvent write FOnMediaPlayerEvent;
property OnMediaPlayerMediaChanged: TNotifyMediaChanged read FOnMediaPlayerMediaChanged write FOnMediaPlayerMediaChanged;
property OnMediaPlayerNothingSpecial: TNotifyEvent read FOnMediaPlayerNothingSpecial write FOnMediaPlayerNothingSpecial;
property OnMediaPlayerOpening: TNotifyEvent read FOnMediaPlayerOpening write FOnMediaPlayerOpening;
property OnMediaPlayerBuffering: TNotifyEvent read FOnMediaPlayerBuffering write FOnMediaPlayerBuffering;
property OnMediaPlayerPlaying: TNotifyEvent read FOnMediaPlayerPlaying write FOnMediaPlayerPlaying;
property OnMediaPlayerPaused: TNotifyEvent read FOnMediaPlayerPaused write FOnMediaPlayerPaused;
property OnMediaPlayerSwitchPlay: TNotifyEvent read FOnMediaPlayerSwitchPlay write FOnMediaPlayerSwitchPlay;
property OnMediaPlayerStopped: TNotifyEvent read FOnMediaPlayerStopped write FOnMediaPlayerStopped;
property OnMediaPlayerForward: TNotifyEvent read FOnMediaPlayerForward write FOnMediaPlayerForward;
property OnMediaPlayerBackward: TNotifyEvent read FOnMediaPlayerBackward write FOnMediaPlayerBackward;
property OnMediaPlayerEndReached: TNotifyEvent read FOnMediaPlayerEndReached write FOnMediaPlayerEndReached;
property OnMediaPlayerEncounteredError: TNotifyEvent read FOnMediaPlayerEncounteredError write FOnMediaPlayerEncounteredError;
property OnMediaPlayerTimeChanged: TNotifyTimeChanged read FOnMediaPlayerTimeChanged write FOnMediaPlayerTimeChanged;
property OnMediaPlayerPositionChanged: TNotifyPositionChanged read FOnMediaPlayerPositionChanged write FOnMediaPlayerPositionChanged;
property OnMediaPlayerSeekableChanged: TNotifySeekableChanged read FOnMediaPlayerSeekableChanged write FOnMediaPlayerSeekableChanged;
property OnMediaPlayerPausableChanged: TNotifyPausableChanged read FOnMediaPlayerPausableChanged write FOnMediaPlayerPausableChanged;
property OnMediaPlayerTitleChanged: TNotifyTitleChanged read FOnMediaPlayerTitleChanged write FOnMediaPlayerTitleChanged;
property OnMediaPlayerSnapshotTaken: TNotifySnapshotTaken read FOnMediaPlayerSnapshotTaken write FOnMediaPlayerSnapshotTaken;
property OnMediaPlayerLengthChanged: TNotifyLengthChanged read FOnMediaPlayerLengthChanged write FOnMediaPlayerLengthChanged;
property OnMediaPlayerVideoOutChanged: TNotifyVideoOutChanged read FOnMediaPlayerVideoOutChanged write FOnMediaPlayerVideoOutChanged;
property OnMediaPlayerScrambledChanged: TNotifyScrambledChanged read FOnMediaPlayerScrambledChanged write FOnMediaPlayerScrambledChanged;
property OnMediaPlayerCorked: TNotifyEvent read FOnMediaPlayerCorked write FOnMediaPlayerCorked;
property OnMediaPlayerUnCorked: TNotifyEvent read FOnMediaPlayerUnCorked write FOnMediaPlayerUnCorked;
property OnMediaPlayerMuted: TNotifyEvent read FOnMediaPlayerMuted write FOnMediaPlayerMuted;
property OnMediaPlayerUnMuted: TNotifyEvent read FOnMediaPlayerUnMuted write FOnMediaPlayerUnMuted;
property OnMediaPlayerAudioVolumeChanged: TNotifyAudioVolumeChanged read FOnMediaPlayerAudioVolumeChanged write FOnMediaPlayerAudioVolumeChanged;
property OnMediaPlayerVideoSizeChanged: TNotifyVideoSizeChanged read FOnMediaPlayerVideoSizeChanged write FOnMediaPlayerVideoSizeChanged;
property OnMediaPlayerEsAdded: TNotifyMediaPlayerEsAdded read FOnMediaPlayerEsAdded write FOnMediaPlayerEsAdded;
property OnMediaPlayerEsDeleted: TNotifyMediaPlayerEsDeleted read FOnMediaPlayerEsDeleted write FOnMediaPlayerEsDeleted;
property OnMediaPlayerEsSelected: TNotifyMediaPlayerEsSelected read FOnMediaPlayerEsSelected write FOnMediaPlayerEsSelected;
property OnMediaPlayerAudioDevice: TNotifyMediaPlayerAudioDevice read FOnMediaPlayerAudioDevice write FOnMediaPlayerAudioDevice;
property OnMediaPlayerChapterChanged: TNotifyMediaPlayerChapterChanged read FOnMediaPlayerChapterChanged write FOnMediaPlayerChapterChanged;
property OnRendererDiscoveredItemAdded: TNotifyRendererDiscoveredItemAdded read FOnRendererDiscoveredItemAdded write FOnRendererDiscoveredItemAdded;
property OnRendererDiscoveredItemDeleted: TNotifyRendererDiscoveredItemDeleted read FOnRendererDiscoveredItemDeleted write FOnRendererDiscoveredItemDeleted;
property UseEvents: boolean read FUseEvents write FUseEvents default TRUE;
property LastAudioOutput: WideString read FLastAudioOutput;
property LastAudioOutputDeviceId: WideString read FLastAudioOutputDeviceId;
end;
procedure Register;
implementation
{$R *.RES}
{$IFDEF DELPHI_XE6_UP}
uses
System.AnsiStrings;
{$ENDIF}
procedure Register;
begin
RegisterComponents('FmxPasLibVlc', [TFmxPasLibVlcPlayer]);
end;
////////////////////////////////////////////////////////////////////////////////
procedure fmx_lib_vlc_player_event_hdlr(p_event: libvlc_event_t_ptr; data: Pointer); cdecl; forward;
function fmx_libvlc_video_lock_cb(ptr: Pointer; planes: PVCBPlanes): Pointer; cdecl; forward;
procedure fmx_libvlc_video_unlock_cb(ptr: Pointer; picture: Pointer; planes: PVCBPlanes); cdecl; forward;
procedure fmx_libvlc_video_display_cb(ptr: Pointer; picture: Pointer); cdecl; forward;
function fmx_libvlc_video_format_cb(var ptr: Pointer; chroma: PAnsiChar; var width: LongWord; var height: LongWord; pitches: PVCBPitches; lines: PVCBLines): LongWord; cdecl; forward;
procedure fmx_libvlc_video_cleanup_cb(ptr: Pointer); cdecl; forward;
////////////////////////////////////////////////////////////////////////////////
constructor TFmxPasLibVlcPlayer.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
width := 320;
height := 240;
FForceAspectRatio := 16 / 9;
FAudioOutput := aoDefault;
FLastAudioOutput := '';
FLastAudioOutputDeviceId := '';
FTitleShow := FALSE;
FTitleShowPos := plvPosCenter;
FTitleShowTimeOut := 2000;
FSnapshotFmt := 'png';
FSnapShotPrv := FALSE;
FSpuShow := TRUE;
FOsdShow := TRUE;
FViewTeleText := FALSE;
p_mi := NIL;
p_mi_ev_mgr := NIL;
FMute := FALSE;
FVLC := NIL;
p_mi := NIL;
FUseEvents := TRUE;
FStartOptions := TStringList.Create;
FVideoCbCtx := TFmxPasLibVlcVideoCbCtx.Create(SELF);
FVideoCbCtx.ForceAspectRatio := FForceAspectRatio;
// if (csDesigning in ComponentState) then exit;
end;
procedure TFmxPasLibVlcPlayer.DestroyPlayer();
begin
EventsDisable();
Sleep(50);
if (p_mi <> NIL) then
begin
libvlc_video_set_callbacks(p_mi, NIL, NIL, NIL, NIL);
libvlc_video_set_format_callbacks(p_mi, NIL, NIL);
Stop();
libvlc_media_player_release(p_mi);
p_mi := NIL;
end;
Sleep(50);
end;
destructor TFmxPasLibVlcPlayer.Destroy;
begin
DestroyPlayer();
if Assigned(FVLC) then
begin
FreeAndNil(FVLC);
end;
FreeAndNil(FVideoCbCtx);
FreeAndNil(FStartOptions);
inherited Destroy;
end;
procedure TFmxPasLibVlcPlayer.EventsEnable();
begin
EventsDisable();
if (p_mi <> NIL) then
begin
p_mi_ev_mgr := libvlc_media_player_event_manager(p_mi);
if Assigned(p_mi_ev_mgr) then
begin
libvlc_event_attach(p_mi_ev_mgr, libvlc_MediaPlayerMediaChanged, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_attach(p_mi_ev_mgr, libvlc_MediaPlayerNothingSpecial, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_attach(p_mi_ev_mgr, libvlc_MediaPlayerOpening, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_attach(p_mi_ev_mgr, libvlc_MediaPlayerBuffering, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_attach(p_mi_ev_mgr, libvlc_MediaPlayerPlaying, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_attach(p_mi_ev_mgr, libvlc_MediaPlayerPaused, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_attach(p_mi_ev_mgr, libvlc_MediaPlayerStopped, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_attach(p_mi_ev_mgr, libvlc_MediaPlayerForward, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_attach(p_mi_ev_mgr, libvlc_MediaPlayerBackward, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_attach(p_mi_ev_mgr, libvlc_MediaPlayerEndReached, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_attach(p_mi_ev_mgr, libvlc_MediaPlayerEncounteredError, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_attach(p_mi_ev_mgr, libvlc_MediaPlayerTimeChanged, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_attach(p_mi_ev_mgr, libvlc_MediaPlayerPositionChanged, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_attach(p_mi_ev_mgr, libvlc_MediaPlayerSeekableChanged, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_attach(p_mi_ev_mgr, libvlc_MediaPlayerPausableChanged, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_attach(p_mi_ev_mgr, libvlc_MediaPlayerTitleChanged, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_attach(p_mi_ev_mgr, libvlc_MediaPlayerSnapshotTaken, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_attach(p_mi_ev_mgr, libvlc_MediaPlayerLengthChanged, fmx_lib_vlc_player_event_hdlr, SELF);
// availiable from 2.2.0
libvlc_event_attach(p_mi_ev_mgr, libvlc_MediaPlayerVout, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_attach(p_mi_ev_mgr, libvlc_MediaPlayerScrambledChanged, fmx_lib_vlc_player_event_hdlr, SELF);
// availiable from 2.2.2
libvlc_event_attach(p_mi_ev_mgr, libvlc_MediaPlayerCorked, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_attach(p_mi_ev_mgr, libvlc_MediaPlayerUncorked, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_attach(p_mi_ev_mgr, libvlc_MediaPlayerMuted, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_attach(p_mi_ev_mgr, libvlc_MediaPlayerUnmuted, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_attach(p_mi_ev_mgr, libvlc_MediaPlayerAudioVolume, fmx_lib_vlc_player_event_hdlr, SELF);
// availiable from 3.0.0
libvlc_event_attach(p_mi_ev_mgr, libvlc_MediaPlayerESAdded, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_attach(p_mi_ev_mgr, libvlc_MediaPlayerESDeleted, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_attach(p_mi_ev_mgr, libvlc_MediaPlayerESSelected, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_attach(p_mi_ev_mgr, libvlc_MediaPlayerAudioDevice, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_attach(p_mi_ev_mgr, libvlc_MediaPlayerChapterChanged, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_attach(p_mi_ev_mgr, libvlc_RendererDiscovererItemAdded, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_attach(p_mi_ev_mgr, libvlc_RendererDiscovererItemDeleted, fmx_lib_vlc_player_event_hdlr, SELF);
end;
end;
end;
procedure TFmxPasLibVlcPlayer.EventsDisable();
begin
if Assigned(p_mi_ev_mgr) then
begin
libvlc_event_detach(p_mi_ev_mgr, libvlc_RendererDiscovererItemDeleted, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_detach(p_mi_ev_mgr, libvlc_RendererDiscovererItemAdded, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_detach(p_mi_ev_mgr, libvlc_MediaPlayerChapterChanged, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_detach(p_mi_ev_mgr, libvlc_MediaPlayerAudioDevice, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_detach(p_mi_ev_mgr, libvlc_MediaPlayerESSelected, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_detach(p_mi_ev_mgr, libvlc_MediaPlayerESDeleted, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_detach(p_mi_ev_mgr, libvlc_MediaPlayerESAdded, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_detach(p_mi_ev_mgr, libvlc_MediaPlayerAudioVolume, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_detach(p_mi_ev_mgr, libvlc_MediaPlayerUnmuted, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_detach(p_mi_ev_mgr, libvlc_MediaPlayerMuted, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_detach(p_mi_ev_mgr, libvlc_MediaPlayerUncorked, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_detach(p_mi_ev_mgr, libvlc_MediaPlayerCorked, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_detach(p_mi_ev_mgr, libvlc_MediaPlayerScrambledChanged, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_detach(p_mi_ev_mgr, libvlc_MediaPlayerVout, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_detach(p_mi_ev_mgr, libvlc_MediaPlayerLengthChanged, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_detach(p_mi_ev_mgr, libvlc_MediaPlayerSnapshotTaken, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_detach(p_mi_ev_mgr, libvlc_MediaPlayerTitleChanged, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_detach(p_mi_ev_mgr, libvlc_MediaPlayerPausableChanged, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_detach(p_mi_ev_mgr, libvlc_MediaPlayerSeekableChanged, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_detach(p_mi_ev_mgr, libvlc_MediaPlayerPositionChanged, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_detach(p_mi_ev_mgr, libvlc_MediaPlayerTimeChanged, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_detach(p_mi_ev_mgr, libvlc_MediaPlayerEncounteredError, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_detach(p_mi_ev_mgr, libvlc_MediaPlayerEndReached, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_detach(p_mi_ev_mgr, libvlc_MediaPlayerBackward, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_detach(p_mi_ev_mgr, libvlc_MediaPlayerForward, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_detach(p_mi_ev_mgr, libvlc_MediaPlayerStopped, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_detach(p_mi_ev_mgr, libvlc_MediaPlayerPaused, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_detach(p_mi_ev_mgr, libvlc_MediaPlayerPlaying, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_detach(p_mi_ev_mgr, libvlc_MediaPlayerBuffering, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_detach(p_mi_ev_mgr, libvlc_MediaPlayerOpening, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_detach(p_mi_ev_mgr, libvlc_MediaPlayerNothingSpecial, fmx_lib_vlc_player_event_hdlr, SELF);
libvlc_event_detach(p_mi_ev_mgr, libvlc_MediaPlayerMediaChanged, fmx_lib_vlc_player_event_hdlr, SELF);
p_mi_ev_mgr := NIL;
end;
end;
procedure TFmxPasLibVlcPlayer.SetSnapshotFmt(aFormat: string);
begin
FSnapShotFmt := 'png';
aFormat := AnsiLowerCase(aFormat);
if ((aFormat = 'png') or (aFormat = 'jpg')) then
begin
FSnapShotFmt := aFormat;
end;
end;
procedure TFmxPasLibVlcPlayer.SetSnapshotPrv(aValue: Boolean);
begin
if (FSnapshotPrv <> aValue) then
begin
FSnapshotPrv := aValue;
end;
end;
procedure TFmxPasLibVlcPlayer.SetSpuShow(aValue: Boolean);
begin
if (FSpuShow <> aValue) then
begin
FSpuShow := aValue;
end;
end;
procedure TFmxPasLibVlcPlayer.SetOsdShow(aValue: Boolean);
begin
if (FOsdShow <> aValue) then
begin
FOsdShow := aValue;
end;
end;
procedure TFmxPasLibVlcPlayer.UpdateTitleShow();
begin
if (p_mi <> NIL) and (VLC.VersionBin >= $020100) then
begin
if FTitleShow then
begin
case FTitleShowPos of
plvPosCenter:
libvlc_media_player_set_video_title_display(p_mi, libvlc_position_center, FTitleShowTimeOut);
plvPosLeft:
libvlc_media_player_set_video_title_display(p_mi, libvlc_position_left, FTitleShowTimeOut);
plvPosRight:
libvlc_media_player_set_video_title_display(p_mi, libvlc_position_right, FTitleShowTimeOut);
plvPosTop:
libvlc_media_player_set_video_title_display(p_mi, libvlc_position_top, FTitleShowTimeOut);
plvPosTopLeft:
libvlc_media_player_set_video_title_display(p_mi, libvlc_position_top_left, FTitleShowTimeOut);
plvPosTopRight:
libvlc_media_player_set_video_title_display(p_mi, libvlc_position_top_right, FTitleShowTimeOut);
plvPosBottom:
libvlc_media_player_set_video_title_display(p_mi, libvlc_position_bottom, FTitleShowTimeOut);
plvPosBottomLeft:
libvlc_media_player_set_video_title_display(p_mi, libvlc_position_bottom_left, FTitleShowTimeOut);
plvPosBottomRight:
libvlc_media_player_set_video_title_display(p_mi, libvlc_position_bottom_right, FTitleShowTimeOut);
end;
end
else
begin
libvlc_media_player_set_video_title_display(p_mi, libvlc_position_disable, FTitleShowTimeOut);
end;
end;
end;
procedure TFmxPasLibVlcPlayer.SetTitleShow(aValue: Boolean);
begin
if (FTitleShow <> aValue) then
begin
FTitleShow := aValue;
UpdateTitleShow();
end;
end;
procedure TFmxPasLibVlcPlayer.SetTitleShowPos(aValue: TPasLibVlcTitlePosition);
begin
if (FTitleShowPos <> aValue) then
begin
FTitleShowPos := aValue;
UpdateTitleShow();
end;
end;
procedure TFmxPasLibVlcPlayer.SetTitleShowTimeOut(aValue: LongWord);
begin
if (FTitleShowTimeOut <> aValue) then
begin
FTitleShowTimeOut := aValue;
UpdateTitleShow();
end;
end;
procedure TFmxPasLibVlcPlayer.SetViewTeleText(aValue: Boolean);
begin
if (FViewTeleText <> aValue) then
begin
if aValue then
ShowTeleText()
else
HideTeleText();
end;
end;
procedure TFmxPasLibVlcPlayer.UpdateDeInterlace();
var
dm: string;
begin
if (p_mi = NIL) then
exit;
if (FDeinterlaceFilter = deON) then
begin
dm := vlcDeinterlaceModeNames[FDeinterlaceMode];
end
else
begin
dm := '';
end;
if (dm <> '') then
begin
libvlc_video_set_deinterlace(p_mi, PAnsiChar(Utf8Encode(dm)));
end
else
begin
libvlc_video_set_deinterlace(p_mi, NIL);
end;
end;
function TFmxPasLibVlcPlayer.GetDeinterlaceModeName(): WideString;
begin
Result := vlcDeinterlaceModeNames[FDeinterlaceMode];
end;
function TFmxPasLibVlcPlayer.GetIsEnded: Boolean;
begin
Result := (GetState() = plvPlayer_Ended);
end;
function TFmxPasLibVlcPlayer.GetIsStopped: Boolean;
begin
Result := (GetState() = plvPlayer_Stopped);
end;
procedure TFmxPasLibVlcPlayer.SetDeinterlaceFilter(aValue: TDeinterlaceFilter);
begin
if (FDeinterlaceFilter <> aValue) then
begin
FDeinterlaceFilter := aValue;
UpdateDeInterlace();
end;
end;
procedure TFmxPasLibVlcPlayer.SetDeinterlaceMode(aValue: TDeinterlaceMode);
begin
if (FDeinterlaceMode <> aValue) then
begin
FDeinterlaceMode := aValue;
UpdateDeInterlace();
end;
end;
procedure TFmxPasLibVlcPlayer.SetForceAspectRatio(const Value: Single);
begin
FForceAspectRatio := Value;
FVideoCbCtx.ForceAspectRatio := Value;
end;
function TFmxPasLibVlcPlayer.GetVlcInstance(): TPasLibVlc;
var
oIdx: Integer;
begin
if not Assigned(FVLC) then
begin
FVLC := TPasLibVlc.Create;
for oIdx := 0 to FStartOptions.Count - 1 do
begin
FVLC.AddOption(FStartOptions.Strings[oIdx]);
end;
FVLC.AddOption('--drop-late-frames');
// for versions before 2.1.0
FVLC.TitleShow := FTitleShow;
if not FSpuShow then
FVLC.AddOption('--no-spu')
else
FVLC.AddOption('--spu');
if not FOsdShow then
FVLC.AddOption('--no-osd')
else
FVLC.AddOption('--osd');
if not FSnapshotPrv then
FVLC.AddOption('--no-snapshot-preview')
else
FVLC.AddOption('--snapshot-preview');
if (FAudioOutput <> aoDefault) then
FVLC.AddOption('--aout=' + vlcAudioOutputNames[FAudioOutput]);
{if (FVideoOutput <> voDefault) then
FVLC.AddOption('--vout=' + vlcVideoOutputNames[FVideoOutput]);}
end;
Result := FVLC;
end;
procedure TFmxPasLibVlcPlayer.SetStartOptions(Value: TStringList);
begin
FStartOptions.Assign(Value);
end;
function TFmxPasLibVlcPlayer.GetPlayerHandle(): libvlc_media_player_t_ptr;
var
p_instance: libvlc_instance_t_ptr;
begin
if (p_mi = NIL) then
begin
// get instance
p_instance := VLC.Handle;
if (p_instance <> NIL) then
begin
// create media player
p_mi := libvlc_media_player_new(p_instance);
// handling mouse events by vlc ???
if (p_mi <> NIL) then
begin
// libvlc_video_set_mouse_input(p_mi, 1);
// libvlc_video_set_key_input(p_mi, 1);
libvlc_video_set_callbacks(p_mi, fmx_libvlc_video_lock_cb, fmx_libvlc_video_unlock_cb, fmx_libvlc_video_display_cb, Pointer(FVideoCbCtx));
libvlc_video_set_format_callbacks(p_mi, fmx_libvlc_video_format_cb, fmx_libvlc_video_cleanup_cb);
end;
//
// with context do
// begin
// video_w := 640;
// video_h := 480;
// pitch_w := video_w * FMX.Types.PixelFormatBytes[TPixelFormat.BGRA];
//
// (*
// * Furthermore, we recommend that pitches and lines be multiple of 32
// * to not break assumption that might be made by various optimizations
// * in the video decoders, video filters and/or video converters.
// *)
// video_w_a32 := (((640 + 31) shr 5) shl 5);
// video_h_a32 := (((640 + 31) shr 5) shl 5);
// pitch_w_a32 := video_w_a32 * FMX.Types.PixelFormatBytes[TPixelFormat.BGRA];
//
// if (buff <> NIL) then
// begin
// FreeMem(buff);
// buff_size := 0;
// end;
// buff_size := video_w_a32 * pitch_w_a32 + 32;
// GetMem(buff, buff_size);
// buff_a32 := Pointer(((NativeInt(buff) + 31) shr 5) shl 5);
//
// bmpi.SetSize(640, 480);
//
// (view as TFmxPasLibVlcPlayer).Bitmap.Assign(bmpi);
// end;
end;
end;
UpdateTitleShow();
if FUseEvents then
begin
EventsEnable();
end;
Result := p_mi;
end;
function GetToSep(var str: WideString; sep: WideString): WideString;
var
p: Integer;
begin
p := Pos(sep, str);
if (p > 0) then
begin
Result := Copy(str, 1, p - 1);
Delete(str, 1, p - 1 + Length(sep));
end
else
begin
Result := str;
str := '';
end;
end;
procedure TFmxPasLibVlcPlayer.Play(var media: TPasLibVlcMedia; audioOutput: WideString = ''; audioOutputDeviceId: WideString = ''; audioSetTimeOut: Cardinal = 1000);
begin
// assign media to player
libvlc_media_player_set_media(p_mi, media.MD);
// play
libvlc_media_player_play(p_mi);
// release media
media.Free;
media := NIL;
UpdateTitleShow();
if ((audioOutput <> '') or (audioOutputDeviceId <> '')) then
begin
while (libvlc_media_player_is_playing(p_mi) = 0) do
begin
Sleep(10);