GXS.FileMP3.pas 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. //
  2. // The graphics engine GLXEngine. The unit of GXScene for Delphi
  3. //
  4. unit GXS.FileMP3;
  5. (* Support for MP3 format *)
  6. interface
  7. {$I Stage.Defines.inc}
  8. uses
  9. System.Classes,
  10. GXS.ApplicationFileIO,
  11. GXS.SoundFileObjects;
  12. type
  13. (* Support for MP3 format.
  14. *Partial* support only, access to PCMData is NOT supported. *)
  15. TgxMP3File = class(TgxSoundFile)
  16. private
  17. data: array of Byte; // used to store MP3 bitstream
  18. protected
  19. public
  20. function CreateCopy(AOwner: TPersistent): TgxDataFile; override;
  21. class function Capabilities: TDataFileCapabilities; override;
  22. procedure LoadFromStream(Stream: TStream); override;
  23. procedure SaveToStream(Stream: TStream); override;
  24. procedure PlayOnWaveOut; override;
  25. function WAVData: Pointer; override;
  26. function WAVDataSize: Integer; override;
  27. function PCMData: Pointer; override;
  28. function LengthInBytes: Integer; override;
  29. end;
  30. //=============================================================
  31. implementation
  32. //=============================================================
  33. // ------------------
  34. // ------------------ TgxMP3File ------------------
  35. // ------------------
  36. function TgxMP3File.CreateCopy(AOwner: TPersistent): TgxDataFile;
  37. begin
  38. Result := inherited CreateCopy(AOwner);
  39. if Assigned(Result) then
  40. begin
  41. TgxMP3File(Result).data := Copy(data);
  42. end;
  43. end;
  44. class function TgxMP3File.Capabilities: TDataFileCapabilities;
  45. begin
  46. Result := [dfcRead, dfcWrite];
  47. end;
  48. procedure TgxMP3File.LoadFromStream(Stream: TStream);
  49. begin
  50. // MP3 isn't actually, just loaded directly...
  51. Assert(Assigned(Stream));
  52. SetLength(data, Stream.Size);
  53. if Length(data) > 0 then
  54. Stream.Read(data[0], Length(data));
  55. end;
  56. procedure TgxMP3File.SaveToStream(Stream: TStream);
  57. begin
  58. if Length(data) > 0 then
  59. Stream.Write(data[0], Length(data));
  60. end;
  61. procedure TgxMP3File.PlayOnWaveOut;
  62. begin
  63. Assert(False, 'MP3 playback on WaveOut not supported.');
  64. end;
  65. function TgxMP3File.WAVData: Pointer;
  66. begin
  67. if Length(data) > 0 then
  68. Result := @data[0]
  69. else
  70. Result := nil;
  71. end;
  72. function TgxMP3File.WAVDataSize: Integer;
  73. begin
  74. Result := Length(data);
  75. end;
  76. function TgxMP3File.PCMData: Pointer;
  77. begin
  78. Result := nil;
  79. end;
  80. function TgxMP3File.LengthInBytes: Integer;
  81. begin
  82. Result := 0;
  83. end;
  84. //------------------------------------------------------------------
  85. initialization
  86. //------------------------------------------------------------------
  87. RegisterSoundFileFormat('mp3', 'MPEG Layer3 files', TgxMP3File);
  88. end.