Why my button not work correctly? SDL2
<p>I try to make little program with SDL2 and C++. There is a window and button on window. I want to do that when I press first time the button music starts to play. Yeah I made it work.</p>

<pre><code>            if((mouseX &gt;= buttonRect.x &amp;&amp; mouseX &lt; (buttonRect.x + buttonRect.w)) &amp;&amp; (mouseY &gt;= buttonRect.y &amp;&amp; mouseY &lt; (buttonRect.y + buttonRect.h))){
                if(event.button.button == SDL_BUTTON(SDL_BUTTON_LEFT)){
                    if(Mix_PlayingMusic() == 0){
                        Mix_PlayMusic(music, -1);
                    }
                }
            }
</code></pre>

<p>But I want to make that when button is pressed second time music would pause. And if it will pressed again it resume.</p>

<p>I tried this:</p>

<pre><code>            if((mouseX &gt;= buttonRect.x &amp;&amp; mouseX &lt; (buttonRect.x + buttonRect.w)) &amp;&amp; (mouseY &gt;= buttonRect.y &amp;&amp; mouseY &lt; (buttonRect.y + buttonRect.h))){
                if(event.button.button == SDL_BUTTON(SDL_BUTTON_LEFT)){
                    if(Mix_PlayingMusic() == 0){
                        Mix_PlayMusic(music, -1);
                    }else{
                        if(Mix_PausedMusic() == 1){
                            Mix_ResumeMusic();
                        }else{
                            Mix_PauseMusic();
                        }
                    }
                }
            }
</code></pre>

<p>But it won't work. When I press the button music starts and stops instantly. If If I hold mouse button down on the button music will play, but if I move mouse it stops.</p>