How to stop a song before starting another?

0

could you help me? I have been investigating and I can not find a solution.

I'm working on C #. I have a button called Play that executes this code

        //esto va hasta arriba donde estan los demas using
        using WMPLib;

         //esto se ejecuta al presionar un boton
        try
        {
             wplayer = new WindowsMediaPlayer
            {
                URL = rutaCancion //variable global tipo string
            };

            wplayer.controls.play();

        }

        catch (Exception exe)
        {

        }

rutaCancion contains the song route. When pressing the play button, the song is executed, the problem is that when I select another route, and press play, the previous song does not stop playing, but continues playing and the other song starts (they are played at the same time). / p>

How do I stop the previous song? I tried to put this code

            wplayer.controls.stop();

before giving play but no longer plays anything.

    
asked by Abner 15.04.2018 в 02:10
source

1 answer

0

If the idea is to play mp3 audio you could evaluate better libraries like being

NAudio

You can add the reference by means of nuget , analyze the example

Play an Audio File from a WinForms application

In the example, you use AudioFileReader to access the audio file.

Of course it's not the only library you could evaluate too

cscore

    
answered by 17.04.2018 в 05:35