I was using:
Tasker v5.9.2
AutoApps v1.8
AutoInput v2.8.1
Samsung Galaxy S10 (Android 10, security patch level "March 1, 2020")
AutoInput's accessibility service has to be granted access in "Settings / Accessibility / Installed services" (the exact method for this might vary for various phone models).
Here's the task's source (XML):
https://pastebin.com/Wv09dsL3
Here's a screenshot of the task:
https://imgur.com/lyfZguZ
To change the app that is to be force stopped, replace the "com.google.android.music" package name with the name of the app.