/shiny:shiny-musicfrom shiny
Generate code using Shiny.Music, a unified API for accessing the device music library on Android, iOS, and Mac Catalyst with permissions, metadata querying, filtering, playback, lyrics, album art, audio output route detection (speaker/wired/USB/Bluetooth/car/HDMI/AirPlay), and file copy
Ships in shiny. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
You are an expert in Shiny.Music, a .NET library that provides a unified API for accessing the device music library on Android, iOS, and Mac Catalyst. It supports permission management, querying track metadata, playing music files, fetching lyrics, retrieving album artwork, and copying tracks (where platform restrictions allow).
Invoke this skill when the user wants to:
MusicFilterHasStreamingSubscriptionAsync()IMediaLibrary playlist CRUD methodsMicrosoft.Extensions.AI tools (search, browse-by-mood, playback control, playlist management) via Shiny.Music.Extensions.AIShiny.MusicShiny.Musicnet10.0-android, net10.0-ios26.2, net10.0-maccatalyst26.2using Shiny.Music;
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.UseShiny(); // REQUIRED (v4+): Android permission checks run on Shiny.Core's AndroidPlatform
builder.Services.AddShinyMusic();
return builder.Build();
}
}
<!-- Android 13+ (API 33+) -->
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
<!-- Android 12 and below (API < 33) -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="32" />
READ_MEDIA_AUDIO permission (audio files only).READ_EXTERNAL_STORAGE.<key>NSAppleMusicUsageDescription</key>
<string>This app needs access to your music library to browse and play your music.</string>
This key is mandatory. The app will crash on launch without it.
Provides access to the device music library including permissions, querying, and file operations.
Task<PermissionStatus> RequestPermissionAsync();
Prompts the user for music library access. On Android, requests READ_MEDIA_AUDIO (API 33+) or READ_EXTERNAL_STORAGE (older) via Shiny.Core's AndroidPlatform.RequestAccess — this requires Shiny hosting (.UseShiny()), which is why AddShinyMusic() must be paired with UseShiny() on Android (v4+). On Apple platforms, calls MPMediaLibrary.RequestAuthorization.
Returns: PermissionStatus — Granted, Denied, Restricted (Apple platforms only), or Unknown.
Task<PermissionStatus> CheckPermissionAsync();
Checks the current permission status without prompting the user.
Task<IReadOnlyList<MusicMetadata>> GetAllTracksAsync();
Returns all music tracks on the device. Permission must be granted first. On Android, queries MediaStore.Audio.Media with IsMusic != 0. On Apple platforms, uses MPMediaQuery.SongsQuery. Only music is returned — no videos, ringtones, podcasts, or audiobooks.
Task<IReadOnlyList<MusicMetadata>> SearchTracksAsync(string query);
Searches tracks by title, artist, or album. Case-insensitive partial string matching.
Task<IReadOnlyList<GroupedCount<string>>> GetGenresAsync(MusicFilter? filter = null);
Returns all distinct, non-null genre names from the user's music library with track counts, sorted alphabetically. When a MusicFilter is provided, only tracks matching the filter criteria are considered for grouping. Permission must be granted first.
Task<IReadOnlyList<GroupedCount<int>>> GetYearsAsync(MusicFilter? filter = null);
Returns all distinct, non-zero release years from the user's music library with track counts, sorted in ascending order. When a MusicFilter is provided, only tracks matching the filter criteria are considered. On Android, uses MediaStore.Audio.Media.YEAR; on Apple platforms, derives year from MPMediaItem.ReleaseDate.
Task<IReadOnlyList<GroupedCount<int>>> GetDecadesAsync(MusicFilter? filter = null);
Returns all distinct decades with track counts, sorted in ascending order. Each decade is its starting year (e.g., 1990 for the 1990s). When a MusicFilter is provided, only tracks matching the filter criteria are considered.
Task<IReadOnlyList<MusicMetadata>> GetTracksAsync(MusicFilter filter);
Returns tracks matching the specified filter criteria. All non-null filter properties are combined with AND logic. On Android, genre filtering queries via MediaStore.Audio.Genres.Members; year/decade/search use SQL WHERE clauses. On Apple platforms, uses MPMediaQuery.SongsQuery with client-side LINQ filtering.
Task<MusicMetadata?> GetTrackByIdAsync(string trackId);
Returns a single track by its platform-specific identifier (MusicMetadata.Id), or null if no track with that identifier exists. On Android, queries MediaStore.Audio.Media with an Id = ? selection. On Apple platforms, looks up the MPMediaItem with the matching persistent ID. Useful for restoring a previously-saved "now playing" track without loading the whole library.
Task<IReadOnlyList<MusicMetadata>> GetTracksByIdsAsync(IEnumerable<string> trackIds);
Returns multiple tracks by identifier in a single query. Results are ordered to match the supplied trackIds; duplicate identifiers are collapsed and identifiers that do not resolve to a track are omitted. On Android, issues one Id IN (...) query; on Apple platforms, makes a single pass over MPMediaQuery.SongsQuery. Prefer this over calling GetTrackByIdAsync in a loop when hydrating a saved list of track IDs (e.g., a queue or favorites list).
Task<IReadOnlyList<PlaylistInfo>> GetPlaylistsAsync();
Returns all playlists with their song counts, sorted alphabetically by name. On Android, merges MediaStore playlists with locally-stored custom playlists. On Apple platforms, reads system playlists from MPMediaQuery.PlaylistsQuery and merges with locally-stored custom playlists. Permission must be granted first.
Task<PlaylistInfo?> GetPlaylistByIdAsync(string playlistId);
Returns a single playlist (with its song count) by identifier, or null if not found. Resolves both device playlists and locally-stored custom playlists (custom: prefixed IDs). On Android, reads device playlists from MediaStore.Audio.Playlists; on Apple platforms from MPMediaQuery.PlaylistsQuery. Use this to re-resolve a saved playlist's current name and count without enumerating every playlist via GetPlaylistsAsync.
Task<IReadOnlyList<MusicMetadata>> GetPlaylistTracksAsync(string playlistId);
Returns all tracks in the specified playlist, in playlist order. The playlistId is the platform-specific identifier returned by GetPlaylistsAsync. On Android, queries MediaStore.Audio.Playlists.Members for platform playlists or the local JSON store for custom playlists. On Apple platforms, retrieves tracks from MPMediaPlaylist for system playlists or from the local JSON store for custom playlists.
Task<string?> GetAlbumArtPathAsync(string trackId);
Returns a file path to the album artwork image for the specified track. On Android, returns the content URI for the album art from MediaStore. On Apple platforms, exports the MPMediaItem.Artwork image to a cached JPEG file and returns its path. Returns null if no artwork is available.
Task<AudioLevels?> AnalyzeLevelsAsync(string trackId, TimeSpan? window = null);
Decodes a track to PCM offline — without playing it — and measures its amplitude. Use it to draw a waveform / VU meter, or to locate parts of a song (an intro, a chorus, a solo). Returns null for DRM-protected / streaming-only tracks that cannot be decoded to PCM (the same tracks CopyTrackAsync refuses) — always null-check the result.
MediaExtractor + MediaCodec; Apple: AVAssetExportSession → AVAssetReader), which lets analysis run even while the same track is playing (the live asset is otherwise held by the OS music player). Both down-mix to a single mono envelope at a fixed rate, so results are comparable across platforms.window is the analysis resolution (duration per RMS/peak entry); defaults to 500 ms.AudioLevels contains:
Rms / Peak — IReadOnlyList<float>, per-window levels normalized 0.0–1.0 against the track's loudest sample (entry i covers [i*Window, (i+1)*Window)).Sections — IReadOnlyList<AudioSection>: contiguous same-energy runs, each with Start, Duration, End, AudioEnergy (Silent/Quiet/Moderate/Loud), and AverageLevel. This is the coarse "song structure".var levels = await library.AnalyzeLevelsAsync(track.Id);
if (levels is not null)
{
// the last loud stretch is often an outro solo
var solo = levels.Sections.Where(s => s.Energy == AudioEnergy.Loud).MaxBy(s => s.Start);
if (solo is not null)
{
await player.PlayAsync(track);
player.Seek(solo.Start);
}
}
Task<bool> CopyTrackAsync(MusicMetadata track, string destinationPath);
Copies a music file to the specified path. Creates parent directories if needed. Returns false for DRM-protected tracks or on failure.
AVAssetExportSession in M4A format. DRM-protected Apple Music subscription tracks cannot be copied (AssetURL is null).Task<PlaylistInfo> CreatePlaylistAsync(string name);
Creates a new locally-stored custom playlist with the given name. On both platforms, playlists are persisted as JSON in local app data.
Task RemovePlaylistAsync(string playlistId);
Removes a custom playlist by its identifier.
Task AddTrackToPlaylistAsync(string playlistId, MusicMetadata track);
Adds a track to an existing custom playlist. No-op if the track already exists in the playlist.
Task RemoveTrackFromPlaylistAsync(string playlistId, string trackId);
Removes a track from an existing custom playlist.
Task<bool> HasStreamingSubscriptionAsync();
Checks whether the user has an active music streaming subscription that allows catalog playback. On Apple platforms, this queries MusicKit MusicSubscription.GetCurrentAsync. On Android, this always returns false.
Task<IReadOnlyList<MusicMetadata>> SearchCatalogAsync(string term, int limit = 25);
Searches the Apple Music streaming catalog (via MusicKit MusicCatalogSearchRequest) — unlike SearchTracksAsync, which searches only the user's local library, this returns catalog tracks that need not be in the library. Each result carries a MusicMetadata.CatalogId and is playable through IMusicPlayer.PlayAsync when the user has an active subscription. Catalog tracks are streaming-only: ContentUri is empty and they cannot be copied.
PlatformNotSupportedException on Android.limit is capped at 25 by Apple Music; defaults to 25.if (await library.HasStreamingSubscriptionAsync())
{
var results = await library.SearchCatalogAsync("daft punk", limit: 10);
if (results.Count > 0)
await player.PlayAsync(results[0]); // streams by CatalogId
}
Controls playback of music files from the device library. Implements IDisposable.
Android.Media.MediaPlayer with content URIs from MediaStore.MPMusicPlayerController.ApplicationMusicPlayer. For local tracks, looks up the MPMediaItem by persistent ID via MPMediaQuery and sets the queue. For streaming catalog tracks (those with a CatalogId from SearchCatalogAsync), enqueues by catalog id via MPMusicPlayerStoreQueueDescriptor — no library membership required, but an active subscription is.Task PlayAsync(MusicMetadata track);
Stops any current track, loads the specified one, and begins playback. For local tracks, throws InvalidOperationException if the track is not found in the music library. Catalog tracks (with a CatalogId) are streamed by catalog id and do not require library membership (an active subscription is required).
Android.Media.MediaPlayer with content URIs. Internally increments the play count in the local JSON store.MPMusicPlayerController — looks up the MPMediaItem by persistent ID, sets the queue, and starts playback.void Pause(); // No effect if not Playing
void Resume(); // No effect if not Paused
void Stop(); // Stops and releases the current track
void Seek(TimeSpan position);
Seeks to the specified position. Android uses millisecond precision; Apple platforms use second precision.
IVuMeter CreateVuMeter(AudioLevels? implied = null, TimeSpan? interval = null);
Creates an event-based VU meter for the current playback. Call Start(), subscribe to LevelChanged, and Dispose() when done.
android.media.audiofx.Visualizer when the app holds RECORD_AUDIO (IsLive == true). Add <uses-permission android:name="android.permission.RECORD_AUDIO" /> and request it at runtime; without it, it falls back to the implied meter.IsLive == false) — levels are synthesized from implied (the AnalyzeLevelsAsync result) at the current playback position, since MPMusicPlayerController exposes no output tap. Pass the analysis or the meter emits silence.LevelChanged may fire on a background thread — marshal to the UI before drawing. Each VuLevel has Position, Rms, Peak (0..1), and Energy.
var levels = await _library.AnalyzeLevelsAsync(track.Id);
var meter = _player.CreateVuMeter(levels);
meter.LevelChanged += (_, level) =>
MainThread.BeginInvokeOnMainThread(() => DrawVu(level.Rms, level.Peak));
meter.Start();
For a specific position without a running meter, use audioLevels.SampleAt(position) → VuLevel.
| Property | Type | Description |
|---|---|---|
State | PlaybackState | Current state: Stopped, Playing, or Paused |
CurrentTrack | MusicMetadata? | Currently loaded track, or null if stopped |
Position | TimeSpan | Current playback position (TimeSpan.Zero if no track) |
Duration | TimeSpan | Total duration of current track (TimeSpan.Zero if no track) |
IsDucked | bool | Whether a duck scope is currently active |
Volume | float | Device media volume, 0.0–1.0. Getter works on all platforms. Setter works on Android only; on Apple platforms it throws NotSupportedException (no supported OS API to set system volume) |
IsVolumeControlSupported | bool | Whether setting Volume is supported: true on Android, false on Apple. Always check this before assigning Volume |
| Event | Description |
|---|---|
StateChanged | Raised on state transitions (e.g., Playing -> Paused) |
PlaybackCompleted | Raised when a track finishes naturally (not via Stop()) |
VolumeChanged | EventHandler<float> — raised when the device media volume changes (hardware buttons, Control Center, or a successful Volume set); argument is the new volume 0.0–1.0 |
IAsyncDisposable Duck(DuckOptions? options = null);
Temporarily lowers the currently playing music so an announcement (e.g. text-to-speech) can be heard over top. Returns an IAsyncDisposable scope — full volume is restored when the scope is disposed. Wrap the announcement in an await using block:
await using (player.Duck(new DuckOptions { Level = 0.2 }))
{
await TextToSpeech.Default.SpeakAsync("Turn left in 200 meters");
}
// music ramps back to full volume here
Duck() call returns a no-op scope — the existing duck is not superseded and keeps running until its own scope is disposed. This avoids overlapping restore/fades fighting over the volume. Dispose the active scope to restore full volume.player.IsDucked to know whether a duck is active.DuckOptions.Level, FadeIn, and FadeOut exactly.AVAudioSession with DuckOthers. Level and the fade durations are advisory only — the OS controls duck depth and ramp. Announcement audio played through the app's audio session (an AVAudioPlayer, or AVSpeechSynthesizer with UsesApplicationAudioSession = true) plays at full volume over the ducked music; only other out-of-process audio is ducked.public record DuckOptions
{
public double Level { get; init; } = 0.2; // target volume 0.0–1.0 while ducked
public TimeSpan FadeIn { get; init; } = TimeSpan.FromMilliseconds(200); // ramp-down when ducking starts
public TimeSpan FadeOut { get; init; } = TimeSpan.FromMilliseconds(200); // ramp-up when the scope is disposed
}
| Property | Type | Default | Description |
|---|---|---|---|
Level | double | 0.2 | Target volume (0.0–1.0) while ducked. Android: applied exactly. Apple: ignored (OS-controlled) |
FadeIn | TimeSpan | 200ms | Ramp-down duration when ducking starts. Android: honored. Apple: ignored |
FadeOut | TimeSpan | 200ms | Ramp-up duration when the duck scope is disposed. Android: honored. Apple: ignored |
float Volume { get; set; } // device media volume, 0.0–1.0
bool IsVolumeControlSupported { get; }
event EventHandler<float>? VolumeChanged;
Volume is the device-wide system media volume (0.0–1.0), independent of any active duck. Reading works on all platforms; setting is platform-limited — always guard with IsVolumeControlSupported:
// Read anywhere
var level = player.Volume;
// Set only where supported (Android). On Apple the setter throws NotSupportedException.
if (player.IsVolumeControlSupported)
player.Volume = 0.5f;
// Observe changes (hardware buttons, Control Center, or a successful set)
player.VolumeChanged += (_, v) => Console.WriteLine($"Volume is now {v:P0}");
Volume reads/writes the system STREAM_MUSIC level via AudioManager (settable). This is separate from ducking, which attenuates only this player's own output. IsVolumeControlSupported is true. The stream is integer-stepped, so a set value is quantized to the nearest step and reading it back may differ slightly. Setting silently (no system volume UI) still raises VolumeChanged.Volume reads AVAudioSession.OutputVolume (reliable). The setter throws NotSupportedException — iOS/Mac Catalyst expose no supported API to change the system volume (MPMusicPlayerController.Volume was deprecated in iOS 7 and is a no-op). IsVolumeControlSupported is false. Let the user adjust volume via the hardware buttons or an MPVolumeView. VolumeChanged fires from KVO on the audio session's output volume.Reports the audio output route music is playing through, and raises an event when it changes. Registered by AddShinyMusic() as a singleton — resolve it from DI like any other service.
public interface IAudioOutputDevices
{
AudioOutputDevice? Current { get; }
IReadOnlyList<AudioOutputDevice> GetOutputs();
event EventHandler<AudioOutputDevice?>? Changed;
}
public record AudioOutputDevice(string Id, string Name, AudioOutputType Type, bool IsCurrent);
public enum AudioOutputType
{
Unknown, BuiltInSpeaker, BuiltInReceiver, WiredHeadphones, WiredHeadset,
Bluetooth, BluetoothA2dp, Usb, CarAudio, Hdmi, AirPlay
}
Output only and read-only. There is no input/microphone enumeration (this is a music library) and no way to set the route — that is the user's job via the OS route picker / Control Center. No permission is required.
AudioOutputExtensions)Prefer these over switching on AudioOutputType. Each has an overload for both AudioOutputDevice and AudioOutputType:
| Method | True for | Use it for |
|---|---|---|
IsWired() | WiredHeadphones, WiredHeadset, Usb | "is something plugged in" — USB counts because on handsets with no 3.5mm jack the wired option is USB-C |
IsBluetooth() | Bluetooth (HFP/SCO/LE), BluetoothA2dp | Bluetooth badge/icon; music normally routes over A2DP |
IsBuiltIn() | BuiltInSpeaker, BuiltInReceiver | nothing is plugged in or paired |
IsHeadphones() | wired or Bluetooth headphones/headsets | "audio is private to the user" |
IsExternalSystem() | CarAudio, Hdmi, AirPlay | playback has left the device |
var outputs = serviceProvider.GetRequiredService<IAudioOutputDevices>();
var current = outputs.Current; // null when the platform reports no route
if (current != null && current.IsBluetooth())
Console.WriteLine($"Playing on {current.Name}");
// Pause when the user unplugs and audio falls back to the loudspeaker
outputs.Changed += (_, device) =>
{
if (device?.IsBuiltIn() == true)
MainThread.BeginInvokeOnMainThread(player.Pause);
};
Threading: Changed is raised on whatever thread the OS delivers the route notification on. Always marshal to the UI thread (MainThread.BeginInvokeOnMainThread) before touching UI state.
GetOutputs() returns all connected outputs. AudioDeviceInfo has no "active" flag, so Current is derived — the connected outputs are ranked by the platform's own media routing priority (Bluetooth → wired → USB → car/HDMI → built-in speaker, earpiece last) and the winner wins. Good for media playback, but do not present it as a platform guarantee.Current comes from AVAudioSession.CurrentRoute. The OS exposes only the active route's ports, so GetOutputs() returns that route (usually one entry) — never write code that treats it as a picker/discovery list of reachable AirPlay or Bluetooth destinations. A mic-equipped wired headset shows as WiredHeadphones (Apple reports the headset mic only on the input side), so use IsWired() / IsHeadphones() rather than testing for WiredHeadset.Provides lyrics for music tracks.
Task<LyricsResult?> GetLyricsAsync(MusicMetadata track);
Returns lyrics for the specified track, or null if no lyrics are available. The result may contain plain text lyrics, synchronized lyrics in LRC format, or both.
public record LyricsResult(string? PlainLyrics, string? SyncedLyrics);
| Property | Type | Description |
|---|---|---|
PlainLyrics | string? | Plain text (unsynchronized) lyrics, or null if unavailable |
SyncedLyrics | string? | Synchronized lyrics in LRC format with timestamps, or null if unavailable |
Synced lyrics use the standard LRC format with timestamps:
[00:12.00]First line of lyrics
[00:17.50]Second line of lyrics
[00:23.10]Third line of lyrics
Each line is prefixed with [mm:ss.xx] indicating when the line should be displayed during playback.
LyricsExtensions)LyricsExtensions (namespace Shiny.Music) turns synced lyrics into the instrumental (no-vocal) sections of a track — intro, breaks, solos, outro — with no audio decode, so it works even for DRM tracks where AnalyzeLevelsAsync returns null.
IReadOnlyList<InstrumentalGap> GetInstrumentalGaps(
this LyricsResult? lyrics,
TimeSpan? trackDuration = null, // enables the trailing (outro) gap
TimeSpan? minimumGap = null); // default 8s — excludes ordinary pauses between lines
IReadOnlyList<LrcLine> ParseSyncedLyrics(this LyricsResult? lyrics); // (Timestamp, Text) lines
InstrumentalGap has Start, Duration, and End. Requires SyncedLyrics (returns empty for plain-only lyrics). Combine with AnalyzeLevelsAsync: the lyric gaps give precise boundaries, the audio Sections tell you which gap is the loud solo versus the quiet intro.
// "Start playing the guitar solo"
var lyrics = await _lyricsProvider.GetLyricsAsync(track);
var gaps = lyrics.GetInstrumentalGaps(track.Duration);
var solo = gaps.MaxBy(g => g.Duration); // the longest instrumental stretch
if (solo is not null)
{
await _player.PlayAsync(track);
_player.Seek(solo.Start);
}
public record MusicMetadata(
string Id,
string? Title,
string? Artist,
string? Album,
string? Genre,
TimeSpan Duration,
string? AlbumArtUri,
bool? IsExplicit,
string ContentUri,
string? StoreId = null,
int? Year = null,
int PlayCount = 0,
string? CatalogId = null
);
| Property | Description |
|---|---|
Id | Platform-specific unique ID. Android: MediaStore row ID. Apple platforms: MPMediaItem persistent ID. |
Title | Track title, or null if not available. |
Artist | Artist or performer, or null if not available. |
Album | Album name, or null if not available. |
Genre | Genre, or null if unavailable. |
Duration | Playback duration. |
AlbumArtUri | Album art URI. Android: MediaStore content URI. Apple platforms: null (use GetAlbumArtPathAsync for cached artwork). |
IsExplicit | Whether the track is marked as explicit content. Apple platforms only via MPMediaItem.IsExplicitItem; always null on Android. |
ContentUri | URI for playback/copy. Android: content:// URI. Apple platforms: ipod-library:// asset URL from MPMediaItem.AssetURL (empty string for DRM-protected tracks). |
StoreId | Track persistent ID used for MPMusicPlayerController playback. Apple platforms only; null on Android. |
Year | Release year of the track, or null if not available. Android: MediaStore.Audio.Media.YEAR; Apple platforms: derived from MPMediaItem.ReleaseDate. |
PlayCount | Number of times the track has been played. Apple platforms: from MPMediaItem.PlayCount. Android: from locally stored JSON play counts (incremented automatically by the player). |
CatalogId | Apple Music catalog identifier, set on tracks returned by SearchCatalogAsync. When present, the track is a streaming catalog item: PlayAsync enqueues it by this id via MPMusicPlayerStoreQueueDescriptor (subscription required) and ContentUri is empty (not copyable). null for local tracks and always null on Android. |
public record PlaylistInfo(string Id, string Name, int SongCount);
| Property | Description |
|---|---|
Id | Platform-specific unique identifier. Android: MediaStore playlist row ID or custom: prefixed ID for custom playlists. Apple platforms: MPMediaPlaylist persistent ID or custom: prefixed ID for custom playlists. |
Name | The display name of the playlist. |
SongCount | The number of tracks in the playlist. |
Defines optional criteria for filtering music tracks. All specified properties are combined with AND logic. Used with GetTracksAsync, GetGenresAsync, GetYearsAsync, and GetDecadesAsync.
public class MusicFilter
{
public string? Genre { get; init; }
public int? Year { get; init; }
public int? Decade { get; init; }
public string? SearchQuery { get; init; }
}
| Property | Description |
|---|---|
Genre | Filter by genre name (case-insensitive match). |
Year | Filter by exact release year. Takes precedence over Decade if both are set. |
Decade | Filter by decade start year (e.g., 1990 for the 1990s). Ignored if Year is also set. |
SearchQuery | Text search across title, artist, and album (case-insensitive, contains match). |
Returned by GetGenresAsync, GetYearsAsync, and GetDecadesAsync.
public record GroupedCount<T>(T Value, int Count);
| Property | Description |
|---|---|
Value | The grouped value (string for genres, int for years/decades). |
Count | The number of tracks that belong to this group. |
| Value | Description |
|---|---|
Unknown | User has not been prompted yet |
Denied | User denied access |
Granted | User granted access |
Restricted | Apple platforms only — blocked by system policy (parental controls, MDM) |
| Value | Description |
|---|---|
Stopped | No track playing; player is idle |
Playing | A track is actively playing |
Paused | Playback is paused and can be resumed |
On Apple platforms, ContentUri is populated from MPMediaItem.AssetURL which provides an ipod-library:// URL for locally-synced tracks. DRM-protected Apple Music subscription tracks have no AssetURL — their ContentUri will be empty. However, all tracks can still be played via MPMusicPlayerController using the StoreId (persistent ID).
| Track Source | ContentUri | Playable | Copyable |
|---|---|---|---|
| Apple platforms — local/purchased tracks | ipod-library:// URL | yes | yes |
| Apple platforms — DRM subscription tracks | empty | yes (via MPMusicPlayerController) | no |
| Android local files | content:// URI | yes | yes |
Use HasStreamingSubscriptionAsync() to determine if the user has an active Apple Music subscription (on Apple platforms):
var canStream = await _library.HasStreamingSubscriptionAsync();
if (canStream)
{
// User has an active Apple Music subscription
}
On Android, this always returns false.
RequestPermissionAsync() before any query or playback operation.UseShiny() on Android (v4+) — Android permission checks run on Shiny.Core's AndroidPlatform, so the app must be under Shiny hosting (.UseShiny() in MAUI, or ShinyAndroidApplication + ShinyAndroidActivity natively). Without it, IMediaLibrary cannot resolve AndroidPlatform. Apple platforms have no such requirement.IMediaLibrary and IMusicPlayer should be singletons in DI.IMusicPlayer implements IDisposable; call Dispose() or let the DI container handle it.Restricted on Apple platforms — distinct from Denied; means system policy blocks access.AVAssetExportSession outputs M4A.HasStreamingSubscriptionAsync() — check before presenting streaming playback UI to the user.MusicFilter for combined queries — filter tracks by genre + year/decade in a single call rather than filtering in memory.GetGenresAsync(new MusicFilter { Decade = 1990 }) to find genres represented in the 90s.GetPlaylistsAsync and GetPlaylistTracksAsync — browse playlists and retrieve their contents in playlist order.GetTrackByIdAsync / GetPlaylistByIdAsync rather than scanning GetAllTracksAsync/GetPlaylistsAsync. For a list of track IDs, use GetTracksByIdsAsync (single query) instead of a loop of GetTrackByIdAsync. All three return null/omit entries for IDs that no longer resolve — always null-check.GetAlbumArtPathAsync — retrieve album artwork as a cached file path for display in the UI.ILyricsProvider.GetLyricsAsync — fetch lyrics for a track. Check SyncedLyrics for timed LRC format, fall back to PlainLyrics for plain text.IMediaLibrary — use CreatePlaylistAsync, RemovePlaylistAsync, AddTrackToPlaylistAsync, RemoveTrackFromPlaylistAsync. On both platforms these manage locally-stored custom playlists.PlayCount comes from MPMediaItem.PlayCount (system-tracked). On Android, play counts are incremented internally when PlayAsync is called and stored locally.// Create a playlist
var playlist = await _library.CreatePlaylistAsync("My Favorites");
// Add a track to the playlist
await _library.AddTrackToPlaylistAsync(playlist.Id, track);
// Browse all playlists
var playlists = await _library.GetPlaylistsAsync();
foreach (var p in playlists)
Console.WriteLine($"{p.Name} ({p.SongCount} songs)");
// Get tracks in a playlist
var tracks = await _library.GetPlaylistTracksAsync(playlist.Id);
// Remove a track from a playlist
await _library.RemoveTrackFromPlaylistAsync(playlist.Id, track.Id);
// Remove a playlist
await _library.RemovePlaylistAsync(playlist.Id);
// Fetch lyrics for a track
var lyrics = await _lyricsProvider.GetLyricsAsync(track);
if (lyrics != null)
{
if (!string.IsNullOrEmpty(lyrics.SyncedLyrics))
{
// Parse LRC format for synced display
// Format: [mm:ss.xx]Line of lyrics
foreach (var line in lyrics.SyncedLyrics.Split('\n'))
Console.WriteLine(line);
}
else if (!string.IsNullOrEmpty(lyrics.PlainLyrics))
{
// Display plain text lyrics
Console.WriteLine(lyrics.PlainLyrics);
}
}
// Get album artwork path
var artPath = await _library.GetAlbumArtPathAsync(track.Id);
if (artPath != null)
{
// Use as image source in MAUI
var imageSource = ImageSource.FromFile(artPath);
}
// All Rock tracks
var rockTracks = await library.GetTracksAsync(new MusicFilter { Genre = "Rock" });
// All tracks from the 1990s
var nineties = await library.GetTracksAsync(new MusicFilter { Decade = 1990 });
// Rock tracks from 1995
var rock95 = await library.GetTracksAsync(new MusicFilter { Genre = "Rock", Year = 1995 });
// Genres in the 2000s (with counts)
var genres2000s = await library.GetGenresAsync(new MusicFilter { Decade = 2000 });
// Years for Jazz (with counts)
var jazzYears = await library.GetYearsAsync(new MusicFilter { Genre = "Jazz" });
// Decades for Pop (with counts)
var popDecades = await library.GetDecadesAsync(new MusicFilter { Genre = "Pop" });
// Combined: genres matching "rock" search in the 1980s
var rock80s = await library.GetGenresAsync(new MusicFilter { Decade = 1980, SearchQuery = "rock" });
// Browse all playlists
var playlists = await library.GetPlaylistsAsync();
foreach (var p in playlists)
Console.WriteLine($"{p.Name} ({p.SongCount} songs)");
// Get tracks in a playlist
var playlistTracks = await library.GetPlaylistTracksAsync(playlists[0].Id);
The separate Shiny.Music.Extensions.AI NuGet package exposes the music library and player as
Microsoft.Extensions.AI AIFunction tools, so an LLM chat
agent can search/browse the library, pick a track for a mood, control playback, and manage playlists.
It is AOT-compatible (hand-authored JSON schemas, no reflection) and depends only on
Microsoft.Extensions.AI.Abstractions.
Shiny.Music.Extensions.AI (in addition to Shiny.Music)Shiny.Music.Extensions.AIAddMusicAITools(...) (DI) and the resolvable MusicAITools bundle (.Tools)Each Add… opts a group of tools in; anything not added is invisible to the LLM. AddMusicAITools
requires AddShinyMusic() first (it resolves IMediaLibrary/IMusicPlayer/ILyricsProvider).
using Shiny.Music.Extensions.AI;
builder.Services.AddShinyMusic();
builder.Services.AddMusicAITools(tools => tools
.AddLibrary() // search_tracks, browse_tracks, list_music_categories,
// list_playlists, get_playlist_tracks, get_lyrics
.AddPlayback() // play_track, control_playback, get_now_playing
.AddPlaylistManagement() // create_playlist, modify_playlist, delete_playlist
);
// or: builder.Services.AddMusicAITools(tools => tools.AddAll()); // the three areas above
// AddCatalog() (search_catalog) is Apple-only and NOT in AddAll(). Guard the opt-in
// with a compiler flag so the tool is only offered where it works:
builder.Services.AddMusicAITools(tools =>
{
tools.AddLibrary().AddPlayback().AddPlaylistManagement();
#if IOS || MACCATALYST
tools.AddCatalog(); // search_catalog — Apple Music streaming catalog
#endif
});
var tools = sp.GetRequiredService<MusicAITools>().Tools;
var response = await chatClient.GetResponseAsync(
messages,
new ChatOptions { Tools = [.. tools] }
);
| Tool | Area | Arguments | Purpose |
|---|---|---|---|
search_tracks | Library | query (required), limit | Free-text search over title/artist/album |
browse_tracks | Library | genre, year, decade, query, limit | Filter the library — the "pick a song for the mood" path |
list_music_categories | Library | kind (genres|years|decades, required), genre | Distinct categories with track counts |
list_playlists | Library | — | All playlists with ids and song counts |
get_playlist_tracks | Library | playlist_id (required), limit | Tracks in a playlist |
analyze_song_structure | Library | track_id (required) | Instrumental gaps (from synced lyrics, DRM-safe) + audio-energy sections (offline scan, null for DRM) in seconds — to start playback at a solo/chorus. No audio is played |
get_lyrics | Library | track_id (required) | Plain and/or synced lyrics (needs ILyricsProvider) |
search_catalog | Catalog (Apple-only) | query (required), limit | Search the Apple Music streaming catalog (not just the local library); returns ids usable with play_track |
play_track | Playback | track_id (required), start_seconds | Load and play a track by id (local or catalog); optionally start partway in (e.g. at a solo from analyze_song_structure) |
control_playback | Playback | action (pause|resume|stop|seek, required), position_seconds | Transport control |
get_now_playing | Playback | — | Current state, track, position, duration |
create_playlist | Playlist mgmt | name (required) | Create a custom playlist |
modify_playlist | Playlist mgmt | action (add_track|remove_track), playlist_id, track_id (all required) | Add/remove a track |
delete_playlist | Playlist mgmt | playlist_id (required) | Delete a custom playlist |
{ "error": "..." } rather than throwing.search_tracks/browse_tracks/get_playlist_tracks/search_catalog return
ids that play_track, get_lyrics, and modify_playlist consume. Catalog results carry a catalogId
and aren't in the local library — play_track remembers them from the search so it can stream them by id.AddCatalog() (the search_catalog tool) is Apple-only and is not included in AddAll(). Guard the
opt-in with #if IOS || MACCATALYST so it isn't offered on Android (where the underlying call throws).IMediaLibrary.RequestPermissionAsync() from the app first.AddPlayback() throws at registration if no IMusicPlayer is available (i.e. AddShinyMusic() was not
called on a platform target).What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub shinyorg/skills --plugin shiny57 skills in this plugin
/localizegenGenerate strongly-typed localization classes from .resx resource files using Shiny.Extensions.Localization.Generator for .NET applications/shiny-accessorysetupGenerate code using Shiny.BluetoothLE.AccessorySetup - the system accessory pairing sheet for BLE devices (AccessorySetupKit on iOS 18+, CompanionDeviceManager on Android) with no MFi, no location prompt and no general Bluetooth prompt on iOS; picked accessories open as Shiny.BluetoothLE peripherals, and Android adds background presence (device appeared / disappeared) events/shiny-actorsGenerate code using Shiny.Actors — Orleans-style virtual actors without the ceremony, AOT/trim-clean, running anywhere .NET runs including .NET MAUI and Blazor WebAssembly. Covers actor interfaces and source-generated proxies, the ShinyActorBuilder (AddShinyActors), persistent state with ETags, named states and auto-save, event-sourced JournaledActor with snapshots, state and event migrations, typed streams (durable, implicit consumers), timers and persistent reminders (background jobs via Shiny.Jobs, on-time OS notifications via Shiny.Notifications), concurrency control ([Reentrant], [AlwaysInterleave], [ReadOnly], [StatelessWorker]), call filters and request context, OpenTelemetry traces and metrics, remoting over HTTP (Shiny.Net.HttpServer server, RemoteActorSystem client), mDNS discovery of actor servers, Shiny.DocumentDb storage (SQLite, PostgreSQL, IndexedDB...), and the ActorTestHost testing kit.Other plugins' skills for the same job