我正在编写一个简单的音乐播放器,我需要能够暂停音乐,所以我尝试使用Microsoft::DirectX::AudioVideoPlayback API来实现这个功能,因为PlaySound不支持这种功能。然而,程序总是触发断点并引发异常。
所以我用空表单创建了一个新的空Visual空项目,只添加了代码来初始化一个新的音频对象并播放一个音频文件,而且我仍然得到相同的异常。问题发生的行是创建音频对象的新实例的行。
我对Visual不是很有经验,我以前从未使用过这个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
};
}发布于 2017-06-25 13:47:08
我得到的错误如下:
An unhandled exception of type 'System.IO.FileLoadException' occurred in
System.Windows.Forms.dll
Additional information: Mixed mode assembly is built against version
'v1.1.4322' of the runtime and cannot be loaded in the 4.0 runtime without
additional configuration information.在浏览了几个关于堆栈溢出的问题和答案之后,我想到了如何解决这个问题。
https://stackoverflow.com/questions/44462807
复制相似问题