jackneedshelp jackneedshelp - 1 year ago 119
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 Source

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();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download