2024-08-03 16:31:08 +02:00
[![Coverage ](https://pvv.ntnu.no/~oysteikt/gitea/mpvipc-async/main/coverage/badges/for_the_badge.svg )](https://pvv.ntnu.no/~oysteikt/gitea/mpvipc-async/main/coverage/src/)
[![Docs ](https://img.shields.io/badge/docs-blue?style=for-the-badge&logo=rust )](https://pvv.ntnu.no/~oysteikt/gitea/mpvipc-async/main/docs/mpvipc_async/)
2024-04-30 17:39:33 +02:00
2024-08-03 16:27:11 +02:00
# mpvipc-async
2017-05-29 17:54:12 +02:00
2024-08-03 15:52:41 +02:00
> **NOTE:** This is a fork of [gitlab.com/mpv-ipc/mpvipc](https://gitlab.com/mpv-ipc/mpvipc), which introduces a lot of changes to be able to use the library asynchronously with [tokio](https://github.com/tokio-rs/tokio).
---
2017-05-29 17:54:12 +02:00
A small library which provides bindings to control existing mpv instances through sockets.
## Dependencies
2024-08-03 15:52:41 +02:00
- `mpv` (runtime dependency)
- `cargo-nextest` (optional test depencency)
- `grcov` (optional test depencency)
2017-05-29 17:54:12 +02:00
## Example
Make sure mpv is started with the following option:
2024-05-04 00:06:43 +02:00
```bash
2022-07-10 15:34:14 +02:00
$ mpv --input-ipc-server=/tmp/mpv.sock --idle
2024-05-04 00:06:43 +02:00
```
2017-05-29 17:54:12 +02:00
2024-05-04 00:06:43 +02:00
Here is a small code example which connects to the socket `/tmp/mpv.sock` and toggles playback.
2017-05-29 17:54:12 +02:00
2022-07-10 15:34:14 +02:00
```rust
2024-08-03 16:27:11 +02:00
use mpvipc_async::*;
2017-05-29 17:54:12 +02:00
2024-05-04 00:06:43 +02:00
#[tokio::main]
async fn main() -> Result< (), MpvError> {
let mpv = Mpv::connect("/tmp/mpv.sock").await?;
let paused: bool = mpv.get_property("pause").await?;
2024-08-03 15:52:41 +02:00
mpv.set_property("pause", !paused).await.expect("Error pausing");
2017-05-29 17:54:12 +02:00
}
2024-05-04 00:06:43 +02:00
```