jackneedshelp jackneedshelp - 28 days ago 18
C# Question

How to close Window Media Player after it is finish playing?

I want to know how to close the media player when it finishes playing my wav file. Because if I run this multiple times, it consumes an dangerous amount of computer ram. If you can solve that without closing it, by all means tell me.

var player = new WMPLib.WindowsMediaPlayer();
player.URL = @"D:\notes\01.wav";


This is the code to play it.

Answer

There isn't a way to exit the player, the only(not so ideal approach) is to kill it.

    var proc = Process.GetProcessesByName("wmplayer");
    if (proc.Length > 0) {
        proc[proc.Length - 1].Kill();
    }