简体   繁体   English

播放.wav文件

[英]playing a .wav file

I'm using visual studio 2010 express and I'm trying to write a simple program that will repeat a wave file 5 times(I'm running a windows xp sp3). 我正在使用Visual Studio 2010 Express,并且正在尝试编写一个简单的程序,该程序将重复Wave文件5次(我正在运行Windows XP SP3)。

This is as far as I got: 这是我得到的:

#include "stdafx.h"
#include <windows.h>
#include <iostream>

using namespace std;   
int main ()
{
    int a = 5;
        while(a >= 1){
            cout << "It's a wav file";
            PlaySound(L"SomeAudioFile-01.wav", NULL, SND_FILENAME);
            --a;
        }
    return 0;
 }

The problem is I keep getting this error message when I'm building it: 问题是我在构建它时不断收到此错误消息:

1>------ Build started: Project: It's a F**king Country, Configuration: Release Win32 --    ----
1>  mycode.cpp
1>..\..\..\..\..\Shaul's documents\Visual Studio 2010\Projects\MyProject\Release\SomeAudioFile-01.wav : fatal error LNK1136: invalid or corrupt file
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

The file is perfectly fine and plays with no problems whatsoever outside visual studio. 该文件非常好,在视觉工作室之外没有任何问题。

Help would be truly appreciated. 帮助将不胜感激。

不是将WAV文件添加到项目文件中,而是将其添加到资源并使用SND_RESOURCE而不是SND_FILENAME

You include the sound file as a object file, so the compiler tries to link with it. 您将声音文件包含为目标文件,因此编译器会尝试与其链接。 But it's a binary file that's not linkable (which is what the error message says). 但这是一个不可链接的二进制文件(这是错误消息所显示的内容)。

Don't include the sound file in the project, so the environment won't link with it. 不要在项目中包含声音文件,因此环境不会与之链接。

PS In the future, please refrain from using "bad" words on a public site like this. PS将来,请不要在这样的公共网站上使用“坏”字。

To get rid of the linker error, you need to tell the IDE to link with the winmm.lib library also, so open Project/Properties/Configuration Properties/Linker/Input and append winmm.lib in the Additional Dependencies field. 要摆脱链接器错误,您需要告诉IDE还要与winmm.lib库链接,因此打开Project / Properties / Configuration Properties / Linker / Input并在Additional Dependencies字段中附加winmm.lib

Also, use the following function profile: 另外,使用以下功能配置文件:

PlaySound(L"audio.wav", NULL, SND_APPLICATION); PlaySound(L“ audio.wav”,NULL,SND_APPLICATION);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM