473,387 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Playsound() plays only a part of the song

3
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 1876

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

Similar topics

1
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...
19
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...
5
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...
2
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...
10
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...
3
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 =...
4
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. ...
0
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. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.