Share your Android screen and audio on macOS
Tags: productivity, tutorial, beginners, devtips
Published: 2020-10-08 13:56:56

Forget it about Vysor, there is a better and *FREE* option to screencast your Android screen called [scrcpy](https://github.com/Genymobile/scrcpy) and [sndcpy](https://github.com/rom1v/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.

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

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

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

Run this commands on terminal:

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

Restart your terminal, then update and upgrade brew sources:

```bash
brew update --force --quiet
brew upgrade
brew cleanup
```
<figcaption>https://brew.sh — usage: https://docs.brew.sh/FAQ</figcaption>


Run this command, and follow doctor recommendations:

```bash
brew doctor
```

## Android Debug Bus (ADB) 

You need [adb](https://developer.android.com/studio/command-line/adb), accessible from your PATH. 

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

```bash
brew install --cask android-platform-tools
```

### 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](https://dev-to-uploads.s3.amazonaws.com/i/4s6lwe35ikzr0sccly41.png)

## VideoLan

[VLC](https://www.videolan.org/) the famous cross-platform multiplayer.

```bash
brew install --cask vlc
```

# 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.

```bash
brew install scrcpy
```

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](https://github.com/Genymobile/scrcpy#features) to learn the keyboard shortcuts and other features.

# 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](https://github.com/rom1v/sndcpy#get-the-app) from GitHub and extract those files on the recommended path: `~/Applications/Android/sndcpy`.

## Alias

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

```bash
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"
```

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](https://dev-to-uploads.s3.amazonaws.com/i/2zpgyrh52n11wrnnqb2q.png)

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](https://dev-to-uploads.s3.amazonaws.com/i/s5ap9bae9tw84hu35eiu.gif)

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:

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

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:

```bash
#!/bin/bash

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

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

![sndcpy](https://dev-to-uploads.s3.amazonaws.com/i/4s9bnv29vzofd8ipvp89.png)

![scrcpy](https://dev-to-uploads.s3.amazonaws.com/i/kcydtww21524zh2fa7c1.png)

## iTerm

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

![goku](https://dev-to-uploads.s3.amazonaws.com/i/tc0robgnf1w6n8liwcc3.gif)

Add this code to `scrsnd.sh` file:

```bash
#!/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
```

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

![iterm](https://dev-to-uploads.s3.amazonaws.com/i/dxfg0v51luz41c91kyoc.png)

___

**That’s All Folks!**
**Happy Coding** 🖖

[![beer](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mkgsx4aw6qn9i9ax6as9.png)](https://github.com/sponsors/deinsoftware)