473,657 Members | 2,550 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Playsound() plays only a part of the song

3 New Member
I tried to play a wav file with function Playsound() but it played only the first seconds of the song.I would like to play whole the song.What might de be wrong?Here is my code in case someone can help.




Expand|Select|Wrap|Line Numbers
  1. /*
  2. This uses the high level WAVE API PlaySound() to play a WAVE file in memory. I simply
  3. open the WAVE file called "nagelas.wav" (ie, in order for this example to
  4. work, you should make sure that you have such a WAVE file on your system). allocate
  5. some memory to completely load the entire file image into memory, and then use that
  6. for PlaySound().
  7. */
  8.  
  9. #include <windows.h>
  10. #include <stdio.h>
  11. #include <conio.h>
  12.  
  13. #include <winreg.h>
  14. #include <mmsystem.h>
  15.  
  16.  
  17.  
  18. TCHAR        WaveName[] = "nagelas.wav";
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29. /********************************** main() *******************************/
  30.  
  31. int main(int argc, char **argv)
  32. {
  33.     HANDLE            inHandle;
  34.     char *            wavePtr;
  35.     unsigned long    waveSize, action;
  36.     char            ch;
  37.  
  38.     /* Open the WAVE file */
  39.     if (INVALID_HANDLE_VALUE != (inHandle = CreateFile("nagelas.wav", GENERIC_READ,
  40.         FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL|FILE_FLAG_SEQUENTIAL_SCAN, 0)))
  41.     {
  42.         /* I'm going to skip checking that this is a WAVE file. I'll assume that it is.
  43.          *    Normally, you'd check it's RIFF header.
  44.          */
  45.  
  46.         /* Get the size of the file */
  47.         if(0xFFFFFFFF != (waveSize = GetFileSize(inHandle, 0)) && waveSize)
  48.         {
  49.             /* Allocate some memory to load the file */
  50.             if ((wavePtr = (char *)VirtualAlloc(0, waveSize, MEM_COMMIT, PAGE_READWRITE)))
  51.             {
  52.                 /* Read in WAVE file */
  53.                 if (ReadFile(inHandle, wavePtr, waveSize, &action, 0) && waveSize == action)
  54.                 {
  55.                     /* Play the WAVE */
  56.                     if (!PlaySound((LPCSTR)wavePtr, 0, SND_MEMORY | SND_NODEFAULT))
  57.                     {
  58.                         printf("Error playing WAVE!\r\n");
  59.                     }
  60.                 }
  61.                 else
  62.                 {
  63.                     printf("Error loading WAVE!\r\n");
  64.                 }
  65.  
  66.                 /* Free the memory */
  67.                 VirtualFree(wavePtr, waveSize, MEM_FREE);
  68.             }
  69.             else
  70.             {
  71.                 printf("Can't get memory!\r\n");
  72.             }
  73.         }
  74.         else
  75.         {
  76.             printf("Bad WAVE size!\r\n");
  77.         }
  78.  
  79.         /* Close the WAVE file */
  80.         CloseHandle(inHandle);
  81.     }
  82.     else
  83.     {
  84.         printf("Can't load the WAVE file!\r\n");
  85.     }
  86.     scanf("%c",&ch);
  87.     return(0);
  88. }
Apr 17 '07 #1
0 1897

Sign in to post your reply or Sign up for a free account.

Similar topics

1
5477
by: Ben Bateman | last post by:
I am tyring to write a small menu program that will display the lyrics of a song, and then play the song. I was told that you have to convert the mp3 to wav, did that. The 2 function calls under each case is included in another header file that I created. I have the <mmsystem.h> included in the main cpp file. The functions under the PlaySound function works correctly, but it is not playing the wav file.
19
15425
by: bballmitch | last post by:
Why won't the following code work? char soundfile2 = "C:/Windows/Media/pinky and the brain.wav"; PlaySound(soundfile2,NULL,SND_FILENAME|SND_SYNC|SND_ASYNC); getchar(); i put libwinmm.a in the parameters and i have all the right headerfiles in there, but it won't work. it says that i must declare SND_FILENAME ,
5
2343
by: MLH | last post by:
I have a line of code that works when called from a procedure in Access 2.0 form... PlaySound("C:\cr\help\Help0018.wav", 0) I imported what I thought was needed into A97. However, running it is unsuccessful. I get an error saying "file mmsystem not found". I think I've violated some API call protocol.
2
1683
by: Joe Thompson | last post by:
Hi, I am trying to use PlaySound in a VC++.net Windows app (VS 2003). I can use it to play a file but now I want to play it from a resource. I have two questions: How do I add a wav file to my project as a resource (steps please) How do I call PlaySound once that I have the wav file as part of the resource.
10
2474
by: Ot | last post by:
I found information on PlaySound. I implemented it in my program and it works just dandy. The only little problem is that I have to package the ..wav files and send them along since PlaySound plays a sound file. One of the options I found in a nice description of PlaySound says that there are a couple of other choices. 1) The sound can be in the registry and actually controlled/selected by the end user.
3
3156
by: tamarindm | last post by:
I need to play a .wav file over and over again. I am using the following code. private static extern bool PlaySound( string lpszName, int hModule, int dwFlags ); public int SND_ASYNC = 0x0001; // play asynchronously public int SND_LOOP = 0x0008; // loop the sound until next PlaySound
4
2147
by: Cogito | last post by:
Chaps and Chapettes, Program in C++. Im doing a project to detect a defined marker, then play the relevent sound when it can no longer be seen. It worked well when using the beep function. if( config->//not visivle ) Beep(176,20);
0
1260
by: Mike | last post by:
I am a novice writing a simple program in Visual C++ Express and am having an issue. I basically have several picture boxes of the same size on top of each other with only one visible at a time. I have a button that when clicked triggers an event that makes each picturebox visible one at a time and plays a wav file associated with the image in the picturebox. I have put an example of the code below: //picturebox1 is already visible on...
0
8425
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8743
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8622
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6177
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4333
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2745
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1973
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1736
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.