jackneedshelp
jackneedshelp

Reputation: 137

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.

Upvotes: 3

Views: 3103

Answers (2)

Mohit S
Mohit S

Reputation: 14024

This might do the trick for you

var player = new WMPLib.WindowsMediaPlayer();
player.URL = @"D:\notes\01.wav";
Thread.Sleep(2000);
player.controls.stop();
player.close();

Edit

Than you can kill the process and stop the WMPlayer

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

Upvotes: 0

Basvo
Basvo

Reputation: 156

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();
    }

Upvotes: 2

Related Questions