Devices
LDPlayer ADB Connect and Port Setup for MAS
Enable ADB debugging in LDPlayer 9, find the ADB port, connect the instance to Macro Automation Studio, and replace the recorder with screen-aware macros.
- Windows
- Emulator
- Studio
- Python SDK
On this page
- Before you start
- 1. Install LDPlayer 9
- 2. Set a fixed resolution
- 3. Enable ADB debugging in LDPlayer 9
- 4. The LDPlayer ADB port and how MAS scans it
- 5. Connect LDPlayer over ADB in MAS
- Macros on LDPlayer
- Several LDPlayer instances
- Troubleshooting
- LDPlayer ADB device not found
- LDPlayer shows offline
- Find the LDPlayer 9 ADB port
- Macro not working
- Control it from Python
This guide shows how to connect LDPlayer 9 to Macro Automation Studio (MAS) over ADB, and how MAS macros differ from LDPlayer’s Operation Recorder. LDPlayer ships for Windows only, so every step below is a Windows step.
Before you start
- MAS installed and signed in on Windows 10 or 11. MAS is a free download for the trial; get it from the download page.
- LDPlayer 9 installed from ldplayer.net and started once.
- The instance fully booted to the Android home screen.
- The apps you want to automate installed and signed in inside LDPlayer.
1. Install LDPlayer 9
- Download LDPlayer 9 from the vendor site and run the installer.
- Start LDPlayer and wait for the home screen.
- Install and sign in to the apps you want to automate before you add the device to MAS.
2. Set a fixed resolution
MAS matches template images pixel for pixel, so pick a resolution once and keep it.
- Click the gear icon in the LDPlayer toolbar to open Settings.
- Open Display and choose the custom resolution option.
- Enter a width of 540, a height of 960 and a DPI of 240. This is the MAS baseline; a macro you write yourself expects whatever resolution you captured in Asset Lab.
- Click Save settings and restart the instance when LDPlayer asks.
3. Enable ADB debugging in LDPlayer 9
LDPlayer keeps ADB closed until you open it. The vendor documents the switch under Other settings:
- Open Settings.
- Click Other settings.
- Set ADB debugging to Open local connection.
- Click Save settings.
- Restart the instance. The setting takes effect after the restart.
4. The LDPlayer ADB port and how MAS scans it
The first LDPlayer instance listens on 5555. MAS does not use adb devices to discover emulators. It scans the running processes and keeps a port when all of these hold:
- The process name contains
ldvboxheadless,ld9boxheadless,dnplayer,ldplayerorvboxnetnat. - The port is odd and between 5555 and 5599: 5555, 5557, 5559 and so on.
- The socket listens on
127.0.0.1,0.0.0.0or all interfaces.
Matching ports appear in the Add New Device dialog labelled LD Player, for example 5555 - LD Player. MAS scans when you open a device group and each time you click Refresh. Further instances take the next odd ports, which is why the rule runs to 5599: it covers 23 running instances.
5. Connect LDPlayer over ADB in MAS
- Open Device Groups in the sidebar and open a group, or create one.
- Click Add Device.
- Type a Device Name of up to 50 characters.
- In Port, pick the
LD Playerentry for this instance. Click Refresh if the list is empty. - If LDPlayer uses a port that does not fit the rule above, choose Custom Port and type it. MAS accepts 1024 to 65535.
- Optionally choose a Startup Macro.
- Click Add Device, then click Start on the device card.
The card shows Connecting and then Running. MAS starts its own adb server, removes any stale entry for 127.0.0.1:<port>, and runs adb connect against it.
Macros on LDPlayer
LDPlayer’s Operation Recorder (a toolbar button, or Ctrl + 8) records taps, swipes and text input and replays them as a script. Its script settings offer an Execution loop (Till loops number, Till time or Till manual stop), a Loop Interval and Accelerating. What it cannot do is look at the screen. Every tap replays at the coordinates you recorded, so a loading delay, a pop-up or a button that moved sends the next tap into nothing, and the loop keeps going regardless. The script also runs only inside LDPlayer.
A MAS macro is a Python script that checks the screen before it acts. It finds a button with template matching, reads text with OCR, waits with retries, and branches on what it sees. The same script runs on LDPlayer, on other emulators and on a cloud device without edits, because MAS drives the device over adb.
- To rebuild a recorded routine as a screen-aware macro, follow Image recognition macros.
- To loop it until a condition is met, with a stop condition the recorder cannot express, or to run it on a schedule, read Loops, stop conditions and scheduling.
- Marketplace macros install as MAS macros and run on the device you assign.
Several LDPlayer instances
Instances created in LDMultiplayer (the Multi-player toolbar button, then New player or Clone player) each listen on their own port. Add each one as a separate device in the same device group, assign a macro and settings profile per device, and use Start All and Stop All on the group. Set the resolution per instance in the manager’s Settings so templates match on all of them. See Device groups for per-device arguments and proxies.
Troubleshooting
LDPlayer ADB device not found
The device card shows Error with “Failed to start device”, the log says “unable to connect to device”, or MAS lists no LD Player entry. Work through these causes:
- ADB debugging is not set to Open local connection, or the instance was not restarted after the change. Set it, save, and restart.
- The instance is still booting. Wait for the home screen, then click Refresh and Start again.
- The port belongs to a different instance. Fix it with Edit Device on the card.
- The scan reported “Failed to scan emulator ports”. Restart MAS and open the dialog again.
- adb printed “connection refused” or “cannot connect” in the device logs. Nothing listens on that port; run
adb connect 127.0.0.1:5555in a terminal to check.
LDPlayer shows offline
adb devices lists 127.0.0.1:<port> offline and commands hang. The adb daemon inside the instance has stopped answering, usually after sleep, an update or a second adb server on the machine. Click Stop on the card, restart the LDPlayer instance, close other tools that run their own adb server, and click Start. MAS disconnects the stale entry and reconnects on every start. If it stays offline, restart MAS so its adb server starts clean. More fixes are on ADB troubleshooting.
Find the LDPlayer 9 ADB port
The vendor’s ADB guide does not show a place in LDPlayer’s settings where the port is printed, so read it from MAS or from adb. In MAS, open Add New Device and click Refresh: every port it found is listed with LD Player next to it, lowest first, so the first instance is 5555 and the next ones follow at 5557 and 5559. In a terminal, adb connect 127.0.0.1:5555 answers “connected” for a live port and “cannot connect” for a dead one. Once you know the port, it stays the same as long as you start instances in the same order.
Macro not working
Two different problems share this phrase.
- A recorded LDPlayer script taps the wrong spot or loops without effect. The resolution changed since the recording, the app now loads slower, or a pop-up sits over the button. Recorded scripts cannot recover from any of these; rebuild the routine as a MAS macro with Image recognition macros.
- A MAS macro stalls or stops. Open Logs on the device card:
ImageNotFoundErrorandTimeoutErrorname the step that failed. Check that the instance runs at the resolution the templates were captured at, that the device card is at Running, and that no LDPlayer script is sending input at the same time.
Control it from Python
With the card at Running, a macro’s src/app.py drives the instance through the mas package. MAS chooses the port, so scripts never reference it.
import mas
size = mas.get_screen_size()
mas.log(f"LDPlayer screen is {size.width}x{size.height}")
match = mas.find_object_retry(1234, total_tries=3, time_sleep=2.0)
if match:
mas.click(match.x, match.y)Read the SDK overview for every namespace, and Control an Android emulator from Python for a complete first script.
Next steps
Related pages
Thanks. If something is wrong, tell us in Discord.
Questions? Ask in Discord