0

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..?

4
Contributors
10
Replies
11
Views
6 Years
Discussion Span
Last Post by nick.crane
Featured Replies
0

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..

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

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 by TurkAlush: n/a

0

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 by nick.crane: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.