Prevent music players from auto play on bluetooth connect


Question

Whenever I connect my android device with a bluetooth device, it automatically starts spotify and starts playing.

As far as I know this also happens to other users/players (according to google)



How can I prevent this (without signing out of spotify)?



Android: 6.0.1
Spotify Version: 6.2.0.1015


Answer

Background



Major part of this guide was extracted here: How to Disable Bluetooth Automatic Playback on any Android Phone



The point of this guide isn't to disable Bluetooth music entirely, otherwise the latter can easily be achieved by:



Disable Bluetooth Music : Settings >> Bluetooth >> Your device(Car) >> Settings  then uncheck audio support.



..and this simply destroys the whole purpose of the guide.



 It is important to know that autoplay is a feature of many Bluetooth devices, despite the fact people do see this "feature" as a problem though, which is the original reason the original author wrote the guide.






Understanding Bluetooth Autoplay on Android




  • What essentially happens when you connect a Bluetooth device that sends an autoplay command is that this command is seen as a KeyEvent for toggle play/pause in Android.


  • Applications with a MediaButtonReceiver broadcast receiver can then react to this Media Button event.


  • Android keeps track of the last application that requests to receive Media Button events.





Any new media application can take over to listen to Media Button key
events by calling setMediaButtonReceiver in AudioManager, and that
application will handle Media Button key events until another
application requests control.




You can actually see which application is currently set to respond to these key events by entering the following ADB command:



adb shell settings get secure media_button_receiver



On the author’s device, this command yielded the following output:



com.google.android.music/com.google.android.music.playback.MediaButtonIntentReceiver




This is the broadcast receiver set up by Google Play Music to respond
to Media Button key events. So if I plug in my Bluetooth device, my
phone will automatically start playback in Google Play Music.




Disabling Bluetooth Autoplay with Tasker



Profile (or Trigger)




  • Goto Profiles Tab and click the "+"

  • Event >> State >> Net >> BT Connected

  • Tap back to exit from this window



Task



You will notice as soon as you exit, you will be prompted to link this to a Task




  • Scroll all the way up the Task list select "New Task + "

  • You can just keep it anonymous or give it a name

  • Click "+" to add new Action

  • Media >> Media Button Events >> Grab

  • Tap back to exit from this task



AFAIK root is not necessary for this task



enter image description here enter image description here enter image description here



Once you’re done, Tasker should now automatically set itself as the Media Button Receiver in Android upon connection to your selected Bluetooth devices. This way, the play/pause action that is sent will not be received by any of your media applications, but instead by Tasker



Unfortunately I couldn’t get Spotify or Soundcloud music application to replicate the issue. However, I retested this feature using a PC with the remote audio service (Bluetooth module on my PC supports that) to test the bluetooth autoplay feature.



Tests done




  1. Enabled Bluetooth audio service (to use PC speakers to listen to remote audio).


  2. Open two different music apps on android and played music and play


  3. Created a “media button grab” in Tasker to handle Media Button key events.


  4. Retested (2) with Tasker running the previously created task.




enter image description here



Results




  1. On test (2) the audio output was transferred to PC speakers indicating that the autoplay feature was still active.


  2. After performing test (4), the audio sound output came from android and was not transferred to PC speakers. Which essentially solves the issue.







Alternatively..



Head to playstore and get Bluetooth connect & Play



enter image description here enter image description here enter image description here



You can tell it which app should play for each bluetooth device (or to NOT play on a given BT device)



Acknowledgements




Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes