Mute Phone Audio when Headphones are Unplugged I only ever unmute my phone when my headphones are plugged into it. I'm looking to automate this process. Here's what I want to happen:

if (headphones are unplugged) {

  mute all audio on the phone

} else {

  play audio through headphones

}


I've heard of automation apps like Tasker and Task, but I don't really know how to use them, or even if this is possible.
I am using Macrodroid and Automate to demonstrate what you ask. 

With Macrodroid

You will need to create 2 macros.

1st macro: Headset plugged


In the Trigger tab, select Headphones Insert/Remove, then choose Headphones Inserted followed by Any.
In the Actions tab, select Volume Change, then give the appropriate permissions. Set the level of each audio stream (see below picture on the left).
Give the macro a name, then save it. It will look like the picture on the right.





2nd macro: Headset unplugged


In the Trigger tab, select Headphones Insert/Remove, then choose Headphones Removed.
In the Actions tab, select Volume Change, then give the appropriate permissions. Set the level of each audio stream to 0 (see below picture on the left).
Give the macro a name, then save it. It will look like the picture below on the right.





With Automate


In the Interface section, select "Wire headset plugged?", then link its IN with the OK of the "Flow beginning" block.
In the Camera &amp; Sound section, select "Audio stream mute state" twice. 


Click on the first block, set the state to Unmute, select an audio stream, then click Done. Link the IN to the Yes of the "When wire headset plugged" block, then Link the OK to the IN of the "When wire headset plugged" block.
Click on the second block, set the state to Mute, then select an audio stream. Link the IN to the No of the "When wire headset plugged" block, then Link the OK to the IN of the "When wire headset plugged" block.

It will look like the image below. Give your flow a name then save it, then click on Start.


Note: I have selected Music stream for this example. Only the music will be muted/unmuted. Add more blocks for the other audio streams (voice call, alarm, system, etc).