Search code examples
c#winformsbassbass.dll

How to combine two buttons


There is button_play and button_pause. I want to combine them into one button. The first time the song is pressed, the song starts playing. The second press - pause. At the third press, the playback continues. I can not do it.

Please tell me, how I can combine them.

private void button_play_Click(object sender, EventArgs e)
{
    if ((list_catalog.Items.Count != 0) && (list_catalog.SelectedIndex != -1))
    {
        string current = Vars.Files[list_catalog.SelectedIndex];
        Vars.CurrentTrackNumber = list_catalog.SelectedIndex;
        BassLike.Play(current, BassLike.Volume);
        label_time1.Text = TimeSpan.FromSeconds(BassLike.GetPosOfStream(BassLike.Stream)).ToString();
        label_time2.Text = TimeSpan.FromSeconds(BassLike.GetTimeOfStream(BassLike.Stream)).ToString();
        xrewind.Maximum = BassLike.GetTimeOfStream(BassLike.Stream);
        xrewind.Value = BassLike.GetPosOfStream(BassLike.Stream);
        timer1.Enabled = true;
    }
}

private void button_pause_Click(object sender, EventArgs e)
{
    BassLike.Pause();
}

Solution

  • Something like:

    private bool _isPlaying;
    
    private void button_Click(object sender, EventArgs e)
    {
        if(!_isPlaying)
        {
            mediaThing.Play();
            button1.Text = "Pause";
        }
        else
        {
            mediaThing.Pause();
            button1.Text = "Play";
        }
    
        _isPlaying = !_isPlaying;
    }