I have a simple doorbell application. I've implemented a timer which changes the image of the ImageButton
after a certain amount of time.
When the button is pressed, the phone plays a sound, vibrates, changes the image at millisecond 0 and then again at millisecond 2807 (this is the length of my sound file).
I've a function which basically states that if (!sound.isPlaying()) { (Do something) }
. This works just fine, but when the button is pressed rapidly, sometimes the image will change within a second and the button can be pressed rapidly, allowing the sound file to be played rapidly and the phone to vibrate whenever it is pressed, rather than on a set time.
I was wondering if there was a function which allows me to say certain things can happen when a timer is running, and only when it is. Ie: if (!timer.isRunning()) { (Allow everything to function as normal) }
, thus allowing the button to function only when there is no timer currently running.
I already have a couple of these similar statements running:
if ((booleanName) && !(soundName).isPlaying()) {
(vibrate)
(play Sound)
(change image on 0ms based on timer)
(change image on 2807ms based on timer)
} else if (!(booleanName) && !(soundName).isPlaying()) {
(play Sound)
(change image on 0ms based on timer)
(change image on 2807ms based on timer)
}
I want to add another condition to the statement, something like !timerTask.isRunning()
so that it will only run when the timer is not. For some reason, if statement's conditions are being met even though the sound is playing.
Would putting the (vibrate) and (play Sound) functions on a timer which starts at 0ms (such as the first image change), allow those functions to happen only at the appropriate time, or would this make a difference?
Aucun commentaire:
Enregistrer un commentaire