⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mp3class.pas

📁 电子小说阅读器v2.68可用于阅读pdf.html等各种形式的文档
💻 PAS
字号:
{
模块名称:MP3播放的接口

使用方法:无

返回值:  无
}

unit MP3Class;

{$TYPEDADDRESS OFF} // Unit must be compiled without type-checked pointers.

interface

uses Windows, ActiveX, Classes, Graphics, OleServer, OleCtrls, StdVCL;

// *********************************************************************//
// GUIDS declared in the TypeLibrary. Following prefixes are used:        
//   Type Libraries     : LIBID_xxxx                                      
//   CoClasses          : CLASS_xxxx                                      
//   DISPInterfaces     : DIID_xxxx                                       
//   Non-DISP interfaces: IID_xxxx                                        
// *********************************************************************//
const
  // TypeLibrary Major and minor versions
  MPEGPLAYLibMajorVersion = 1;
  MPEGPLAYLibMinorVersion = 0;

  LIBID_MPEGPLAYLib: TGUID = '{3B00B10A-6EF0-11D1-A6AA-0020AFE4DE54}';

  DIID__DMp3Play: TGUID = '{3B00B10B-6EF0-11D1-A6AA-0020AFE4DE54}';
  DIID__DMp3PlayEvents: TGUID = '{3B00B10C-6EF0-11D1-A6AA-0020AFE4DE54}';
  CLASS_Mp3Play: TGUID = '{3B00B10D-6EF0-11D1-A6AA-0020AFE4DE54}';
type

// *********************************************************************//
// Forward declaration of types defined in TypeLibrary                    
// *********************************************************************//
  _DMp3Play = dispinterface;
  _DMp3PlayEvents = dispinterface;

// *********************************************************************//
// Declaration of CoClasses defined in Type Library                       
// (NOTE: Here we map each CoClass to its Default Interface)              
// *********************************************************************//
  Mp3Play = _DMp3Play;


// *********************************************************************//
// DispIntf:  _DMp3Play
// Flags:     (4112) Hidden Dispatchable
// GUID:      {3B00B10B-6EF0-11D1-A6AA-0020AFE4DE54}
// *********************************************************************//
  _DMp3Play = dispinterface
    ['{3B00B10B-6EF0-11D1-A6AA-0020AFE4DE54}']
    property SelWaveDevice: Smallint dispid 1;
    property Max44: WordBool dispid 2;
    property FrameCount: Integer dispid 3;
    property IsCopyrighted: WordBool dispid 4;
    property IsOriginal: WordBool dispid 5;
    property HasChecksums: WordBool dispid 6;
    property Layer: Smallint dispid 7;
    property SampleFrequency: Integer dispid 8;
    property BitRate: Integer dispid 9;
    property MPEGVersion: Smallint dispid 10;
    property MPEGMode: Smallint dispid 11;
    property FrameNotifyCount: Smallint dispid 12;
    property Version: Smallint dispid 13;
    property MsPerFrame: Single dispid 14;
    property TotalTime: Integer dispid 15;
    property ChannelMode: Smallint dispid 16;
    function  Open(const mp3file: WideString; const wavefile: WideString): Smallint; dispid 17;
    function  Play: Smallint; dispid 18;
    function  Pause: Smallint; dispid 19;
    function  Seek(Frame: Integer): Smallint; dispid 20;
    function  Stop: Smallint; dispid 21;
    function  Close: Smallint; dispid 22;
    function  Authorize(const Name: WideString; const Password: WideString): Smallint; dispid 23;
    function  SetErrorMode(ErrorsOn: Smallint): Smallint; dispid 24;
    function  GetVolumeLeft: Integer; dispid 25;
    function  SetVolume(LeftVolume: Integer; RightVolume: Integer): Smallint; dispid 26;
    function  GetVolumeRight: Integer; dispid 27;
    function  SetVolumeP(LeftVolumeP: Smallint; RightVolumeP: Smallint): Smallint; dispid 28;
    function  GetVolumeRightP: Smallint; dispid 29;
    function  GetVolumeLeftP: Smallint; dispid 30;
    function  GetNumDevs: Smallint; dispid 31;
    function  GetDevName(iDev: Smallint): WideString; dispid 32;
    function  GetDevParam(iDev: Smallint): Integer; dispid 33;
    function  SetOutDevice(iDev: Smallint): Smallint; dispid 34;
    function  GetOutDevice: Smallint; dispid 35;
    function  PlayFromTo(FrameA: Integer; FrameB: Integer): Smallint; dispid 36;
    function  GetWaveLengthSecs: Single; dispid 37;
    function  PlayFromToS(Secx: Single; Secy: Single): Smallint; dispid 38;
    function  GetLeftSelVolumeP: Smallint; dispid 39;
    function  SetSpeed(Percent: Smallint): Smallint; dispid 40;
    procedure AboutBox; dispid -552;
  end;

// *********************************************************************//
// DispIntf:  _DMp3PlayEvents
// Flags:     (4096) Dispatchable
// GUID:      {3B00B10C-6EF0-11D1-A6AA-0020AFE4DE54}
// *********************************************************************//
  _DMp3PlayEvents = dispinterface
    ['{3B00B10C-6EF0-11D1-A6AA-0020AFE4DE54}']
    procedure ActFrame(ActFrame: Integer); dispid 1;
    procedure ThreadEnded; dispid 2;
    procedure Failure(ErrorCode: Integer; const ErrStr: WideString); dispid 3;
  end;


// *********************************************************************//
// OLE Control Proxy class declaration
// Control Name     : TMp3Play
// Help String      : Mp3Play Control
// Default Interface: _DMp3Play
// Def. Intf. DISP? : Yes
// Event   Interface: _DMp3PlayEvents
// TypeFlags        : (34) CanCreate Control
// *********************************************************************//
  TMp3PlayActFrame = procedure(Sender: TObject; ActFrame: Integer) of object;
  TMp3PlayFailure = procedure(Sender: TObject; ErrorCode: Integer; const ErrStr: WideString) of object;

  TMp3Play = class(TOleControl)
  private
    FOnActFrame: TMp3PlayActFrame;
    FOnThreadEnded: TNotifyEvent;
    FOnFailure: TMp3PlayFailure;
    FIntf: _DMp3Play;
    function  GetControlInterface: _DMp3Play;
  protected
    procedure CreateControl;
    procedure InitControlData; override;
  public
    function  Open(const mp3file: WideString; const wavefile: WideString): Smallint;
    function  Play: Smallint;
    function  Pause: Smallint;
    function  Seek(Frame: Integer): Smallint;
    function  Stop: Smallint;
    function  Close: Smallint;
    function  Authorize(const Name: WideString; const Password: WideString): Smallint;
    function  SetErrorMode(ErrorsOn: Smallint): Smallint;
    function  GetVolumeLeft: Integer;
    function  SetVolume(LeftVolume: Integer; RightVolume: Integer): Smallint;
    function  GetVolumeRight: Integer;
    function  SetVolumeP(LeftVolumeP: Smallint; RightVolumeP: Smallint): Smallint;
    function  GetVolumeRightP: Smallint;
    function  GetVolumeLeftP: Smallint;
    function  GetNumDevs: Smallint;
    function  GetDevName(iDev: Smallint): WideString;
    function  GetDevParam(iDev: Smallint): Integer;
    function  SetOutDevice(iDev: Smallint): Smallint;
    function  GetOutDevice: Smallint;
    function  PlayFromTo(FrameA: Integer; FrameB: Integer): Smallint;
    function  GetWaveLengthSecs: Single;
    function  PlayFromToS(Secx: Single; Secy: Single): Smallint;
    function  GetLeftSelVolumeP: Smallint;
    function  SetSpeed(Percent: Smallint): Smallint;
    procedure AboutBox;
    property  ControlInterface: _DMp3Play read GetControlInterface;
    property  DefaultInterface: _DMp3Play read GetControlInterface;
  published
    property  TabStop;
    property  Align;
    property  DragCursor;
    property  DragMode;
    property  ParentShowHint;
    property  PopupMenu;
    property  ShowHint;
    property  TabOrder;
    property  Visible;
    property  OnDragDrop;
    property  OnDragOver;
    property  OnEndDrag;
    property  OnEnter;
    property  OnExit;
    property  OnStartDrag;
    property SelWaveDevice: Smallint index 1 read GetSmallintProp write SetSmallintProp stored False;
    property Max44: WordBool index 2 read GetWordBoolProp write SetWordBoolProp stored False;
    property FrameCount: Integer index 3 read GetIntegerProp write SetIntegerProp stored False;
    property IsCopyrighted: WordBool index 4 read GetWordBoolProp write SetWordBoolProp stored False;
    property IsOriginal: WordBool index 5 read GetWordBoolProp write SetWordBoolProp stored False;
    property HasChecksums: WordBool index 6 read GetWordBoolProp write SetWordBoolProp stored False;
    property Layer: Smallint index 7 read GetSmallintProp write SetSmallintProp stored False;
    property SampleFrequency: Integer index 8 read GetIntegerProp write SetIntegerProp stored False;
    property BitRate: Integer index 9 read GetIntegerProp write SetIntegerProp stored False;
    property MPEGVersion: Smallint index 10 read GetSmallintProp write SetSmallintProp stored False;
    property MPEGMode: Smallint index 11 read GetSmallintProp write SetSmallintProp stored False;
    property FrameNotifyCount: Smallint index 12 read GetSmallintProp write SetSmallintProp stored False;
    property Version: Smallint index 13 read GetSmallintProp write SetSmallintProp stored False;
    property MsPerFrame: Single index 14 read GetSingleProp write SetSingleProp stored False;
    property TotalTime: Integer index 15 read GetIntegerProp write SetIntegerProp stored False;
    property ChannelMode: Smallint index 16 read GetSmallintProp write SetSmallintProp stored False;
    property OnActFrame: TMp3PlayActFrame read FOnActFrame write FOnActFrame;
    property OnThreadEnded: TNotifyEvent read FOnThreadEnded write FOnThreadEnded;
    property OnFailure: TMp3PlayFailure read FOnFailure write FOnFailure;
  end;

procedure Register;

implementation

uses ComObj;

procedure TMp3Play.InitControlData;
const
  CEventDispIDs: array [0..2] of DWORD = (
    $00000001, $00000002, $00000003);
  CControlData: TControlData2 = (
    ClassID: '{3B00B10D-6EF0-11D1-A6AA-0020AFE4DE54}';
    EventIID: '{3B00B10C-6EF0-11D1-A6AA-0020AFE4DE54}';
    EventCount: 3;
    EventDispIDs: @CEventDispIDs;
    LicenseKey: nil (*HR:$80004005*);
    Flags: $00000000;
    Version: 401);
begin
  ControlData := @CControlData;
  TControlData2(CControlData).FirstEventOfs := Cardinal(@@FOnActFrame) - Cardinal(Self);
end;

procedure TMp3Play.CreateControl;

  procedure DoCreate;
  begin
    FIntf := IUnknown(OleObject) as _DMp3Play;
  end;

begin
  if FIntf = nil then DoCreate;
end;

function TMp3Play.GetControlInterface: _DMp3Play;
begin
  CreateControl;
  Result := FIntf;
end;

function  TMp3Play.Open(const mp3file: WideString; const wavefile: WideString): Smallint;
begin
  Result := DefaultInterface.Open(mp3file, wavefile);
end;

function  TMp3Play.Play: Smallint;
begin
  Result := DefaultInterface.Play;
end;

function  TMp3Play.Pause: Smallint;
begin
  Result := DefaultInterface.Pause;
end;

function  TMp3Play.Seek(Frame: Integer): Smallint;
begin
  Result := DefaultInterface.Seek(Frame);
end;

function  TMp3Play.Stop: Smallint;
begin
  Result := DefaultInterface.Stop;
end;

function  TMp3Play.Close: Smallint;
begin
  Result := DefaultInterface.Close;
end;

function  TMp3Play.Authorize(const Name: WideString; const Password: WideString): Smallint;
begin
  Result := DefaultInterface.Authorize(Name, Password);
end;

function  TMp3Play.SetErrorMode(ErrorsOn: Smallint): Smallint;
begin
  Result := DefaultInterface.SetErrorMode(ErrorsOn);
end;

function  TMp3Play.GetVolumeLeft: Integer;
begin
  Result := DefaultInterface.GetVolumeLeft;
end;

function  TMp3Play.SetVolume(LeftVolume: Integer; RightVolume: Integer): Smallint;
begin
  Result := DefaultInterface.SetVolume(LeftVolume, RightVolume);
end;

function  TMp3Play.GetVolumeRight: Integer;
begin
  Result := DefaultInterface.GetVolumeRight;
end;

function  TMp3Play.SetVolumeP(LeftVolumeP: Smallint; RightVolumeP: Smallint): Smallint;
begin
  Result := DefaultInterface.SetVolumeP(LeftVolumeP, RightVolumeP);
end;

function  TMp3Play.GetVolumeRightP: Smallint;
begin
  Result := DefaultInterface.GetVolumeRightP;
end;

function  TMp3Play.GetVolumeLeftP: Smallint;
begin
  Result := DefaultInterface.GetVolumeLeftP;
end;

function  TMp3Play.GetNumDevs: Smallint;
begin
  Result := DefaultInterface.GetNumDevs;
end;

function  TMp3Play.GetDevName(iDev: Smallint): WideString;
begin
  Result := DefaultInterface.GetDevName(iDev);
end;

function  TMp3Play.GetDevParam(iDev: Smallint): Integer;
begin
  Result := DefaultInterface.GetDevParam(iDev);
end;

function  TMp3Play.SetOutDevice(iDev: Smallint): Smallint;
begin
  Result := DefaultInterface.SetOutDevice(iDev);
end;

function  TMp3Play.GetOutDevice: Smallint;
begin
  Result := DefaultInterface.GetOutDevice;
end;

function  TMp3Play.PlayFromTo(FrameA: Integer; FrameB: Integer): Smallint;
begin
  Result := DefaultInterface.PlayFromTo(FrameA, FrameB);
end;

function  TMp3Play.GetWaveLengthSecs: Single;
begin
  Result := DefaultInterface.GetWaveLengthSecs;
end;

function  TMp3Play.PlayFromToS(Secx: Single; Secy: Single): Smallint;
begin
  Result := DefaultInterface.PlayFromToS(Secx, Secy);
end;

function  TMp3Play.GetLeftSelVolumeP: Smallint;
begin
  Result := DefaultInterface.GetLeftSelVolumeP;
end;

function  TMp3Play.SetSpeed(Percent: Smallint): Smallint;
begin
  Result := DefaultInterface.SetSpeed(Percent);
end;

procedure TMp3Play.AboutBox;
begin
  DefaultInterface.AboutBox;
end;

procedure Register;
begin
  RegisterComponents('ActiveX',[TMp3Play]);
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -