0

私は InteropServices の使用に慣れていませんがWMPLib、コンソール アプリケーションから曲を再生するために使用しています。Visual Studio からデバッグすると、アプリケーションは期待どおりに動作します。しかし、クラッシュして次の例外が発生します。

Unhandled Exception: System.Runtime.InteropServices.COMException: The message filter indicated that the application is busy. (Exception from HRESULT: 0x8001010A (RPC_E_SERVERCALL_RETRYLATER))
   at WMPLib.IWMPPlayer4.get_controls()
   at ConsoleMP3Player.Program.Main(String[] args) in C:\Users\Ibrahim\Desktop\Console.Mp3\Console.Mp3\Program.cs:line 67

コマンドラインから実行すると:

C:\Users\Ibrahim\Desktop\Console.Mp3\Console.Mp3\bin\Debug>ConsoleMP3Player play

playコマンド の簡単なコードは次のとおりです。

var _player = new WindowsMediaPlayer();
_player.URL = "Full path to a mp3 file";
_player.controls.play();

どんな助けでも大歓迎です。

4

1 に答える 1

1

不適切な COM コントロールの代わりに、マネージドでスレッドセーフな MediaPlayer クラスを使用してみてください。PresentationCore と WindowsBase への参照を追加して、これを試してください。

using System.Windows.Media;

public void PlaySoundAsync(string filename)
{
    // This plays the file asynchronously and returns immediately.
    MediaPlayer mp = new MediaPlayer();
    mp.MediaEnded += new EventHandler(Mp_MediaEnded);
    mp.Open(new Uri(filename));
    mp.Play();
}

private void Mp_MediaEnded(object sender, EventArgs e)
{
    // Close the player once it finished playing. You could also set a flag here or raise another event.
    ((MediaPlayer)sender).Close();
}
于 2015-11-07T09:03:49.673 に答える