dart_mpd 0.1.2 copy "dart_mpd: ^0.1.2" to clipboard
dart_mpd: ^0.1.2 copied to clipboard

a dart package which implements the MPD protocol. https://www.musicpd.org/

example/lib/example.dart

import 'package:dart_mpd/dart_mpd.dart';

Future<void> main() async {
  final client = MpdClient(
    connectionDetails: MpdConnectionDetails.resolve(),
  );

  // a request will automatically connect to the socket if not already connected
  final song = await client.currentsong();

  // responses are parsed into models
  print(song.artist);
  print(song.title);

  // you can also manually connect and close the socket
  await client.connection.connect();
  await client.connection.close();

  // you can hook into the connection lifecycle through callbacks on the client
  MpdClient(
    connectionDetails: MpdConnectionDetails.resolve(),
    onConnect: () => print('connected'),
    onDone: () => print('closed'),
  );

  // `MpdConnectionDetails.resolve` will resolve the connection details from
  // environment variables and fallback to the default values as described in
  // https://mpd.readthedocs.io/en/stable/client.html#connecting-to-mpd
  MpdConnectionDetails.resolve();

  // you can also manually specify the connection details
  MpdConnectionDetails(
    host: 'localhost',
    port: 6600,
    timeout: const Duration(seconds: 30),
  );

  // a request can throw the following errors:
  // - `SocketException` if the host-lookup or connection fails
  // - `MpdClientException` if an unexpected response is received
  // - `MpdResponseError` if the server returns an error response
  // - any other error that may be thrown when trying to parse the response
  //   (this indicates a bug in the library and should be reported)

  try {
    await client.setvol(200);
  } catch (e) {
    print(e);
  }
}
3
likes
0
pub points
77%
popularity

Publisher

unverified uploader

a dart package which implements the MPD protocol. https://www.musicpd.org/

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

file, freezed_annotation, json_annotation, platform

More

Packages that depend on dart_mpd