Hey James. What methods do you use to play sounds in Delphi. So far I've managed to get basic wave playback working using the following code:
Sounds.AddFile(txtFile.Text, ExtractFileName(txtFile.Text) , TV_SOUNDTYPE_DIRECTXSTEREO);
// using sKey = '' (let sound engine determine key) doesn't work for me.
// TV_SOUNDTYPE_UNDEFINED (let sound engine determine sound type) doesn't work either
...
var
aSoundv : Variant;
...
aSoundv := Sounds.Item[OleVariant(1)];
aSoundv.Play;
This is somewhat ok, but I wanted to use the COM interfaces to the sounds since they are more strongly typed. Anyways, after lots of hacking, I now got code like this :
var
aSound : IDispatch;
aWav : _TVSoundDXStereo;
...
aSound := Sounds.Item[OleVariant(1)];
if aSound.QueryInterface(IID__TVSoundDXStereo , aWav) = S_OK then
aWav.Play;
This is better, but it requires me to know that the sound I am going to play is of type TVSoundDXStereo. aWav has to be of the type
_TVSoundDXStereo and the call to QueryInterface() has to use the
IID__TVSoundDXStereo interface ID. Not too flexible...
Is there a better way to do this??
----
It works, u just need to make sure that it calls SoundINit (or InitSound) only once, theres a bug when u set the SOUNDENABLE flag to true, it calls InitSound twice (do'h!)
This is wierd... when I make a call to SoundEngine.Init(), my app throws an exception when I close it. When I comment it out, it doesn't. This is this the exact opposite of how you described it!!
Yes, "strange things happen with TV objects when dealing with Delphi" ...
