Winamp Zone - Player.pas

unit player;

(**************************************************
** Abstract classes: TPlayer, TPlaylist, TVolume **
** Copyrights (c) 2004, Slava Antonov            **
** WWW:    http://slava.users.otts.ru            **
**************************************************)

interface

{$ifndef NO_EXCEPTIONS}
uses
  SysUtils;
{$endif}

type

  TVolume = class(TObject)
  protected
    function GetValue: Byte; virtual; abstract;
    procedure SetValue(AValue: Byte); virtual; abstract;
  public
    procedure Increase; virtual; abstract;
    procedure Decrease; virtual; abstract;
    property Value: Byte read GetValue write SetValue;
      
  end;

  TTrack = class(TObject)
  protected
    function GetFileURL: String; virtual; abstract;
    function GetLength: Integer; virtual; abstract;
    function GetPosition: Integer; virtual; abstract;
    procedure SetPosition(Value: Integer); virtual; abstract;
    function GetTitle: String; virtual; abstract;
  public
    property FileURL: String read GetFileURL;
      
    property Length: Integer read GetLength;
      
    property Position: Integer read GetPosition write SetPosition;
      
    property Title: String read GetTitle;
      
  end;

  TSortMode = (smTitle, smFileName, smFullPath, smReverse,
               smRandomize);
    
    

{$ifndef NO_EXCEPTIONS}
  EPlaylist = class(Exception);
{$endif}
  TPlaylist = class(TObject)
  protected
    function GetLength: Integer; virtual; abstract;
    function GetItem(Index: Integer): TTrack; virtual; abstract;
    function GetPlaylistFile: String; virtual; abstract;
    function GetPosition: Integer; virtual; abstract;
    procedure SetPosition(Value: Integer); virtual; abstract;
  public
    procedure Add(const Path: String); virtual; abstract;
      
    procedure Clear; virtual; abstract;
      
    procedure Load(const Path: String); virtual; abstract;
      
      
    procedure RemoveDeadFiles; virtual; abstract;
    procedure Save; overload; virtual; abstract;
    procedure Save(const FileName: String); overload; virtual; abstract;
    procedure Sort(SortMode: TSortMode); virtual; abstract;

    property Length: Integer read GetLength;
      
    property Items[Index: Integer]: TTrack read GetItem; default;
      
    property PlaylistFile: String read GetPlaylistFile;
      
    property Position: Integer read GetPosition write SetPosition;
      
  end;

{ Play modes }
  TPlayMode = set of (pmRepeat, pmShuffle);

{ Play states }
  TPlayState = (psNone, psStop, psPlay, psPause);

  TPlayerVersion = class(TObject)
  protected
    FMajor: Integer;
    FMinor: Integer;
  public
    property Major: Integer read FMajor;
    property Minor: Integer read FMinor;
  end;

{ Events }
  TPlayerEvent = procedure of object;
  TPlayerEventEx = procedure(ByUser: Boolean) of object;
  TPlayerStateChangeEvent = procedure(NewState: TPlayState;
    OldState: TPlayState; ByUser: Boolean) of object;

  TPlayer = class(TObject)
  protected
    FCurrentTrack: TTrack;
    FVolume: TVolume;
    FPlaylist: TPlaylist;
    FVersion: TPlayerVersion;

    FOnPrev: TPlayerEvent;
    FOnPlay: TPlayerEvent;
    FOnPause: TPlayerEvent;
    FOnStop: TPlayerEventEx;
    FOnNext: TPlayerEventEx;
    FOnStateChange: TPlayerStateChangeEvent;

    function GetMode: TPlayMode; virtual; abstract;
    procedure SetMode(const Value: TPlayMode); virtual; abstract;
    function GetState: TPlayState; virtual; abstract;
  public
    procedure Prev; virtual; abstract;
    procedure Play; overload; virtual; abstract;
      { Соответсвует нажатию кнопки Play }
    procedure Play(const Path: String); overload; virtual; abstract;
      { Начать воспроизведение указанного файла, пути или папки }
    procedure Pause; virtual; abstract;
    procedure Stop; virtual; abstract;
    procedure Next; virtual; abstract;

    procedure Fastforward; virtual; abstract;
    procedure Rewind; virtual; abstract;

    property CurrentTrack: TTrack read FCurrentTrack;
    property Mode: TPlayMode read GetMode write SetMode;
    property Playlist: TPlaylist read FPlaylist;
    property State: TPlayState read GetState;
    property Version: TPlayerVersion read FVersion;
    property Volume: TVolume read FVolume;

  { Player events }
    property OnPrev: TPlayerEvent read FOnPrev write FOnPrev;
    property OnPlay: TPlayerEvent read FOnPlay write FOnPlay;
    property OnPause: TPlayerEvent read FOnPause write FOnPause;
    property OnStop: TPlayerEventEx read FOnStop write FOnStop;
    property OnNext: TPlayerEventEx read FOnNext write FOnNext;

    property OnStateChange: TPlayerStateChangeEvent read
      FOnStateChange write FOnStateChange;
  end;

resourcestring
  SInvalidTrackIndex = 'Track index (%d) out of bounds';

implementation

end.
Слава Антонов © 2002 — August 13, 2008
Индекс цитирования 197-577-902 ICQ-статус
Hosted by uCoz