Changeset 353 for CoolAudio/Systems/UAudioSystem.pas
- Timestamp:
- Apr 23, 2012, 2:57:12 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
CoolAudio/Systems/UAudioSystem.pas
r352 r353 9 9 10 10 type 11 TMediaPlayerDriverClass = class of TMediaPlayerDriver; 11 12 TOutputDriver = (omAlsa, omOSS, omDirectX, omWin32); 12 13 … … 22 23 constructor Create(AOwner: TComponent); override; 23 24 destructor Destroy; override; 25 function GetMediaPlayerDriverClass: TMediaPlayerDriverClass; virtual; 24 26 property OutputMode: TOutputDriver read FOutputDriver write SetOutputMode; 25 27 end; … … 27 29 TAudioSystemClass = class of TAudioSystem; 28 30 29 { T Player }30 31 T Player = class(TComponent)31 { TMediaPlayerDriver } 32 33 TMediaPlayerDriver = class 32 34 private 33 35 protected … … 60 62 property Playing: Boolean read FPlaying write SetPlaying; 61 63 property Active: Boolean read FActive write SetActive; 64 constructor Create; virtual; 65 destructor Destroy; override; 66 end; 67 68 TMediaPlayer = class(TComponent) 69 private 70 procedure CheckDriver; 71 function GetActive: Boolean; 72 function GetAudioSystem: TAudioSystem; 73 function GetFileName: string; 74 function GetLength: TDateTime; 75 function GetMuted: Boolean; 76 function GetPlaying: Boolean; 77 function GetPosition: TDateTime; 78 function GetVolume: Real; 79 procedure SetActive(AValue: Boolean); 80 procedure SetAudioSystem(AValue: TAudioSystem); 81 procedure SetFileName(AValue: string); 82 procedure SetMuted(AValue: Boolean); 83 procedure SetPlaying(AValue: Boolean); 84 procedure SetPosition(AValue: TDateTime); 85 procedure SetVolume(AValue: Real); 86 public 87 Driver: TMediaPlayerDriver; 88 procedure Play; 89 procedure Pause; 90 procedure Stop; 91 procedure Open; 92 procedure Close; 93 property Position: TDateTime read GetPosition write SetPosition; 94 property Length: TDateTime read GetLength; 95 property Playing: Boolean read GetPlaying write SetPlaying; 96 published 97 property Volume: Real read GetVolume write SetVolume; // 0..1 98 property Muted: Boolean read GetMuted write SetMuted; 99 property AudioSystem: TAudioSystem read GetAudioSystem write SetAudioSystem; 100 property FileName: string read GetFileName write SetFileName; 101 property Active: Boolean read GetActive write SetActive; 62 102 constructor Create(AOwner: TComponent); override; 63 103 destructor Destroy; override; 64 104 end; 65 105 66 TPlayerClass = class of T Player;106 TPlayerClass = class of TMediaPlayerDriver; 67 107 68 108 { TAudioSystemManagerItem } … … 71 111 Name: string; 72 112 SystemClass: TAudioSystemClass; 73 PlayerClass: TPlayerClass;113 Supported: Boolean; 74 114 end; 75 115 … … 78 118 TAudioSystemManager = class(TComponent) 79 119 Systems: TObjectList; // TListObject<TAudioSystem> 80 procedure Register(Name: string; SystemClass: TAudioSystemClass; 81 PlayerClass: TPlayerClass); 120 procedure Register(Name: string; SystemClass: TAudioSystemClass); 82 121 procedure FillStringList(StringList: TStrings); 83 function SearchByName(Name: string ): TAudioSystemManagerItem;122 function SearchByName(Name: string; SupportedOnly: Boolean = True): TAudioSystemManagerItem; 84 123 constructor Create(AOwner: TComponent); override; 85 124 destructor Destroy; override; … … 90 129 Mp3FileExt = '.mp3'; 91 130 131 var 132 DefaultAudioSystem: TAudioSystem; 133 92 134 resourcestring 93 135 SOpenOutputFailed = 'Failed opening audio output'; 136 SDefaultAudioSystemNotSet = 'Default audio system not set'; 137 SMediaPlayerDriverNotAssigned = 'Media player driver not assigned'; 94 138 95 139 96 140 implementation 141 142 { TMediaPlayer } 143 144 function TMediaPlayer.GetLength: TDateTime; 145 begin 146 CheckDriver; 147 Result := Driver.Length; 148 end; 149 150 procedure TMediaPlayer.CheckDriver; 151 begin 152 if not Assigned(Driver) then 153 raise Exception.Create(SMediaPlayerDriverNotAssigned); 154 end; 155 156 function TMediaPlayer.GetActive: Boolean; 157 begin 158 CheckDriver; 159 Result := Driver.Active; 160 end; 161 162 function TMediaPlayer.GetAudioSystem: TAudioSystem; 163 begin 164 CheckDriver; 165 Result := Driver.AudioSystem; 166 end; 167 168 function TMediaPlayer.GetFileName: string; 169 begin 170 CheckDriver; 171 Result := Driver.FileName; 172 end; 173 174 function TMediaPlayer.GetMuted: Boolean; 175 begin 176 CheckDriver; 177 Result := Driver.Muted; 178 end; 179 180 function TMediaPlayer.GetPlaying: Boolean; 181 begin 182 CheckDriver; 183 Result := Driver.Playing; 184 end; 185 186 function TMediaPlayer.GetPosition: TDateTime; 187 begin 188 CheckDriver; 189 Result := Driver.Position; 190 end; 191 192 function TMediaPlayer.GetVolume: Real; 193 begin 194 CheckDriver; 195 Result := Driver.Volume; 196 end; 197 198 procedure TMediaPlayer.SetActive(AValue: Boolean); 199 begin 200 CheckDriver; 201 Driver.Active := True; 202 end; 203 204 procedure TMediaPlayer.SetAudioSystem(AValue: TAudioSystem); 205 var 206 DriverClass: TMediaPlayerDriverClass; 207 begin 208 FreeAndNil(Driver); 209 DriverClass := AValue.GetMediaPlayerDriverClass; 210 Driver := DriverClass.Create; 211 Driver.AudioSystem := DefaultAudioSystem; 212 end; 213 214 procedure TMediaPlayer.SetFileName(AValue: string); 215 begin 216 CheckDriver; 217 Driver.FileName := AValue; 218 end; 219 220 procedure TMediaPlayer.SetMuted(AValue: Boolean); 221 begin 222 CheckDriver; 223 Driver.Muted := AValue; 224 end; 225 226 procedure TMediaPlayer.SetPlaying(AValue: Boolean); 227 begin 228 CheckDriver; 229 Driver.Playing := AValue; 230 end; 231 232 procedure TMediaPlayer.SetPosition(AValue: TDateTime); 233 begin 234 CheckDriver; 235 Driver.Position := AValue; 236 end; 237 238 procedure TMediaPlayer.SetVolume(AValue: Real); 239 begin 240 CheckDriver; 241 Driver.Volume := AValue; 242 end; 243 244 procedure TMediaPlayer.Play; 245 begin 246 CheckDriver; 247 Driver.Play; 248 end; 249 250 procedure TMediaPlayer.Pause; 251 begin 252 CheckDriver; 253 Driver.Pause; 254 end; 255 256 procedure TMediaPlayer.Stop; 257 begin 258 CheckDriver; 259 Driver.Stop; 260 end; 261 262 procedure TMediaPlayer.Open; 263 begin 264 CheckDriver; 265 Driver.Open; 266 end; 267 268 procedure TMediaPlayer.Close; 269 begin 270 CheckDriver; 271 Driver.Close; 272 end; 273 274 constructor TMediaPlayer.Create(AOwner: TComponent); 275 begin 276 inherited Create(AOwner); 277 if not Assigned(DefaultAudioSystem) then 278 raise Exception.Create(SDefaultAudioSystemNotSet); 279 AudioSystem := DefaultAudioSystem; 280 end; 281 282 destructor TMediaPlayer.Destroy; 283 begin 284 FreeAndNil(Driver); 285 inherited Destroy; 286 end; 97 287 98 288 { TAudioSystemManagerItem } … … 111 301 end; 112 302 113 function TAudioSystemManager.SearchByName(Name: string): TAudioSystemManagerItem; 303 function TAudioSystemManager.SearchByName(Name: string; SupportedOnly: Boolean = True): 304 TAudioSystemManagerItem; 114 305 var 115 306 I: Integer; 116 307 begin 117 308 I := 0; 118 while (I < Systems.Count) and (TAudioSystemManagerItem(Systems[I]).Name <> Name) do Inc(I); 309 while (I < Systems.Count) and 310 ((TAudioSystemManagerItem(Systems[I]).Name <> Name) or 311 (not TAudioSystemManagerItem(Systems[I]).Supported and SupportedOnly)) do Inc(I); 119 312 if I < Systems.Count then Result := TAudioSystemManagerItem(Systems[I]) 120 313 else Result := nil; … … 122 315 123 316 procedure TAudioSystemManager.Register(Name: string; 124 SystemClass: TAudioSystemClass ; PlayerClass: TPlayerClass);317 SystemClass: TAudioSystemClass); 125 318 var 126 319 NewItem: TAudioSystemManagerItem; … … 129 322 NewItem.Name := Name; 130 323 NewItem.SystemClass := SystemClass; 131 NewItem.PlayerClass := PlayerClass;132 324 Systems.Add(NewItem); 133 325 end; … … 145 337 end; 146 338 147 { T Player }148 149 procedure T Player.SetActive(AValue: Boolean);339 { TMediaPlayerDriver } 340 341 procedure TMediaPlayerDriver.SetActive(AValue: Boolean); 150 342 begin 151 343 if FActive = AValue then Exit; … … 153 345 end; 154 346 155 procedure T Player.SetPlaying(AValue: Boolean);347 procedure TMediaPlayerDriver.SetPlaying(AValue: Boolean); 156 348 begin 157 349 if FPlaying = AValue then Exit; … … 159 351 end; 160 352 161 function T Player.GetMuted: Boolean;353 function TMediaPlayerDriver.GetMuted: Boolean; 162 354 begin 163 355 Result := False; 164 356 end; 165 357 166 procedure T Player.SetMuted(AValue: Boolean);167 begin 168 end; 169 170 function T Player.GetLength: TDateTime;358 procedure TMediaPlayerDriver.SetMuted(AValue: Boolean); 359 begin 360 end; 361 362 function TMediaPlayerDriver.GetLength: TDateTime; 171 363 begin 172 364 Result := 0; 173 365 end; 174 366 175 function T Player.GetPosition: TDateTime;367 function TMediaPlayerDriver.GetPosition: TDateTime; 176 368 begin 177 369 Result := 0; 178 370 end; 179 371 180 function T Player.GetVolume: Real;372 function TMediaPlayerDriver.GetVolume: Real; 181 373 begin 182 374 Result := 0; 183 375 end; 184 376 185 procedure T Player.SetPosition(AValue: TDateTime);186 begin 187 end; 188 189 procedure T Player.SetVolume(AValue: Real);190 begin 191 end; 192 193 procedure T Player.SetFileName(AValue: string);377 procedure TMediaPlayerDriver.SetPosition(AValue: TDateTime); 378 begin 379 end; 380 381 procedure TMediaPlayerDriver.SetVolume(AValue: Real); 382 begin 383 end; 384 385 procedure TMediaPlayerDriver.SetFileName(AValue: string); 194 386 begin 195 387 if AValue = FFileName then Exit; … … 199 391 end; 200 392 201 procedure T Player.Play;202 begin 203 end; 204 205 procedure T Player.Pause;206 begin 207 end; 208 209 procedure T Player.Stop;210 begin 211 end; 212 213 procedure T Player.Open;393 procedure TMediaPlayerDriver.Play; 394 begin 395 end; 396 397 procedure TMediaPlayerDriver.Pause; 398 begin 399 end; 400 401 procedure TMediaPlayerDriver.Stop; 402 begin 403 end; 404 405 procedure TMediaPlayerDriver.Open; 214 406 begin 215 407 Active := True; 216 408 end; 217 409 218 procedure T Player.Close;410 procedure TMediaPlayerDriver.Close; 219 411 begin 220 412 Active := False; 221 413 end; 222 414 223 constructor T Player.Create(AOwner: TComponent);415 constructor TMediaPlayerDriver.Create; 224 416 begin 225 417 inherited; 226 418 end; 227 419 228 destructor T Player.Destroy;420 destructor TMediaPlayerDriver.Destroy; 229 421 begin 230 422 Stop; … … 257 449 end; 258 450 451 function TAudioSystem.GetMediaPlayerDriverClass: TMediaPlayerDriverClass; 452 begin 453 Result := TMediaPlayerDriver; 454 end; 455 456 initialization 457 458 DefaultAudioSystem := TAudioSystem.Create(nil); 459 460 finalization 461 462 FreeAndNil(DefaultAudioSystem); 463 259 464 end. 260 465
Note:
See TracChangeset
for help on using the changeset viewer.