forked from rom1v/sndcpy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sndcpy.bat
executable file
·61 lines (49 loc) · 2.1 KB
/
sndcpy.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
@echo off
if not defined ADB set ADB=adb
if not defined VLC set VLC="C:\Program Files\VideoLAN\VLC\vlc.exe"
if not defined SNDCPY_APK set SNDCPY_APK=sndcpy.apk
if not defined SNDCPY_PORT set SNDCPY_PORT=28200
:start
if not "%1"=="" (
set serial=-s %1
echo Waiting for device %1...
) else (
echo Waiting for device...
)
%ADB% %serial% wait-for-device || goto :error
:checkIfAppIsInstalled
%ADB% shell pm list packages | findstr /C:"com.rom1v.sndcpy" > temp.txt
FindStr /C:"com.rom1v.sndcpy" temp.txt >Nul && (goto :startForwarding) || goto :installApp
:end
:installApp
%ADB% %serial% install -t -r -g %SNDCPY_APK% || (
echo Uninstalling existing version first...
%ADB% %serial% uninstall com.rom1v.sndcpy || goto :error
%ADB% %serial% install -t -g %SNDCPY_APK% || goto :error
)
:end
:startForwarding
set balloonText="Device connected. Forwarding Audio."
set balloonTitle=sndcp
set balloonIcon=Information
powershell -Command "[void] [System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms'); $objNotifyIcon=New-Object System.Windows.Forms.NotifyIcon; $objNotifyIcon.BalloonTipText='%balloonText%'; $objNotifyIcon.Icon=[system.drawing.systemicons]::%balloonIcon%; $objNotifyIcon.BalloonTipTitle='%balloonTitle%'; $objNotifyIcon.BalloonTipIcon='None'; $objNotifyIcon.Visible=$True; $objNotifyIcon.ShowBalloonTip(5000);"
%ADB% %serial% forward tcp:%SNDCPY_PORT% localabstract:sndcpy || goto :error
%ADB% %serial% shell am start com.rom1v.sndcpy/.MainActivity || goto :error
:end
:: This method doesn't count that the screen could be skipped
:checkAllowed
::Recommended delay time for the popup to appear
timeout 5
%ADB% shell dumpsys gfxinfo com.rom1v.sndcpy > temp.txt
FindStr /C:"com.rom1v.sndcpy/com.rom1v.sndcpy.MainActivity/android.view.ViewRootImpl" temp.txt >Nul && (goto :checkAllowed) || goto :playAudio
:end
:playAudio
echo Playing audio...
%VLC% -Idummy --demux rawaud --network-caching=50 --play-and-exit tcp://localhost:%SNDCPY_PORT%
echo Device disconnected. Restarting service.
goto :start
:end
:error
echo Failed with error #%errorlevel%.
pause
exit /b %errorlevel%