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

Source: https://automationmacro.com/docs/ldplayer-setup-guide (Devices, updated 2026-09-04)

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](/download).
- LDPlayer 9 installed from [ldplayer.net](https://www.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

1. Download LDPlayer 9 from the vendor site and run the installer.
2. Start LDPlayer and wait for the home screen.
3. 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.

1. Click the gear icon in the LDPlayer toolbar to open **Settings**.
2. Open **Display** and choose the custom resolution option.
3. 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.
4. Click **Save settings** and restart the instance when LDPlayer asks.

> [!WARNING]
> Changing the resolution after you capture templates moves every match, and a macro built for another resolution clicks in the wrong place.

## 3. Enable ADB debugging in LDPlayer 9

LDPlayer keeps ADB closed until you open it. The vendor documents the switch under Other settings:

1. Open **Settings**.
2. Click **Other settings**.
3. Set **ADB debugging** to **Open local connection**.
4. Click **Save settings**.
5. Restart the instance. The setting takes effect after the restart.

> [!NOTE]
> **Open local connection** is enough for MAS, which always connects from the same computer. Root permission is a separate option on the same page, and MAS does not need it.

## 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`, `ldplayer` or `vboxnetnat`.
- 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.0` or 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

1. Open **Device Groups** in the sidebar and open a group, or create one.
2. Click **Add Device**.
3. Type a **Device Name** of up to 50 characters.
4. In **Port**, pick the `LD Player` entry for this instance. Click **Refresh** if the list is empty.
5. If LDPlayer uses a port that does not fit the rule above, choose **Custom Port** and type it. MAS accepts 1024 to 65535.
6. Optionally choose a **Startup Macro**.
7. 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 <kbd>Ctrl</kbd> + <kbd>8</kbd>) 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](/docs/guides/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](/docs/guides/loops-and-scheduling).
- Marketplace macros install as MAS macros and run on the device you assign.

> [!NOTE]
> Stop any Operation Recorder script before you start a device in MAS. Both send input to the same screen and interfere with each other.

## 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](/docs/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:5555` in 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](/docs/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](/docs/guides/image-recognition-macros).
- A MAS macro stalls or stops. Open **Logs** on the device card: `ImageNotFoundError` and `TimeoutError` name 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.

```python
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](/docs/sdk) for every namespace, and [Control an Android emulator from Python](/docs/guides/control-an-emulator-from-python) for a complete first script.
