我正在编写一个简单的音乐播放器,并且我需要能够暂停音乐,因此我尝试使用 Microsoft::DirectX::AudioVideoPlayback API 来执行此操作,因为 PlaySound 不支持该功能。但是程序不断触发断点并抛出异常。
所以我用一个空表单创建了一个新的空 Visual C++ CLR 空项目,只添加了初始化新音频对象和播放音频文件的代码,我仍然得到同样的异常。出现问题的行是创建音频对象的新实例的行。
我对 Visual Studio 不是很有经验,而且我以前从未使用过这个 API。我在项目中添加了对 Microsoft::DirectX 和 Microsoft::DirectX::AudioVideoPlayback .dll 文件的引用,音频文件在目录中。我尝试了一些我在网上找到的东西,但没有任何效果。任何帮助将不胜感激!
这是 MyForm.h 文件:
#pragma once
namespace Project3 {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace Microsoft::DirectX::AudioVideoPlayback;
/// <summary>
/// Summary for MyForm
/// </summary>
public ref class MyForm : public System::Windows::Forms::Form
{
public:
MyForm(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~MyForm()
{
if (components)
{
delete components;
}
}
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->components = gcnew System::ComponentModel::Container();
this->Size = System::Drawing::Size(300,300);
this->Text = L"MyForm";
this->Padding = System::Windows::Forms::Padding(0);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
Audio^ myAudio;
myAudio = gcnew Audio("Carl Grimes - Carl Poppa.wav", false);
myAudio->Play();
}
#pragma endregion
};
}