Skip to content
Shiny PlatformShiny Platform
.NET MAUI on the WebRun your MAUI app in the browser on WebAssembly - real DOM elements, no Blazor. Try the web sample and the .NET MAUI GalleryGet started

AirPlay

Send audio to any AirPlay speaker, Apple TV, HomePod or Mac from iOS, Android, Mac Catalyst, macOS, Windows and Linux, stream everything a device is playing, and make your app an AirPlay speaker that iPhones and Macs can play to. Built on Shiny.Core and Shiny.Net.Discovery, so it runs in any Shiny host - MAUI, a console app or a headless Raspberry Pi.

GitHub GitHub stars for shinyorg/shiny
Downloads NuGet downloads for Shiny.AirPlay
Frameworks
.NET MAUI
.NET
Operating Systems
Android
iOS
Windows
Linux
macOS

This is an audio library. Screen mirroring and AirPlay video need Apple’s FairPlay keys, which Apple licenses only to hardware makers, so they are not available on any platform - not from this library and not from any other that ships in an app store. On iOS and macOS the user starts mirroring from Control Center. AirPlaySenderCapabilities.ScreenMirroring and AirPlayReceiverCapabilities.VideoReceiving exist only so the code says so; they are never set.

Two protocols, chosen per device. Most third-party speakers, AV receivers, AirPort Express and shairport-sync accept AirPlay 1 (RAOP) audio without pairing. Apple TV, HomePod and the macOS AirPlay Receiver want AirPlay 2 with HomeKit pairing - Connect pairs transiently on its own, and devices set to require a code need a one-time PIN pairing. IAirPlayAudioSession.Protocol tells you which one a session used.

The receiver is an AirPlay 1 speaker. iPhones, iPads, Macs and Apple TVs can play to it, but can’t group it into AirPlay 2 multi-room playback. iOS can’t receive at all.

iOS Mac Catalyst macOS Android Windows Linux
Discover & stream PCM ✅ ✅ ✅ ✅ ✅ ✅
Stream the device’s audio ❌ ❌ ✅ 13+ ✅ 10+ ✅ ✅
Pair with Apple TV / HomePod / Mac ✅ ✅ ✅ ✅ ✅ ✅
System AirPlay picker ✅ ✅ ✅ ❌ ❌ ❌
Receive audio ❌ ✅ ✅ ✅ ✅ ✅
Screen mirroring / video ❌ ❌ ❌ ❌ ❌ ❌

Read Capabilities off the instance before offering a feature - anything unavailable throws AirPlayNotSupportedException.

Terminal window
dotnet add package Shiny.AirPlay
builder.Services.AddAirPlaySender(); // discover + stream
builder.Services.AddAirPlayReceiver(); // act as a speaker

Each platform needs a few manifest / Info.plist entries - see Platform Setup.

await sender.RequestAccess(); // shows the local network prompt on iOS
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10));
await foreach (var change in sender.Discover(cts.Token))
{
var d = change.Device;
Console.WriteLine($"{change.Type}: {d.Name} ({d.Model}) audio={d.SupportsAudio} pairing={d.Pairing}");
}

Discover streams until you cancel it. Apple devices advertise twice (_raop._tcp and _airplay._tcp), so a device usually arrives as Appeared and then Updated once the second advertisement fills in its other port. SupportsAudio is false for devices that only accept FairPlay-authenticated audio.

Write takes signed 16-bit little-endian, 44.1 kHz, stereo, interleaved PCM (session.Format) and waits whenever its half-second buffer is full, so a loop of writes streams at exactly real-time speed.

await using var session = await sender.Connect(device, new AirPlayConnectOptions { Volume = 0.4 });
await session.SetMetadata(new AirPlayMetadata
{
Title = "Morning Mix",
Artist = "Shiny FM",
Artwork = coverJpeg,
ArtworkMimeType = "image/jpeg"
});
await session.CopyFrom(pcmStream); // or: await session.Write(buffer) in your own loop
await Task.Delay(session.Latency); // the device plays ~2 s behind - let it finish
  • Decode MP3/AAC and resample yourself first; the library carries PCM only.
  • When you stop writing, silence goes out so the device’s clock keeps running.
  • Pause() / Resume() stop and restart audio and drop what the device has buffered; call Flush() after a seek or skip.
  • SetVolume(0..1) and SetProgress(position, duration) drive the device’s own UI.
  • Open one session per speaker to play to several at once. They are not sample-synchronized with each other.
  • StateChanged reports Disconnected / Faulted when the device drops the session.

AirPlay 1 speakers send their remote and button presses back to the sender:

session.RemoteCommand += (_, command) =>
{
if (command == AirPlayRemoteCommand.Next)
player.Skip();
};

Send everything the device is playing - a browser tab, Spotify, a game - to a speaker:

if (sender.Capabilities.HasFlag(AirPlaySenderCapabilities.SystemAudioCapture))
{
await sender.RequestAccess(systemAudio: true);
await using var session = await sender.Connect(device);
await session.StartSystemAudio();
}
Platform Captured through Notes
Android 10+ MediaProjection + AudioPlaybackCapture Consent dialog on every start; apps that opt out of capture are silent
macOS 13+ ScreenCaptureKit Needs the Screen & System Audio Recording permission; relaunch after the first grant
Windows WASAPI loopback The default output device
Linux PulseAudio / PipeWire monitor Needs libpulse-simple.so.0

The audio still plays locally as well. Write throws while system audio is running.

Transient pairing (HomePod, most Apple TVs, the macOS receiver) happens inside Connect. An Apple TV set to require a code throws AirPlayPairingRequiredException the first time - pair once with the PIN it shows:

try
{
session = await sender.Connect(device);
}
catch (AirPlayPairingRequiredException)
{
await sender.Pair(device, async ct => await PromptForPinAsync(ct)); // null cancels
session = await sender.Connect(device);
}

AirPlayAccessDeniedException means the device’s own AirPlay access setting refuses you and no pairing will help. A Mac’s AirPlay Receiver defaults to Allow AirPlay for: Current User (devices on the same Apple ID only) - it has to be set to Anyone on the same network. Apple TVs and HomePods limited to Only People Sharing This Home behave the same way.

Credentials are kept by IAirPlayCredentialStore. The default store is a JSON file in the app’s data directory that holds this app’s Ed25519 pairing key - register your own implementation (keychain, keystore) before AddAirPlaySender() if that matters to you. Unpair forgets a device.

On iOS, Mac Catalyst and macOS you can also show the operating system’s own picker, which routes the app’s AVAudioSession / AVPlayer output. The OS never says which device was chosen.

if (sender.Capabilities.HasFlag(AirPlaySenderCapabilities.SystemRoutePicker))
await sender.ShowSystemRoutePicker();
var routedToAirPlay = sender.IsSystemRouteAirPlay;
var host = await receiver.Start(new AirPlayReceiverOptions("Kitchen")
{
Playback = AirPlayPlaybackMode.Automatic, // play on this device's speakers
Password = null,
WhenBusy = AirPlaySessionPolicy.Replace // a new sender takes over, as on Apple devices
});
host.SessionStarted += (_, session) =>
{
session.MetadataChanged += (_, m) => ShowNowPlaying(m.Title, m.Artist, m.Artwork);
session.VolumeChanged += (_, v) => volumeSlider.Value = v;
};
// later
await host.DisposeAsync();

With AirPlayPlaybackMode.Manual nothing is played - read the decoded audio yourself, delivered at the moment it should be heard:

await foreach (var frame in session.ReadAudio(ct))
mixer.Write(frame.Pcm.Span); // s16le, session.Format; the sender's volume is not applied

session.SendCommand(AirPlayRemoteCommand.PlayPause) controls the sender (when CanSendCommands is true). host.Name can differ from the requested name when the network already has one.