5/08/2022

A Tasker (Android) Profile to Pause Your Audio Player

Purpose

Shake your phone left-right to pause/unpause your currently playing audio.

But do not do this while headphones (wired or Bluetooth) are connected - they have a pause button.

Also, do not do this if the current app is not the app that play the media. This way you can simply turn off this functionality by going to your home screen for example. This way you can avoid accidental activation.

Must work when screen is locked/display off, too.

Note: works for most apps, but does not work for Pandora :-( now browsers playing media.

Profiles and Tasks

Is a headset connected? Since this is an OR between two conditions and Tasker only allows AND connections in profiles, we use negation here: "a OR b" is the same as "NOT(NOT a AND NOT b)"

Profile: Headset DISconnected
	State: Not BT Connected [ Name:Kian's Headphones Address:* ]
	State: Not Headset Plugged [ Type:Any ]



Enter Task: Headset Disconnected

A1: Variable Set [
     Name: %HEADSET_CONNECTED
     To: false
     Max Rounding Digits: 3
     Structure Output (JSON, etc): On ]



Exit Task: Headset Connected

A1: Variable Set [
     Name: %HEADSET_CONNECTED
     To: true
     Max Rounding Digits: 3
     Structure Output (JSON, etc): On ]

Get the app that is currently playing:

Profile: Get music player
	Event: Music Track Changed [ Output Variables:* Track:* Album:* Artist:* Package:* Type:Playing or Not Playing ]



Enter Task: Music app

A1: Variable Set [
     Name: %MUSICPLAYER
     To: none
     Max Rounding Digits: 3 ]

<com.obreey.reader does not have tracks.
Otherwise we require a track, no track would indicate stopped instead of paused.>
A2: If [ %mt_track neq \%mt_track | %mt_app eq com.obreey.reader ]

    A3: Variable Set [
         Name: %MUSICPLAYER
         To: %mt_app
         Max Rounding Digits: 3 ]

A4: End If

Act on app changed, so we know what is the current app:

Profile: App Changed
	Event: App Changed [ Output Variables:* Package:* ]



Enter Task: App Changed


<Does not get called when screen is locked, so always represents the last open app.>
A2: Variable Set [
     Name: %CURRENT_APP
     To: %app_package
     Max Rounding Digits: 3
     Structure Output (JSON, etc): On ]

Pause on shake:

Profile: Pause Audio
	Event: Shake [ Axis:Left-Right Sensitivity:Very Low Duration:Medium ]
	State: Variable Value  [ %HEADSET_CONNECTED neq true ]
	State: Variable Value  [ %MUSICPLAYER eq %CURRENT_APP ]



Enter Task: Pause

<Does not work on Pandora!>
A1: Media Control [
     Cmd: Toggle Pause
     Simulate Media Button: On
     Package/App Name: %MUSICPLAYER ]

Enjoy.

No comments:

adaxas Web Directory