DEV Community

Cover image for Share your Android screen and audio on macOS
Camilo Martinez
Camilo Martinez

Posted on • Edited on

Share your Android screen and audio on macOS

Forget it about Vysor, there is a better and FREE option to screencast your Android screen called scrcpy and sndcpy as a complement.

With both of them, you will can screencast your android mobile screen and also forward audio to your computer. Sadly they need to run separately.

Command Meaning
scrcpy Screen Copy
sndcpy Sound Copy

In this post, we are going to focus only on macOS devices, but you also can use it as a guide for Windows or Linux following the links on each project.

Prerequisites

Homebrew

Brew has his own classification. The inside brew can found the CLI app and utilities. Inside is cask all the application with Graphical Interface.



/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"


Enter fullscreen mode Exit fullscreen mode

Add this lines to ~/.bash_profile and/or ~/.zshrc file:



# Brew
export BREW_HOME="/opt/homebrew/bin"
export PATH="$BREW_HOME:$PATH"
eval "$($BREW_HOME/brew shellenv)"


Enter fullscreen mode Exit fullscreen mode

Run this commands on terminal:



eval "$(/opt/homebrew/bin/brew shellenv)"
source ~/.zshrc
source ~/.bash_profile


Enter fullscreen mode Exit fullscreen mode

Restart your terminal, then update and upgrade brew sources:



brew update --force --quiet
brew upgrade
brew cleanup


Enter fullscreen mode Exit fullscreen mode
https://brew.sh — usage: https://docs.brew.sh/FAQ

Run this command, and follow doctor recommendations:



brew doctor


Enter fullscreen mode Exit fullscreen mode

Android Debug Bus (ADB)

You need adb, accessible from your PATH.

If you already have installed Android Studio it's most probably that you already have installed ADB.



brew install --cask android-platform-tools


Enter fullscreen mode Exit fullscreen mode

Check connection

To use adb with a device connected over USB, you must enable USB debugging in the device system settings, under Developer options.

On Android 4.2 and higher, the Developer options screen is hidden by default. To make it visible, go to Settings -> About phone and tap Build number seven times. Return to the previous screen to find Developer options at the bottom.

Connect your Android device via USB, and run adb devices command to list available devices.

adb-devices

Install scrcpy

This application provides display and control of Android devices connected on USB (or over TCP/IP). It does not require any root access. It works on GNU/Linux, Windows and macOS.



brew install scrcpy


Enter fullscreen mode Exit fullscreen mode

Now you can run scrcpy command no mather the path where you are. It will mirror your mobile on your device. Press ctrl+c in the terminal to stop.

It's recommended to see the documentation to learn the keyboard shortcuts and other features.


DEPRECATED: you don't need to follow instructions below or install sndcpy and vlc any more, because scrcpy includes forward audio support from version 2.


Install sndcpy

This tool forwards audio from an Android 10 device to the computer. It does not require any root access. It works on GNU/Linux, Windows and macOS.

There is no brew formula available but we can download from GitHub and extract those files on the recommended path: ~/Applications/Android/sndcpy.

VideoLan

VLC the famous cross-platform multiplayer.



brew install --cask vlc


Enter fullscreen mode Exit fullscreen mode

Alias

Assuming you have extracted files on recommended path, add this configurations on ~/.bash_profile and/or ~/.zshrc file:



export SNDCPY_HOME="$HOME/Applications/Android/sndcpy"
export SNDCPY_APK="$HOME/Applications/Android/sndcpy/sndcpy.apk"
export PATH="$SNDCPY_HOME/:$PATH"
alias sndcpy="sh sndcpy"


Enter fullscreen mode Exit fullscreen mode

Update terminal source with this command source ~/.bash_profile or source ~/.zshrc to recognize new paths and aliases. Now you can run sndcpy command no mather the path where you are.

Pairing

It will install the app on the device, and request permission to start audio capture:

pairing

Once you clicked on START NOW, press Enter in the console to start playing on the computer. Press ctrl+c in the terminal to stop.

VLC may print this error message once:

main stream error: connection error: Connection refused

It is "expected", just ignore it. The sound continues to be played on the device. The volume can be adjusted independently on the device and on the computer.

Fusion

They need to run on an independent terminal. What if I teach you how to use the fusion technique with them?

fusion

It's time to convert scrcpy and sndcpy into scrsnd.

On the recommended sndcpy path create an empty file on called scrsnd.sh and set execution permissions with chmod +x scrsnd.sh. Leave empty by now.

And add this alias on ~/.bash_profile and/or ~/.zshrc file:



alias scrsnd="sh $SNDCPY_HOME/scrsnd.sh"


Enter fullscreen mode Exit fullscreen mode

Update terminal source with this command source ~/.bash_profile or source ~/.zshrc to recognize new alias.

It's time to choose one of these roads: Terminal or iTerm.

Terminal

If you prefer to use the built-in Terminal app, add this code to scrsnd.sh file:



#!/bin/bash

osascript <<'END'
tell application "Terminal" to do script "sndcpy"
tell application "Terminal" to do script "scrcpy"
END


Enter fullscreen mode Exit fullscreen mode

Run the scrsnd command and you will see that open two terminals, one with sndcpy and the other with scrcpy.

sndcpy

scrcpy

iTerm

That's my favorite because you can unleash all the power on a single terminal window.

goku

Add this code to scrsnd.sh file:



#!/bin/bash

osascript <<-EOF
    set cmds to {"sndcpy", "scrcpy"}

    tell application "iTerm"
        activate
        create window with default profile

        tell current session of current window
            split vertically with default profile
        end tell

        tell first session of current tab of current window
            write text "sndcpy"
        end tell
        tell second session of current tab of current window
            write text "scrcpy"
        end tell

    end tell
EOF


Enter fullscreen mode Exit fullscreen mode

Run the scrsnd command and you will see a single-window opened in split view with sndcpy and scrcpy.

iterm


That’s All Folks!
Happy Coding 🖖

beer

Top comments (3)

Collapse
 
uwe profile image
Uwe Hollatz

super cool tutorial, I got it running under ten minutes :)

Collapse
 
akyskyer profile image
Akash Kumar

Press Enter once audio capture is authorized on the device to start playing...
after i press enter this prompt is thrown
./sndcpy: line 29: vlc: command not found
😞

Collapse
 
equiman profile image
Camilo Martinez

You need to have installed VLC.