Permissions
Music library access requires runtime permissions on both platforms. The IMediaLibrary interface provides methods to check and request these permissions.
Checking Permission Status
Section titled “Checking Permission Status”var status = await _library.CheckPermissionAsync();// Returns the current status without prompting the userRequesting Permission
Section titled “Requesting Permission”var status = await _library.RequestPermissionAsync();
switch (status){ case PermissionStatus.Granted: // Access allowed — you can now query and play tracks break; case PermissionStatus.Denied: // User denied access — consider showing a rationale break; case PermissionStatus.Restricted: // iOS only — access restricted by system policy (e.g., parental controls) break; case PermissionStatus.Unknown: // Status could not be determined break;}Android Configuration
Section titled “Android Configuration”AndroidManifest.xml
Section titled “AndroidManifest.xml”Add these permissions to your Platforms/Android/AndroidManifest.xml:
<!-- 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" />How It Works
Section titled “How It Works”- API 33+: The library requests the granular
READ_MEDIA_AUDIOpermission, which grants access only to audio files. - API < 33: Falls back to
READ_EXTERNAL_STORAGE, which grants broader file access. - Runtime permission is requested via the MAUI Permissions API.
iOS Configuration
Section titled “iOS Configuration”Info.plist
Section titled “Info.plist”Add this key to your Platforms/iOS/Info.plist:
<key>NSAppleMusicUsageDescription</key><string>This app needs access to your music library to browse and play your music.</string>How It Works
Section titled “How It Works”- Permission is requested via
MPMediaLibrary.RequestAuthorizationfrom theMediaPlayerframework. - iOS may return
Restrictedif access is blocked by device management or parental controls — this is distinct from the user denying access.
Entitlements
Section titled “Entitlements”No special entitlements are required. The MediaPlayer and AVFoundation frameworks are standard iOS frameworks included with the platform.
Best Practices
Section titled “Best Practices”- Always check before querying — Call
RequestPermissionAsync()orCheckPermissionAsync()before callingGetAllTracksAsync()orSearchTracksAsync(). - Handle denial gracefully — If the user denies permission, show UI explaining why the permission is needed and how to grant it in Settings.
- Don’t call repeatedly — On iOS, after the user has responded to the permission prompt once, subsequent calls to
RequestPermissionAsync()will return the cached result without re-prompting. The user must go to Settings to change the permission.