VLC播放器里面的LibVLC.dll调用问题
我在VideoLAN(http://download.videolan.org/pub/videolan/vlc/)下载了0.86i的版本,想在Delphi7中动态调用其中的LibVLC.dll,做一个播放器,结果能生成控件(包括动态生成和安装组件方式),可是都不能播放媒体,请熟悉的朋友帮我,谢谢!!!!!
代码如下:
IceVLCPlayer.pas
- Delphi(Pascal) code
unit IceVLCPlayer;{ TIceVLCPlayer - VLC Player for Delphi (0.8.6i) (c)2008 by Norbert Mereg }interfaceuses SysUtils, Classes, Controls, ExtCtrls, libVLC, Graphics, Windows, Forms;type TEVLCException = class(Exception); TEVLCNotFound = class(Exception); TEVLCLoadLibrary = class(Exception); TErrorEvent = procedure(Sender: TObject; ErrorCode: integer; ErrorMessage: string) of object; TIceVLCPlayer = class(TCustomPanel) private VLC : libvlc_instance; VLCVideo : integer; VLCInput : libvlc_input; VLCError : libvlc_exception; FLength: Int64; FIsPlaying: boolean; FTime: Int64; FPosition: Single; FTimer: TTimer; FVideoWidth: integer; FVideoHeight: integer; FOnPlay: TNotifyEvent; FOnStop: TNotifyEvent; FOnError: TErrorEvent; function CheckError: boolean; procedure FTimerTimer(Sender: TObject); procedure StartPlaying; procedure SetOnPlay(const Value: TNotifyEvent); procedure StopPlaying; procedure SetOnStop(const Value: TNotifyEvent); procedure SetOnError(const Value: TErrorEvent); procedure StopIfPlaying; { Private declarations } protected { Protected declarations } public { Public declarations } property Length: Int64 read FLength; property Time: Int64 read FTime; property Position: Single read FPosition; property IsPlaying: boolean read FIsPlaying; property VideoWidth: integer read FVideoWidth; property VideoHeight: integer read FVideoHeight; constructor Create(AOwner: TComponent); override; destructor Destroy; override; procedure Play(const FileName: string); procedure PlayTV(const CaptureDev: string; const Channel: integer; const Country: integer = 0); procedure Stop; published { Published declarations } property Align; property OnPlay: TNotifyEvent read FOnPlay write SetOnPlay; property OnStop: TNotifyEvent read FOnStop write SetOnStop; property OnError: TErrorEvent read FOnError write SetOnError; end;procedure Register;implementationprocedure Register;begin RegisterComponents('IcePackage', [TIceVLCPlayer]);end;{ TIceVLCPlayer }constructor TIceVLCPlayer.Create(AOwner: TComponent);var Args: array [0..1] of PChar;begin inherited Create(AOwner); VLC := nil; VLCInput := nil; FIsPlaying := False; ParentBackground := False; Color := clBlack; Width := 320; Height := 240; Caption := ''; BevelOuter := bvNone; case VLD_Startup of VLD_SUCCESS : begin end; VLD_NOLIB : begin raise TEVLCLoadLibrary.Create('VLC Player not installed! Please re-install.'); exit; end; VLD_NOTFOUND : begin raise TEVLCNotFound.Create('VLC Player not installed or wrong version! Please re-install.'); exit; end; end; //Clear error var. FillChar(VLCError,SizeOf(VLCError),0); //Create new VLC object Args[0] := PChar(VLD_LibPath); Args[1] := nil; VLC := libvlc_new( 1, @Args[0], VLCError); FTimer := TTimer.Create(nil); FTimer.Enabled := False; FTimer.Interval := 500; FTimer.OnTimer := FTimerTimer;end;destructor TIceVLCPlayer.Destroy;begin FTimer.Free; // NTDLL.DLL error :( // if Assigned(VLC) then // libvlc_destroy(VLC); inherited;end;procedure TIceVLCPlayer.Stop;begin StopIfPlaying;end;procedure TIceVLCPlayer.StopIfPlaying;begin if IsPlaying then begin if Assigned(VLCInput) then begin libvlc_playlist_stop(VLC, VLCError); CheckError; end; libvlc_playlist_clear(VLC, VLCError); CheckError; FTimer.Enabled := False; FIsPlaying := False; libvlc_input_free(VLCInput); VLCInput := nil; end;end;procedure TIceVLCPlayer.Play(const FileName: string);begin StopIfPlaying; VLCVideo := libvlc_playlist_add(VLC, PChar(UTF8Encode(FileName)), '', VLCError); CheckError; StartPlaying;end;procedure TIceVLCPlayer.PlayTV(const CaptureDev: string; const Channel, Country: integer);var Args: array[0..14] of PChar; DevStr: string;begin StopIfPlaying; args[0] := ':dshow-adev=""'; args[1] := ':dshow-size=""'; args[2] := ':dshow-caching=200'; args[3] := ':dshow-chroma=""'; args[4] := ':dshow-fps=0.000000'; args[5] := ':no-dshow-config'; args[6] := ':no-dshow-tuner'; args[7] := PChar(':dshow-tuner-channel=' + IntToStr(Channel)); args[8] := PChar(':dshow-tuner-country=' + IntToStr(Country)); args[9] := ':dshow-tuner-input=2'; //1-Cable, 2-Antenna args[10] := ':dshow-video-input=-1'; args[11] := ':dshow-audio-input=-1'; args[12] := ':dshow-video-output=-1'; args[13] := ':dshow-audio-output=-1'; args[14] := nil; DevStr := 'dshow:// :dshow-vdev="' + CaptureDev + '"'; VLCVideo := libvlc_playlist_add_extended(VLC, PChar(UTF8Encode(DevStr)), '', 14, @Args[0], VLCError); CheckError; StartPlaying;end;function TIceVLCPlayer.CheckError: boolean;var //待续
[解决办法]
很佩服楼主的精神
但下面这段代码没看明白:
// Core
function libvlc_new(argc:integer; args:ppchar; var exception:libvlc_exception):libvlc_instance; cdecl external lib;
procedure libvlc_destroy(vlc:libvlc_instance); cdecl external lib;
procedure libvlc_exception_clear(var exception:libvlc_exception); cdecl external lib;
...
上面的external lib;中的lib本应是动态链接库的名字libvlc.dll,为什么是lib呢?!!lib究竟是什么?!!
其实要达到楼主的目的用windows自带的windowsmediaplayer即可
[解决办法]
ding
[解决办法]
我搞过一个用FFMpeg解码的SDK,你可以看看:
http://blog.csdn.net/cybercake/archive/2008/05/06/2403718.aspx
另有一位大大搞过FFmpeg for Delphi的,你雇条狗找找……