2017-06-09 9 views
0

私は、単純な音楽プレーヤーを書いていると私はので、私はPlaySoundがその機能をサポートしていませんので、これを実行するには、Microsoft :: DirectXの:: AudioVideoPlayback APIを使用しようとしている音楽を一時停止できるようにする必要があります。ただし、プログラムはブレークポイントをトリガして例外をスローします。Microsoft :: DirectX :: AudioVideoPlaybackを使用してオーディオを再生する方法

だから私は、空のフォームを持つ、新しい空のVisual C++ CLR空のプロジェクトを作成し、唯一の新しいオーディオオブジェクトを初期化し、オーディオファイルを再生するためのコードを追加し、私はまだ同じ例外を取得しています。問題が発生する行は、オーディオオブジェクトの新しいインスタンスが作成される行です。

私は非常にVisual Studioに経験していないと私は前にこのAPIを使用したことがありません。私はMicrosoft :: DirectXとMicrosoft :: DirectX :: AudioVideoPlayback .dllファイルへの参照をプロジェクトに追加しました。オーディオファイルはディレクトリにあります。私はオンラインで見つけたいくつかのことを試しましたが、何も効果がありませんでした。どんな助けでも大歓迎です!

#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 
}; 
} 

答えて

0

私は次のようしてきましたエラー:

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. 

私は問題を解決する方法を考え出しstackoverflowの上のいくつかの質問と回答を通過した後

ここMyForm.hファイルです。

  1. .configファイルを作成し、.exeファイルがあるフォルダに置きます。
  2. 名前あなたの.exeファイルは、拡張子(例:MusicPlayer.exeとMusicPlayer.exe.config)を含む命名されているもの.configファイル
  3. 次のコードを貼り付け.configファイル内

    <?xml version="1.0" encoding="utf-8" ?> 
    <configuration> 
        <startup useLegacyV2RuntimeActivationPolicy="true"> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> 
        </startup> 
    </configuration> 
    

    ソリューションエクスプローラ - >プロパティ - >構成プロパティ - >一般でプロジェクトを右クリックして、使用している.NETFrameworkのバージョンを確認できます。 Project Defaults - > .NET Target Framework Versionの下に表示されます。

関連する問題