• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Tasker - Sleep timer.

I'm looking to do a rather specific implementation of a sleep timer.

A favorite audio book app of mine (Audiobook Player 2) has a custom implementation of the standard sleep timer that I rather love... the app has various other issues that prevent me from using it, and no other player I've run across has anything like it. I'm thinking I can emulate the behavior with Tasker, and I'm wondering if any Gurus out there might be able to help me along.

Here's how AP2's sleep timer works:

1.) Once you start playing audio, countdown begins. You don't need to turn the timer on every time.

2.) After, say, five minutes, you'll hear a beep letting you know the book is about to turn off.

3.) At this point, you can just shake the phone to reset the sleep timer for another five minutes. It will beep again to confirm your shake.

I'm primarily concerned with the beep-and-reset function. I'd love to do it by shaking the phone, but almost any other implementation would be just fine by me.

Thanks in advance for any ideas!
 
If you're looking for Tasker to interact with AP2, you'll need to be rooted, and probably running a Cyanogenmod ROM. If you're looking to do this independent of AP2, the you could try something like this:

Task:
Music Play <filename>
Wait 4 minutes 30 seconds
Variable Set %AUDIOTIMER = 1
Notify Sound <notification sound>
Wait 30 seconds
If %AUDIOTIMER Is Set
Variable Clear %AUDIOTIMER
Goto 2
End If


Profile: StopAudioTimer
Context: Variable Value %AUDIOTIMER Is Set
Context: Shake
Task:
Variable Clear %AUDIOTIMER
Music Stop


You could then set a widget or shortcut to run the first task. After 4.5 minutes the %AUDIOTIMER variable is set, allowing the StopAudioTimer profile to activate upon shaking the phone. If you shake the phone during the following 30 second window, the audio will stop.

This isn't a complete solution, as it still needs a way to select the audio file, and you want to stop the audio during the 4.5 minute wait. But this should get you headed in the right direction.
 
Thanks for the reply! I spent three or four hours on this yesterday, though, after this post and got it mostly worked out. I came up, for the most part, with something very similar to what you posted, although mine is (possibly unnecessarily) more convoluted.

My biggest hurdle to date is the "shake" thing... shaking uses the accelerometer (or so I guessed) to check orientation, which, due a limitation in Android, can't be done while the screen is off. Additionally, the "Display On" function in Tasker no longer functions in 2.3+, so I ended up needing to use a "popup" function to accomplish the same goal. For some reason, though, the "shake" function won't respond while the popup is active, which results in me needing to wait three seconds or so before shaking it. Only a slightly irritating kink in my kludge, but it works for the nonce.

I'm going to try to remember to post my finished product when it's more elegant.
 
Back
Top Bottom