Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any WAV sound playback on Mac from Delphi XE2?

Are there any tutorials or examples on how to play WAV files on Mac from application built by Delphi XE2 FireMonkey?

I'm asking because this code does not work:

var
  //fWaves head and data is initialized and plays properly on Win through OpenAL
  fWaves: array of record 
    Head: TWAVHeaderEx;
    Data: array of byte;
  end;
  D: NSData;
  N: NSSound;
begin
  D := TNSData.Wrap(TNSData.Create.initWithBytes(@fWaves[0].Head, SizeOf(fWaves[0].Head) + fWaves[0].Head.DataSize));
  ShowMessage(IntToStr(D.length)); //--Length is correct
  N := TNSSound.Wrap(TNSSound.Create.initWithData(D));
  ShowMessage(FloatToStr(N.Duration)); //--Displays 0
  if N.play then
    ShowMessage('Yes')
  else
    ShowMessage('No'); //--Always returns NO
end;

I'm loading WAV file header and data from memory and it plays fine with OpenAL. So the problem is somewhere in my NSSound usage. Could anyone please provide some working examples of Delphi XE2 sound playback on Mac?

like image 428
Kromster Avatar asked Oct 24 '22 09:10

Kromster


1 Answers

Freepascal/Lazarus has a unit called "macosall.pas" which is a translation of the os-x C++ headerfiles to pascal, allowing you to call native os-x functions.

Sadly this unit is not a part of delphi, but by opening the unit you can copy the function declaration over to delphi and it should work.

I expect that you will find what you need in the quicktime API which is the central hub of media on apple machines. Also check out Apple developer and have a look at the docs.

like image 170
Jon Lennart Aasenden Avatar answered Nov 02 '22 06:11

Jon Lennart Aasenden