Recent

Author Topic: Trying to play a WAVE in a resource; sumped.  (Read 4431 times)

Josh

  • Hero Member
  • *****
  • Posts: 1271
Trying to play a WAVE in a resource; sumped.
« on: January 26, 2019, 06:01:52 pm »
Hi

I am trying to play a wav file from a resource file using MMSYSTEM PlaySound, but the file is not found as its of type WAVE

If I use to locate some text data from resource then the file is found
Code: [Select]
if(FindResource(hInstance, PChar(ASound), RT_RCDATA) <> 0) then using the same on the wav file fails as it not RT_RCDAT but a WAVE type.

Likewise
Code: [Select]
if PlaySound('T_3765_A', HInstance, SND_ASYNC or SND_NODEFAULT or SND_RESOURCE)=false then showmessage('cannot play sound');Will produce the cannot play sound message, as I assume its cant locate the resource type.

Is there a RC_WAVE? data type.

Any other suggestions welcome, its only to be windows so no x-platform needed
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

HeavyUser

  • Sr. Member
  • ****
  • Posts: 397
Re: Trying to play a WAVE in a resource; sumped.
« Reply #1 on: January 26, 2019, 06:45:26 pm »

Is there a RC_WAVE? data type.

if memory serves my right (its bee years back) you do something along the lines of
Code: Pascal  [Select][+][-]
  1. const
  2.   RT_RCWave ='WAVE';
  3.  


Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1312
    • Lebeau Software
Re: Trying to play a WAVE in a resource; sumped.
« Reply #2 on: January 27, 2019, 03:46:24 am »
I am trying to play a wav file from a resource file using MMSYSTEM PlaySound, but the file is not found as its of type WAVE

Being of type WAVE it not a problem for PlaySound().  Are you sure you are using the correct resource ID to access it?

If I use to locate some text data from resource then the file is found
Code: [Select]
if(FindResource(hInstance, PChar(ASound), RT_RCDATA) <> 0) then using the same on the wav file fails as it not RT_RCDAT but a WAVE type.

Then you are doing something wrong, because FindResource() handles WAVE data just fine:

Code: [Select]
FindResource(hInstance, 'TheResourceID', 'WAVE')
Likewise
Code: [Select]
if PlaySound('T_3765_A', HInstance, SND_ASYNC or SND_NODEFAULT or SND_RESOURCE)=false then showmessage('cannot play sound');Will produce the cannot play sound message, as I assume its cant locate the resource type.

You are assuming that is the problem.  Unfortunately, PlaySounds() does not offer any way to find out WHY it failed.  So start eliminating possibilities.  Is HInstance is the correct HMODULE to search in?  Is 'T_3765_A' the correct resource ID to search for?

Is there a RC_WAVE? data type.

No.  Just specify 'WAVE' as a string rather than as an constant ID.  WAVE is a user-defined type, not a system-defined type.

Any other suggestions welcome, its only to be windows so no x-platform needed

Worse case scenario, you could just manually load the WAVE resource data yourself and then use the SND_MEMORY flag to play it.  See Playing WAVE Resources on MSDN.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

440bx

  • Hero Member
  • *****
  • Posts: 3946
Re: Trying to play a WAVE in a resource; sumped.
« Reply #3 on: January 27, 2019, 04:00:28 am »
You are assuming that is the problem.  Unfortunately, PlaySounds() does not offer any way to find out WHY it failed. 
True.  Sometimes, with such functions, it is still useful to call GetLastError.  If the function failed in an internal API call that sets the last error, retrieving the error can give an indication of why the function failed.  When it works, it saves time.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Josh

  • Hero Member
  • *****
  • Posts: 1271
Re: Trying to play a WAVE in a resource; stumped.
« Reply #4 on: February 05, 2019, 12:18:17 am »
apologies for late reply.

The problem I was getting was that if I used playsound to play a file on the hard drive ( as a test as the sounds are in thord party resource) , this would work, but would cause hard disk activity when playing the sounds.
I managed to playsound from a memory stream created from a resource file, but this had a major draw back, if the same sound was played before the previous had finished it would abrubtly terminate the first sound, probably because it was being played from memory. (playing from file this did not happen).

So I quickly set it up to work with BASS audio, and this solved the problem.

also setting const RT_RCWave ='WAVE'; and also others allowed me to easily move the resource data to a memory stream.

Thanks all for your help.
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1312
    • Lebeau Software
Re: Trying to play a WAVE in a resource; stumped.
« Reply #5 on: February 05, 2019, 09:40:21 pm »
I managed to playsound from a memory stream created from a resource file, but this had a major draw back, if the same sound was played before the previous had finished it would abrubtly terminate the first sound, probably because it was being played from memory. (playing from file this did not happen).

Playing from HDD can exhibit the same issue (in fact, when playing a file from HDD, the file is loaded into memory before being played). Whether you play from the HDD or from a memory/resource block, what really matters is whether you are playing synchronously or asynchronously.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

 

TinyPortal © 2005-2018