Skip to content

droidcpy - A Polybar script to control your Android device remote control services. Mirror display with handling, Audio, Webcam. Using scrcpy, sndcpy and v4l2loopback with IP Webcam.

License

tkapias/polybar-droidcpy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

droidcpy

A Polybar script to control your Android device remote control services. Mirror display with handling, Audio, Webcam. Using scrcpy, sndcpy and v4l2loopback with IP Webcam.

image

image

The configurations proposed by this repository are not adapted to all operating systems or easily customized without reading some code. It is dedicated to advanced Android/Linux users who run at least Polybar and Systemd, ideally i3wm too.

You can use the Systemd services wthout Polybar from the terminal, but it's cumbersome to monitor the status of the services and toggle their state from the command line.

Features

  • Display a panel with 3 icons/controls on the status bar, when the Android device is connected on USB.
  • A left-click Stop/start the services cleanly with the same icon.
  • The status of the device and services is displayed graphically.
    • The panel check if the device is connected to ADB and finished booting, if the device is disconnected the panel is hidden.
    • Icons displays the current status of the services by their color: activated, failed, stopped.
    • The background of the Panel is Green if any service is Activated.
      • Or Red if a service is still activated or failed when the device is not ready.

Limitations

  • My testing device was rooted and runs on Android 11, but it should work without root and at least from Android 10.
  • Clicking on a failed service try to start it again, not to stop it:
    • If you disconnect the device while a service is running, it may not stop but switch to failed, you will have to reconnect the device and start/stop cleanly before disconnecting again. Or the Red icon will stay visible.
  • I choose to limit the bitrate (2M) and the resolution (1024) in the parameters to get the best perfs, you can tweak the exec command in the systemd service files.
  • On some device the orientation of the Webcam may be wrong, you can change those settings in the IP Webcam app or in the systemd service file.
  • As it was a quick project and the scripts are commented, I did not centralize options, device name or output colors. There is no central ENV or attributes, you wil have to find it in the code.
    • The scripts are not written to work when there is more than 1 device connected on ADB. And you have to specify the name of your device in the script, or use a wildcard, but then any adb device will show the panel.
  • I did not find any good open source solution for the IP webcam application on Android, it's possible to use Open Camera with scrcpy and v4l2loopback to forward the picture from the screen but it's more limited. But IP Webcam Pro seems to be a clean and serious application.

Requirements

  • scrcpy: display and control of Android devices connected via USB.
    • On Debian and Ubuntu: apt install scrcpy
    • On Arch Linux: pacman -S scrcpy
    • Make sure you enabled adb debugging on your device.
  • sndcpy.apk: audio forwarding of Android devices connected via USB.
    • You need only the APK from release 1.1
    • Install the sndcpy.apk to your device manually or by droping it in scrcpy file drop.
    • polybar-droidcpy use ffplay from the Ffmpeg package, instead of vlc:
      • On Debian and Ubuntu: apt install ffmpeg
      • On Arch Linux: pacman -S ffmpeg
  • v4l2loopback: kernel module to create V4L2 loopback devices.
    • On Debian and Ubuntu: apt install v4l2loopback-dkms
    • On Arch Linux: pacman -S v4l2loopback-dkms
    • Create a first loopback device (/dev/video0): sudo modprobe v4l2loopback
    • To load the device after reboot add a new file to your system,
      • with the content "v4l2loopback": sudo echo "v4l2loopback > "/etc/modules-load.d/v4l2loopback.conf
  • IP Webcam Pro: turns your phone into a network camera.
    • I use the Pro version but it should work with the Lite version too.
    • I changed some settings in the app manually:
      • Video Preferences/Main caméra: Frontal
      • Video Preferences/Resolution: 1280x720
      • Video Preferences/Quality: 80
      • Video Preferences/Orientation: Landscape
      • Local Sharing/Port: 8082 (used in systemd config)
      • Audio Mode: Disabled
  • [ADB] Google/Android useful tool for debugging android devices:
    • On Debian and Ubuntu: apt install android-tools-adb
    • On Arch Linux: pacman -S android-tools
    • Check if you see you device : adb devices -l
  • Polybar: beautiful and highly customizable status bars.
    • On Debian and Ubuntu: apt install polybar
    • On Arch Linux: pacman -S polybar
    • You need to customize your config.ini to incorporate droidcpy as a module.
  • Nerd Fonts: Nerd Fonts takes popular programming fonts and adds a bunch of Glyphs.
  • Systemd: system and service manager for Linux operating systems.
    • Your desktop operating system probably works on this manager. If not, it's complicated to install it.

Optional

  • i3wm: a tiling window manager for X11.
    • It's not mandatory but I use a fork with more features: i3wm-gaps

Installation

  • Check all the Requirements.
  • Copy polybar-droidcpy's repo on your machine:
    cd /tmp
    git clone https://github.com/tkapias/polybar-droidcpy.git
    cd polybar-droidcpy
  • Add the systemd services to your user:
    cp systemd/user/* ~/.config/systemd/user/
    mkdir ~/.logs
    systemctl --user daemon-reload
    systemctl --user status scrcpy.service sndcpy.service v4l2-ipwebcam.service
  • Copy the Polybar droidcpy script to your config directory:
    mkdir ~/.config/polybar/scripts/
    cp polybar/scripts/droidcpy.sh ~/.config/polybar/scripts/
  • Change the name of your device (variable my_device="") in the script (~/.config/polybar/scripts/droidcpy.sh).
    • You can find the name here: adb devices -l
  • Add droidcpy to your Polybar config.ini:
    • New module section:
      [module/droidcpy]
      type   = custom/script
      exec   = ~/.config/polybar/scripts/droidcpy.sh
      tail   = false
      
    • Add it to one of your bars section, example:
      [bar/base]
      modules-left = droidcpy
      
    • Reload your Polybar.
  • If you use i3wm, add some rules for scrcpy, example:
    # assign the program to workspace 3, because I use "set $ws3 number 3"
    assign [class="scrcpy"] $ws3
    
    # force no borders and a floating window for scrpy
    for_window [class=".*"] border pixel 0
    for_window [class="scrcpy"] floating enable
    • Reload your i3wm.

Acknowledgements

About

droidcpy - A Polybar script to control your Android device remote control services. Mirror display with handling, Audio, Webcam. Using scrcpy, sndcpy and v4l2loopback with IP Webcam.

Topics

Resources

License

Stars

Watchers

Forks

Languages