Ivo Stoyanov
Ivo Stoyanov

Reputation: 18749

When I start Android Emulator, the audio on my Mac desktop stops

When I start Android Emulator, the audio on my Mac desktop stops. It starts again when I close the emulator.

Upvotes: 88

Views: 26310

Answers (6)

Paweł Kanarek
Paweł Kanarek

Reputation: 2627

I found easier way than accepted answer from @Ivo Stoyanov to solve this. Just open the emulator config file (for my mac it's ~/.android/avd/{emulator_name}/config.ini and set

hw.audioInput=no
hw.audioOutput=no

Screen from visual studio code

If it's not working then you should "Wipe Data" and "Cold Boot Now" in Android Virtual Device Manager screen from android virtual device manager

Upvotes: 200

on Mac OS Ventura: System preferences > Privacy and Security > Microphone > un-check Android Studio

Upvotes: -1

Praxder
Praxder

Reputation: 2759

To build off @paweł-kanarek answer, here's a small script that loops through all of the Android emulators on your machine and adds

hw.audioInput = no
hw.audioOutput = no

at the end of the file (or replaces it if you already have these options specified).

#!/bin/bash
find ~/.android/avd -name "config.ini" | while read line
do
   awk '!/audio/' $line > tmp
   rm $line
   mv tmp $line
   echo "hw.audioInput = no" >> $line 
   echo "hw.audioOutput = no" >> $line 
done

To run this, simply add this code to a local bash script (I named mine 'disable_emulator_sound.sh'). Then, make it executable with the command chmod +x disable_emulator_sound.sh and run it with ./disable_emulator_sound.sh.

Note: as mentioned in the original answer, after making this change, if it's not working you might have to go into the emulator options menu and run 'Wipe Data' and then run 'Cold Boot Now'.

Upvotes: 26

Morteza Rastgoo
Morteza Rastgoo

Reputation: 6986

Based on Joachim's post:

If you have some Bluetooth headphones and notice a strange hissing sounds while the emulator is running, you might find it useful to add the -noaudio

To have a permanent fix to affect all your virtual devices do the following:

Create a .plist file e.g. studio-environments.plist in the folder ~/Library/LaunchAgents/ with the following content:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>setenv.studio.emu.params</string>
    <key>ProgramArguments</key>
    <array>
        <string>/bin/launchctl</string>
        <string>setenv</string>
        <string>studio.emu.params</string>
        <string>-writable-system,-noaudio</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

To load these changes directly (e.g. to apply changes without rebooting your Mac)

launchctl load ~/Library/LaunchAgents/studio-environments.plist

Extras:

If you run the command while it is already loaded, you will get an error message like this

Load failed: 5: Input/output error

You have to unload it before with

launchctl unload ~/Library/LaunchAgents/studio-environments.plist

You can check your changes with this command:

launchctl getenv studio.emu.params

Note: You won’t hear any sound from the emulator anymore, but the hissing will be gone too

Upvotes: 12

sebokopter
sebokopter

Reputation: 366

You can also withdraw the microphone access for Android Studio in MacOS System Settings in "Security & Privacy". (Though I don't know how well/if it works, since I went for the config.ini approach.)

Step by Step: Link to a better explaination with pictures

  • Go to MacOS "System Preferences" > "Security & Privacy" > Microphone.
  • Click on lock icon on the bottom left to enable editing.
  • Then uncheck the checkmark on Android Studio in the application list on the right.

Kudos to Matt McKenna who shared this on his blog. He wrote about the solution and the background here: https://blog.mmckenna.me/android-emulators-vs-bluetooth-headphones

Upvotes: 6

Ivo Stoyanov
Ivo Stoyanov

Reputation: 18749

When the emulator is started with enabled audio, sometimes it overrides the audio channel of the Mac machine. This happens even if you disable access to the microphone for Android studio in Security settings. To fix the issue you should start the emulator with disabled audio.

There are two options to start the emulator with disabled audio:

I. Start the emulator from the console:

emulator -avd Pixel_2_API_27 -qemu -no-audio

II. If you want to start the emulator with disabled audio directly from Android studio, you should replace the emulator file with a script that will run emulator with additional parameters:

Android Studio by default uses the binary $ANDROID_SDK/emulator/emulatorwhich is located in: ~/Library/Android/sdk/emulator/

You have to do the following:

  1. Rename the emulator binary to emulator-original.

  2. Create a bash script text file with the name emulator that contains:

#!/bin/bash    
~/Library/Android/sdk/emulator/emulator-original $@ -qemu -no-audio
  1. Set the newly created script permissions with chmod +x emulator

Now, Android Studio will run your script that will run the original binary with the addtitional parameters to disable emulator's audio.

N.B. Kudos for the script solution to MartinCR who proposed it here.

Upvotes: 70

Related Questions