📄 xaudioplayer.pas
字号:
FOnNotifyExited: TNotifyEvent;
FOnNotifyPlayerState: TNotifyPlayerStateEvent;
FOnNotifyPlayerMode: TNotifyPlayerModeEvent;
FOnNotifyPlayerEnvironmentInteger: TNotifyEnvironmentIntegerEvent;
FOnNotifyPlayerEnvironmentString: TNotifyEnvironmentStringEvent;
FOnNotifyInputState: TNotifyInputStateEvent;
FOnNotifyInputName: TNotifyInputNameEvent;
FOnNotifyInputCaps: TNotifyInputCapsEvent;
FOnNotifyInputPosition: TNotifyInputPositionEvent;
FOnNotifyInputPositionRange: TNotifyInputPositionRangeEvent;
FOnNotifyInputTimecode: TNotifyInputTimecodeEvent;
FOnNotifyInputTimecodeGranularity: TNotifyInputTimecodeGranularityEvent;
FOnNotifyInputModule: TNotifyInputModuleEvent;
FOnNotifyInputModuleInfo: TNotifyInputModuleInfoEvent;
FOnNotifyInputDeviceInfo: TNotifyInputDeviceInfoEvent;
FOnNotifyInputFilterInfo: TNotifyInputFilterInfoEvent;
FOnNotifyOutputState: TNotifyOutputStateEvent;
FOnNotifyOutputName: TNotifyOutputNameEvent;
FOnNotifyOutputCaps: TNotifyOutputCapsEvent;
FOnNotifyOutputVolume: TNotifyOutputVolumeEvent;
FOnNotifyOutputBalance: TNotifyOutputBalanceEvent;
FOnNotifyOutputPcmLevel: TNotifyOutputPcmLevelEvent;
FOnNotifyOutputMasterLevel: TNotifyOutputMasterLevelEvent;
FOnNotifyOutputChannels: TNotifyOutputChannelsEvent;
FOnNotifyOutputPorts: TNotifyOutputPortsEvent;
FOnNotifyOutputModule: TNotifyOutputModuleEvent;
FOnNotifyOutputModuleInfo: TNotifyOutputModuleInfoEvent;
FOnNotifyOutputDeviceInfo: TNotifyOutputDeviceInfoEvent;
FOnNotifyOutputFilterInfo: TNotifyOutputFilterInfoEvent;
FOnNotifyStreamMimeType: TNotifyStreamMimeTypeEvent;
FOnNotifyStreamDuration: TNotifyStreamDurationEvent;
FOnNotifyStreamParameters: TNotifyStreamParametersEvent;
FOnNotifyStreamProperties: TNotifyStreamPropertiesEvent;
FOnNotifyCodecModule: TNotifyCodecModuleEvent;
FOnNotifyCodecModuleInfo: TNotifyCodecModuleInfoEvent;
FOnNotifyCodecDeviceInfo: TNotifyCodecDeviceInfoEvent;
FOnNotifyCodecQuality: TNotifyCodecQualityEvent;
FOnNotifyCodecEqualizer: TNotifyCodecEqualizerEvent;
FOnNotifyNotificationMask: TNotifyNotificationMaskEvent;
FOnNotifyDebugLevel: TNotifyDebugLevelEvent;
FOnNotifyProgress: TNotifyProgressEvent;
FOnNotifyDebug: TNotifyDebugEvent;
FOnNotifyError: TNotifyErrorEvent;
procedure SetPriority(Priority: Cardinal);
function GetPriority: Cardinal;
procedure ResetExternalInterface;
procedure LoadExternalInterface;
function LoadSymbol(Name: PChar): Pointer;
function CheckPlayerInstance: Boolean;
protected
{ Protected declarations }
function TranslateMessage(var msg_from: TMessage; var msg_to: XA_Message): Integer;
procedure OnWindowsMessage(var win32_msg: TMessage);
public
{ Public declarations }
constructor Create(AOwner:TComponent); override;
destructor Destroy; override;
published
{ Published declarations }
function Init: Boolean;
function ErrorString(Code: Integer): string;
function GetVersion(VersionId: Byte): Cardinal;
procedure Ping(Tag: Cardinal);
procedure Play;
procedure Pause;
procedure Stop;
procedure Synchronize;
procedure InputSeek(Offset: Cardinal; Range: Cardinal);
procedure InputOpen(const Name: string);
procedure InputClose;
procedure InputSendMessage(MsgType: Word; const Data: Pointer; Size: Cardinal);
procedure InputAddFilter(const Name: String; Where: Integer);
procedure InputRemoveFilter(const Name: String; ID: Integer);
procedure InputFilterList;
procedure InputModuleRegister(const Name: String);
procedure InputModuleQuery(ID: Cardinal);
procedure InputModulesList;
procedure OutputOpen(const Name: String);
procedure OutputClose;
procedure OutputMute;
procedure OutputUnmute;
procedure OutputReset;
procedure OutputDrain;
procedure OutputSendMessage(MsgType: Word; const Data: Pointer; Size: Cardinal);
procedure OutputAddFilter(const Name: String; Where: Integer);
procedure OutputRemoveFilter(const Name: String; ID: Integer);
procedure OutputFilterList;
procedure OutputModuleRegister(const Name: String);
procedure OutputModuleQuery(ID: Cardinal);
procedure OutputModulesList;
procedure CodecSendMessage(MsgType: Word; const Data: Pointer; Size: Cardinal);
procedure CodecModuleRegister(const Name: String);
procedure CodecModuleQuery(ID: Cardinal);
procedure CodecModulesList;
procedure SetPlayerMode(Mode: Cardinal);
procedure GetPlayerMode;
procedure SetPlayerEnvironmentInteger(const Name: String; Value: Integer);
procedure GetPlayerEnvironmentInteger(const Name: String);
procedure SetPlayerEnvironmentString(const Name: String; const Value: String);
procedure GetPlayerEnvironmentString(const Name: String);
procedure UnsetPlayerEnvironment(const Name: String);
procedure SetInputModule(ID: Cardinal);
procedure GetInputModule;
procedure SetInputName(const Name: String);
procedure GetInputName;
procedure SetInputPositionRange(Range: Cardinal);
procedure GetInputPositionRange;
procedure SetInputTimecodeGranularity(Granularity: Cardinal);
procedure GetInputTimecodeGranularity;
procedure SetOutputModule(ID: Cardinal);
procedure GetOutputModule;
procedure SetOutputName(const Name: String);
procedure GetOutputName;
procedure SetOutputVolume(Balance: Integer; PcmLevel: Integer; MasterLevel: Integer);
procedure GetOutputVolume;
procedure SetOutputChannels(Channels: Cardinal);
procedure GetOutputChannels;
procedure SetOutputPorts(Ports: Cardinal);
procedure GetOutputPorts;
procedure SetCodecQuality(Quality: Byte);
procedure GetCodecQuality;
procedure SetCodecEqualizer(Equalizer: PXA_EqualizerInfo);
procedure GetCodecEqualizer;
procedure SetNotificationMask(Mask: Cardinal);
procedure GetNotificationMask;
procedure SetDebugLevel(Level: Integer);
procedure GetDebugLevel;
property Priority:Cardinal read GetPriority write SetPriority;
property XaudioPath:String read LibraryPath write LibraryPath;
property OnNotifyMessage:TNotifyMessageEvent read FOnNotifyMessage write FOnNotifyMessage;
property OnNotifyReady:TNotifyEvent read FOnNotifyReady write FOnNotifyReady;
property OnNotifyAck:TNotifyAckEvent read FOnNotifyAck write FOnNotifyAck;
property OnNotifyNack:TNotifyNackEvent read FOnNotifyNack write FOnNotifyNack;
property OnNotifyPong:TNotifyPongEvent read FOnNotifyPong write FOnNotifyPong;
property OnNotifyExited:TNotifyEvent read FOnNotifyExited write FOnNotifyExited;
property OnNotifyPlayerState:TNotifyPlayerStateEvent read FOnNotifyPlayerState write FOnNotifyPlayerState;
property OnNotifyPlayerMode:TNotifyPlayerModeEvent read FOnNotifyPlayerMode write FOnNotifyPlayerMode;
property OnNotifyPlayerEnvironmentInteger:TNotifyEnvironmentIntegerEvent read FOnNotifyPlayerEnvironmentInteger write FOnNotifyPlayerEnvironmentInteger;
property OnNotifyPlayerEnvironmentString:TNotifyEnvironmentStringEvent read FOnNotifyPlayerEnvironmentString write FOnNotifyPlayerEnvironmentString;
property OnNotifyInputState:TNotifyInputStateEvent read FOnNotifyInputState write FOnNotifyInputState;
property OnNotifyInputName:TNotifyInputNameEvent read FOnNotifyInputName write FOnNotifyInputName;
property OnNotifyInputCaps:TNotifyInputCapsEvent read FOnNotifyInputCaps write FOnNotifyInputCaps;
property OnNotifyInputPosition:TNotifyInputPositionEvent read FOnNotifyInputPosition write FOnNotifyInputPosition;
property OnNotifyInputPositionRange:TNotifyInputPositionRangeEvent read FOnNotifyInputPositionRange write FOnNotifyInputPositionRange;
property OnNotifyInputTimecode:TNotifyInputTimecodeEvent read FOnNotifyInputTimecode write FOnNotifyInputTimecode;
property OnNotifyInputTimecodeGranularity:TNotifyInputTimecodeGranularityEvent read FOnNotifyInputTimecodeGranularity write FOnNotifyInputTimecodeGranularity;
property OnNotifyInputModule:TNotifyInputModuleEvent read FOnNotifyInputModule write FOnNotifyInputModule;
property OnNotifyInputModuleInfo:TNotifyInputModuleInfoEvent read FOnNotifyInputModuleInfo write FOnNotifyInputModuleInfo;
property OnNotifyInputDeviceInfo:TNotifyInputDeviceInfoEvent read FOnNotifyInputDeviceInfo write FOnNotifyInputDeviceInfo;
property OnNotifyInputFilterInfo:TNotifyInputFilterInfoEvent read FOnNotifyInputFilterInfo write FOnNotifyInputFilterInfo;
property OnNotifyOutputState:TNotifyOutputStateEvent read FOnNotifyOutputState write FOnNotifyOutputState;
property OnNotifyOutputName:TNotifyOutputNameEvent read FOnNotifyOutputName write FOnNotifyOutputName;
property OnNotifyOutputCaps:TNotifyOutputCapsEvent read FOnNotifyOutputCaps write FOnNotifyOutputCaps;
property OnNotifyOutputVolume:TNotifyOutputVolumeEvent read FOnNotifyOutputVolume write FOnNotifyOutputVolume;
property OnNotifyOutputBalance:TNotifyOutputBalanceEvent read FOnNotifyOutputBalance write FOnNotifyOutputBalance;
property OnNotifyOutputPcmLevel:TNotifyOutputPcmLevelEvent read FOnNotifyOutputPcmLevel write FOnNotifyOutputPcmLevel;
property OnNotifyOutputMasterLevel:TNotifyOutputMasterLevelEvent read FOnNotifyOutputMasterLevel write FOnNotifyOutputMasterLevel;
property OnNotifyOutputChannels:TNotifyOutputChannelsEvent read FOnNotifyOutputChannels write FOnNotifyOutputChannels;
property OnNotifyOutputPorts:TNotifyOutputPortsEvent read FOnNotifyOutputPorts write FOnNotifyOutputPorts;
property OnNotifyOutputModule:TNotifyOutputModuleEvent read FOnNotifyOutputModule write FOnNotifyOutputModule;
property OnNotifyOutputModuleInfo:TNotifyOutputModuleInfoEvent read FOnNotifyOutputModuleInfo write FOnNotifyOutputModuleInfo;
property OnNotifyOutputDeviceInfo:TNotifyOutputDeviceInfoEvent read FOnNotifyOutputDeviceInfo write FOnNotifyOutputDeviceInfo;
property OnNotifyOutputFilterInfo:TNotifyOutputFilterInfoEvent read FOnNotifyOutputFilterInfo write FOnNotifyOutputFilterInfo;
property OnNotifyStreamMimeType:TNotifyStreamMimeTypeEvent read FOnNotifyStreamMimeType write FOnNotifyStreamMimeType;
property OnNotifyStreamDuration:TNotifyStreamDurationEvent read FOnNotifyStreamDuration write FOnNotifyStreamDuration;
property OnNotifyStreamParameters:TNotifyStreamParametersEvent read FOnNotifyStreamParameters write FOnNotifyStreamParameters;
property OnNotifyStreamProperties:TNotifyStreamPropertiesEvent read FOnNotifyStreamProperties write FOnNotifyStreamProperties;
property OnNotifyCodecModule:TNotifyCodecModuleEvent read FOnNotifyCodecModule write FOnNotifyCodecModule;
property OnNotifyCodecModuleInfo:TNotifyCodecModuleInfoEvent read FOnNotifyCodecModuleInfo write FOnNotifyCodecModuleInfo;
property OnNotifyCodecDeviceInfo:TNotifyCodecDeviceInfoEvent read FOnNotifyCodecDeviceInfo write FOnNotifyCodecDeviceInfo;
property OnNotifyCodecQuality:TNotifyCodecQualityEvent read FOnNotifyCodecQuality write FOnNotifyCodecQuality;
property OnNotifyCodecEqualizer:TNotifyCodecEqualizerEvent read FOnNotifyCodecEqualizer write FOnNotifyCodecEqualizer;
property OnNotifyNotificationMask:TNotifyNotificationMaskEvent read FOnNotifyNotificationMask write FOnNotifyNotificationMask;
property OnNotifyDebugLevel:TNotifyDebugLevelEvent read FOnNotifyDebugLevel write FOnNotifyDebugLevel;
property OnNotifyProgress:TNotifyProgressEvent read FOnNotifyProgress write FOnNotifyProgress;
property OnNotifyDebug:TNotifyDebugEvent read FOnNotifyDebug write FOnNotifyDebug;
property OnNotifyError:TNotifyErrorEvent read FOnNotifyError write FOnNotifyError;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('黄兴控件', [TXaudioPlayer]);
end;
{********************************************************************}
constructor TXaudioPlayer.Create(AOwner:TComponent);
begin
{ Init some fields }
LibraryPath := 'xaudio.dll';
LibraryHandle := 0;
Player := nil;
PlayerPriority := XA_CONTROL_PRIORITY_HIGH;
HiddenWindow := 0;
{ Call inherited constructor }
inherited Create(AOwner);
{ Create hidden window to handle messages }
HiddenWindow := AllocateHWnd(OnWindowsMessage);
if (HiddenWindow = 0) then
Raise EXaudioException.Create('Cannot Create Hidden Window');
{ Reset DLL entry points }
ResetExternalInterface;
end;
{********************************************************************}
destructor TXaudioPlayer.Destroy;
var
Shadow: Pointer;
begin
Shadow := Player;
Player := nil;
if (Shadow <> nil) then PlayerDelete(Shadow);
ResetExternalInterface;
if (HiddenWindow <> 0) then DeAllocatehWnd(HiddenWindow);
inherited Destroy;
end;
{********************************************************************}
function TXaudioPlayer.Init : Boolean;
begin
Init := CheckPlayerInstance;
end;
{********************************************************************}
function TXaudioPlayer.LoadSymbol(Name: PChar): Pointer;
var
Symbol: Pointer;
begin
if (LibraryHandle <> 0) then begin
Symbol:= GetProcAddress(LibraryHandle, Name);
if (Symbol = nil) then begin
FreeLibrary(LibraryHandle);
LibraryHandle := 0;
Raise EXaudioException.Create('Cannot Find Symbol ' + Name + ' in Xaudio DLL');
end;
end
else
Symbol := nil;
LoadSymbol := Symbol;
end;
{********************************************************************}
procedure TXaudioPlayer.ResetExternalInterface;
begin
if (LibraryHandle <> 0) then FreeLibrary(LibraryHandle);
LibraryHandle := 0;
@PlayerNew := nil;
@PlayerDelete := nil;
@PlayerSetPriority := nil;
@PlayerGetPriority := nil;
@XaudioErrorString := nil;
@XaudioGetVersion := nil;
@ControlMessageSend_N := nil;
@ControlMessageSend_P := nil;
@ControlMessageSend_S := nil;
@ControlMessageSend_SS := nil;
@ControlMessageSend_SI := nil;
@ControlMessageSend_IPI := nil;
@ControlMessageSend_I := nil;
@ControlMessageSend_II := nil;
@ControlMessageSend_III := nil;
@ControlMessageSend_IIII := nil;
@ControlWin32ParamsToMessage := nil;
end;
{********************************************************************}
procedure TXaudioPlayer.LoadExternalInterface;
begin
LibraryHandle := LoadLibrary(PChar(LibraryPath));
if (LibraryHandle <> 0) then begin
@PlayerNew := LoadSymbol('player_new');
@PlayerDelete := LoadSymbol('player_delete');
@PlayerSetPriority := LoadSymbol('player_set_priority');
@PlayerGetPriority := LoadSymbol('player_get_priority');
@XaudioErrorString := LoadSymbol('xaudio_error_string');
@XaudioGetVersion := LoadSymbol('xaudio_get_version');
@ControlMessageSend_N := LoadSymbol('control_message_send_N');
@ControlMessageSend_P := LoadSymbol('control_message_send_P');
@ControlMessageSend_S := LoadSymbol('control_message_send_S');
@ControlMessageSend_SS := LoadSymbol('control_message_send_SS');
@ControlMessageSend_SI := LoadSymbol('control_message_send_SI');
@ControlMessageSend_IPI := LoadSymbol('control_message_send_IPI');
@ControlMessageSend_I := LoadSymbol('control_message_send_I');
@ControlMessageSend_II := LoadSymbol('control_message_send_II');
@ControlMessageSend_III := LoadSymbol('control_message_send_III');
@ControlMessageSend_IIII := LoadSymbol('control_message_send_IIII');
@ControlWin32ParamsToMessage := LoadSymbol('control_win32_params_to_message');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -