首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Microsoft::DirectX::AudioVideoPlayback播放音频?

如何使用Microsoft::DirectX::AudioVideoPlayback播放音频?
EN

Stack Overflow用户
提问于 2017-06-09 16:36:22
回答 1查看 534关注 0票数 0

我正在编写一个简单的音乐播放器,我需要能够暂停音乐,所以我尝试使用Microsoft::DirectX::AudioVideoPlayback API来实现这个功能,因为PlaySound不支持这种功能。然而,程序总是触发断点并引发异常。

所以我用空表单创建了一个新的空Visual空项目,只添加了代码来初始化一个新的音频对象并播放一个音频文件,而且我仍然得到相同的异常。问题发生的行是创建音频对象的新实例的行。

我对Visual不是很有经验,我以前从未使用过这个API。我向项目添加了对Microsoft::DirectX和Microsoft::DirectX::AudioVideoPlayback .dll文件的引用,音频文件位于目录中。我试过一些我在网上找到的东西,但都没有用。任何帮助都将不胜感激!

下面是MyForm.h文件:

代码语言:javascript
复制
#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
};
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-06-25 13:47:08

我得到的错误如下:

代码语言:javascript
复制
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.

在浏览了几个关于堆栈溢出的问题和答案之后,我想到了如何解决这个问题。

  1. 创建一个.config文件并将其放在.exe文件所在的文件夹中。
  2. 将.config文件命名为.exe文件,包括扩展名(例如MusicPlayer.exe和MusicPlayer.exe.config)
  3. 将以下代码粘贴到.config fileYou中,可以通过右键单击解决方案资源管理器->属性中的项目,然后在Configuration -> General中检查.NETFramework的哪个版本。您应该在Project -> .NET目标框架版本下看到它。
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44462807

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档