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. - /*
-
This uses the high level WAVE API PlaySound() to play a WAVE file in memory. I simply
-
open the WAVE file called "nagelas.wav" (ie, in order for this example to
-
work, you should make sure that you have such a WAVE file on your system). allocate
-
some memory to completely load the entire file image into memory, and then use that
-
for PlaySound().
-
*/
-
-
#include <windows.h>
-
#include <stdio.h>
-
#include <conio.h>
-
-
#include <winreg.h>
-
#include <mmsystem.h>
-
-
-
-
TCHAR WaveName[] = "nagelas.wav";
-
-
-
-
-
-
-
-
-
-
-
/********************************** main() *******************************/
-
-
int main(int argc, char **argv)
-
{
-
HANDLE inHandle;
-
char * wavePtr;
-
unsigned long waveSize, action;
-
char ch;
-
-
/* Open the WAVE file */
-
if (INVALID_HANDLE_VALUE != (inHandle = CreateFile("nagelas.wav", GENERIC_READ,
-
FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL|FILE_FLAG_SEQUENTIAL_SCAN, 0)))
-
{
-
/* I'm going to skip checking that this is a WAVE file. I'll assume that it is.
-
* Normally, you'd check it's RIFF header.
-
*/
-
-
/* Get the size of the file */
-
if(0xFFFFFFFF != (waveSize = GetFileSize(inHandle, 0)) && waveSize)
-
{
-
/* Allocate some memory to load the file */
-
if ((wavePtr = (char *)VirtualAlloc(0, waveSize, MEM_COMMIT, PAGE_READWRITE)))
-
{
-
/* Read in WAVE file */
-
if (ReadFile(inHandle, wavePtr, waveSize, &action, 0) && waveSize == action)
-
{
-
/* Play the WAVE */
-
if (!PlaySound((LPCSTR)wavePtr, 0, SND_MEMORY | SND_NODEFAULT))
-
{
-
printf("Error playing WAVE!\r\n");
-
}
-
}
-
else
-
{
-
printf("Error loading WAVE!\r\n");
-
}
-
-
/* Free the memory */
-
VirtualFree(wavePtr, waveSize, MEM_FREE);
-
}
-
else
-
{
-
printf("Can't get memory!\r\n");
-
}
-
}
-
else
-
{
-
printf("Bad WAVE size!\r\n");
-
}
-
-
/* Close the WAVE file */
-
CloseHandle(inHandle);
-
}
-
else
-
{
-
printf("Can't load the WAVE file!\r\n");
-
}
-
scanf("%c",&ch);
-
return(0);
-
}
0 1876 Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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 =...
|
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.
...
|
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. ...
|
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,...
|
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$) {
}
...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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,...
| |