MpcNET 1.4.0

.NET Standard 2.0
NuGet\Install-Package MpcNET -Version 1.4.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
dotnet add package MpcNET --version 1.4.0
<PackageReference Include="MpcNET" Version="1.4.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MpcNET --version 1.4.0
#r "nuget: MpcNET, 1.4.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install MpcNET as a Cake Addin
#addin nuget:?package=MpcNET&version=1.4.0

// Install MpcNET as a Cake Tool
#tool nuget:?package=MpcNET&version=1.4.0

<img src="icon.png" width="128">

MpcNET

Pure .NET Client Library for Music Player Daemon Servers.
The heart and soul of Stylophone.

Nightly Packages - Stable Versions

Usage

Connection

To create a client for MPD, you must first create a IPEndPoint for the Server with the right IP and Port.

var mpdEndpoint = new IPEndPoint(IPAddress.Loopback, 6600);

Then create a Client and Connect to MPD.

var client = new MpcConnection(mpdEndpoint);
var connected = await client.ConnectAsync();

The ConnectAsync() method is returning a bool to indicate if the connection was successfully. However, this can be queried directly on the Client also:

var isConnected = client.IsConnected;

and for MPD version, additional property is available:

var mpdVersion = client.Version

To disconnect the Client use the follow method:

await client.DisconnectAsync();

or just dispose the client:

client.Dispose();

Send Command

using (var client = new MpcConnection(mpdEndpoint)) {
    await client.ConnectAsync();

    // Look in /Commands to see everything that implements IMpcCommand
    var request = await client.SendAsync(new IMpcCommand<List<string>>(parameters));

    if (!request.IsResponseValid) {
        var mpdError = request.Response?.Result?.MpdError;
        if (mpdError != null && mpdError != "")
            Console.WriteLine($"Error: {mpdError}");
        else
            Console.WriteLine($"Invalid server response: {response}.");

    } else {
        List<string> response = request.Response.Content;
        // do stuff
    }
}

Command Lists

var commandList = new CommandList();

commandList.Add(new IMpcCommand<?>(firstCommandArgument);
commandList.Add(new IMpcCommand<?>(secondCommandArgument);
commandList.Add(new IMpcCommand<?>(thirdCommandArgument);

using (var client = new MpcConnection(mpdEndpoint)) {
    await client.ConnectAsync();
    var request = await client.SendAsync(commandList);

    // Response string contains responses of all the commands, split by commas
    string response = request.Response?.Content;
}

Binary Responses

// Get albumart from MPD
List<byte> data = new List<byte>();

using (var client = new MpcConnection(mpdEndpoint))
{
    long totalBinarySize = 9999;
    long currentSize = 0;

    do
    {
        var albumReq = await client.SendAsync(new AlbumArtCommand(f.Path, currentSize));
        if (!albumReq.IsResponseValid) break;

        var response = albumReq.Response.Content;
        if (response.Binary == 0) break; // MPD isn't giving us any more data, let's roll with what we have.

        totalBinarySize = response.Size;
        currentSize += response.Binary;
        data.AddRange(response.Data);

        Debug.WriteLine($"Downloading albumart: {currentSize}/{totalBinarySize}");
    } while (currentSize < totalBinarySize);
}

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.4.0 294 4/5/2022
1.3.0 199 1/21/2022
1.2.0 372 10/9/2021
1.1.0 314 10/3/2021
1.0.0 308 10/3/2021