C# Windows Form WMPLib cannot set currentposition

95 Views Asked by At

I think this should be working but I do not know why I try and do anything to set the current position or return the current position of a playing audio using the WMPLib inside of VS 2019 here is my code (sorry spaghetti) but basically I'm trying to make a pause function in my windows form thing PictureOfWindowsFormApp

        private void button1_Click(object sender, EventArgs e)
        {
            Console.WriteLine(paused);
            playsound();
            if(paused == true)
            {
                wmpPlayer.controls.currentPosition = currenttime;

                paused = false;
            }

        }

     
        private void button3_Click(object sender, EventArgs e)
        {
            double currenttime = wmpPlayer.controls.currentPosition;
            wmpPlayer.controls.stop();
            paused = true;

        }
    }
}

I've been looking for hours for different methods seeing if there were current position changes or some shit like that

1

There are 1 best solutions below

0
On

Instead of trying to keep the currentPosition and setting it back, you can use the Pause() and Play() functions. Using Play(), when it is paused, will just resume where it was currently at.

private void button1_Click(object sender, EventArgs e)
{
    Console.WriteLine(paused);
    playsound();
    wmpPlayer.controls.play();
}


private void button3_Click(object sender, EventArgs e)
{
    wmpPlayer.controls.pause();
}