How to play, pause and stop a song with only one button?

前端 未结 4 706
野的像风
野的像风 2021-01-16 10:23

I have tried to make an application in android to play, pause and stop a song with one button only.

Can anyone show me how can I make that application?

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-16 10:54

    With one button, the idea, I would guess, can be as follows:

    • Keep a boolean indicating whether the playback is active at the moment; set it to true when you start playback, and false when you stop/pause it or it completes.
    • On a regular tap of the button, if no playback is active, then start the playback
    • On a regular tap, if playback is active, then pause it
    • On a long tap, if playback is active, stop it

提交回复
热议问题