Hey
I have been trying to make a chatmachine, and i wanted to make it play music when the user asked for it, but the problem is how can i make the music stop again? Without closing the player, but by closing with the program..
I used this code

System.Diagnostics.Process.Start("C:Moves Like Jagger - Maroon 5 featuring Christina Aguilera - YouTube.mp3");

But how can i make it stop when the user writes stop..?

Don't really get that with killing it, can not find it..

I know that there are a wmp class, but I can not get that to work..

Process p = System.Diagnostics.Process.Start("C:Moves Like Jagger - Maroon 5 featuring Christina Aguilera - YouTube.mp3");

// when you want it to stop
p.Kill();

Thanks
But it have a problem..
the error is "Cannot process request because the process has exited."

else if (sætning.ToLower().Contains("musik"))
                    {
                        Console.WriteLine("Min musiksmag er stor, fordi jeg kan sådan set lide alt med lidt gang i den.");
                        Console.WriteLine("Hvad kan du lide af musik?");
                        Console.ReadLine();
                        Console.WriteLine("Ikke dårlig musiksmag, gør det noget jeg spiller noget musik?");
                        sætning4 = Console.ReadLine();
                        if (sætning4.ToLower().Contains("nej") || sætning4.ToLower().Contains("no"))
                        {
                            System.Diagnostics.Process p = System.Diagnostics.Process.Start("C:Moves Like Jagger - Maroon 5 featuring Christina Aguilera - YouTube.mp3");
                            Console.WriteLine("For at stoppe musikken skal du skrive stop");
                            sætning5 = Console.ReadLine();
                            if (sætning5 == "stop")
                            {
                                p.Kill();
                            }
                        }
                    }

It is in danish..

Edited 5 Years Ago by TurkAlush: n/a

That is probably because the process is actually a process spawned by Explorer that in turn executes WMP player. Therefore your p does not point to the WMP process.
Try using the command line arguments for media player in your command like this.

string filename = "C:Moves Like Jagger - Maroon 5 featuring Christina Aguilera - YouTube.mp3";
var commandArgs = string.Format(@"/play /close ""{0}""", filename);
System.Diagnostics.Process p = System.Diagnostics.Process.Start("Mplayer2.exe", commandArgs);

Edited 5 Years Ago by nick.crane: n/a

This question has already been answered. Start a new discussion instead.