maui-media-picker

Guide for selecting photos and videos in .NET MAUI, covering picking from gallery or camera, capture, multi-select in .NET 10, MediaPickerOptions, platform permissions, and handling FileResult. Suitable for pick photo, capture photo, take photo, pick video, camera capture, MediaPicker, multi-photo selection and photo library scenarios. Not for general file picking, image display/optimization, or camera streaming.

Last repository push
GitHub Stars
181
Forks
21
Issues / PRs
1

Installation

Review the source and dependencies with a prompt. A package is available to download.

Install with an AI assistant

Copy the prompt so your assistant can review the pinned revision and dependencies first.

View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "maui-media-picker" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-dbe09e82a1b94b3baef669aba5f9ebda483bfc3c86fc72fe08b221df6de7949b. Verify the upstream source and version against https://github.com/davidortinau/maui-skills before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.

Source and setup

github.com

Setup guidance pending

See the original source for supported tools, dependencies, and permissions.

Installation test pending

Guide for selecting photos and videos in .NET MAUI, covering picking from gallery or camera, capture, multi-select in .NET 10, MediaPickerOptions, platform permissions, and handling FileResult. Suitable for pick photo, capture photo, take photo, pick video, camera capture, MediaPicker, multi-photo selection and photo library scenarios. Not for general file picking, image display/optimization, or camera streaming.

0 Downloads

Introduction source: third_party · davidortinau · 0.0.1 Reference

SkillPi interpretation

Testing
Not tested

Browse files

Browse files at the source ↗

Original SKILL.md

Open original ↗
Frontmatter
name: maui-media-picker
description: >-
  Guidance for picking photos/videos, capturing from camera, multi-select (.NET 10),
  MediaPickerOptions, platform permissions, and FileResult handling in .NET MAUI.
  USE FOR: "pick photo", "capture photo", "take picture", "pick video", "camera capture",
  "MediaPicker", "photo gallery", "image picker", "multi-select photos", "MediaPickerOptions".
  DO NOT USE FOR: general file picking (use maui-file-handling),
  image display or optimization (use maui-performance), or camera streaming (use maui-platform-invoke).

.NET MAUI Media Picker — Gotchas & Best Practices

Common Mistakes

1. Forgetting to check for cancellation

Single-select returns null, multi-select returns an empty list. Not checking causes NullReferenceException.

// ❌ Crashes when user cancels
var photo = await MediaPicker.Default.PickPhotoAsync();
using var stream = await photo.OpenReadAsync();

// ✅ Always check for null / empty
var photo = await MediaPicker.Default.PickPhotoAsync();
if (photo is null) return;
using var stream = await photo.OpenReadAsync();

2. Calling from a background thread

All MediaPicker methods must run on the UI thread or they throw.

// ❌ Will throw on some platforms
await Task.Run(async () => await MediaPicker.Default.PickPhotoAsync());

// ✅ Call directly from a command or event handler on the UI thread
var photo = await MediaPicker.Default.PickPhotoAsync();

3. Not checking IsCaptureSupported

Devices without cameras (emulators, some tablets) will throw if you call capture methods.

// ❌ Crashes on devices without a camera
var photo = await MediaPicker.Default.CapturePhotoAsync();

// ✅ Guard with capability check
if (MediaPicker.Default.IsCaptureSupported)
{
    var photo = await MediaPicker.Default.CapturePhotoAsync();
}

4. Not disposing streams

OpenReadAsync() returns a stream that must be disposed.

// ❌ Leaks the stream
var stream = await photo.OpenReadAsync();
var bytes = ReadAllBytes(stream);

// ✅ Dispose with using
using var stream = await photo.OpenReadAsync();

Platform Pitfalls

⚠️ SelectionLimit is not enforced on Android/Windows

MediaPickerOptions.SelectionLimit is advisory. Always validate the count yourself:

var options = new MediaPickerOptions { SelectionLimit = 5 };
var results = await MediaPicker.Default.PickPhotosAsync(options);
if (results.Count() > 5)
{
    // Warn user or take only the first 5
    results = results.Take(5);
}

⚠️ Android storage permissions split at API 33

  • API ≤ 32: needs READ_EXTERNAL_STORAGE / WRITE_EXTERNAL_STORAGE
  • API ≥ 33: needs READ_MEDIA_IMAGES / READ_MEDIA_VIDEO (broad storage permissions are ignored)
  • Use android:maxSdkVersion="32" on the old permissions to avoid Play Store warnings

⚠️ iOS requires all four plist keys for full functionality

Missing any one of NSCameraUsageDescription, NSMicrophoneUsageDescription, NSPhotoLibraryUsageDescription, or NSPhotoLibraryAddUsageDescription causes a runtime crash when that feature is accessed.

⚠️ Android requires <queries> for camera intents

Without the IMAGE_CAPTURE query in AndroidManifest.xml, CapturePhotoAsync may fail silently on Android 11+ due to package visibility restrictions.

Decision Framework

Scenario Method
User picks one photo PickPhotoAsync()
User picks multiple (.NET 10+) PickPhotosAsync() with SelectionLimit
App needs camera capture Check IsCaptureSupported → CapturePhotoAsync()
Save picked file permanently Copy stream to FileSystem.AppDataDirectory
Need photo metadata Set PreserveMetaData = true in MediaPickerOptions

Checklist

  • [ ] All picker calls run on the UI thread
  • [ ] Null/empty checks after every pick/capture call
  • [ ] IsCaptureSupported guard before capture methods
  • [ ] Streams disposed with using
  • [ ] Android manifest has both old and new storage permissions with maxSdkVersion
  • [ ] Android manifest has <queries> block for camera intent
  • [ ] iOS Info.plist has all four usage description keys
  • [ ] SelectionLimit validated in code, not trusted from platform

Current listing version

0.0.1

Verify the source revision ↗

Quality assessment

Out of 100 · Assessment report from SkillPi LAB.

Scenario Value78/100

Highlights

  • 针对 .NET MAUI 开发者在照片/视频选择和相机捕获中的常见痛点提供实用指导
  • 覆盖多选、权限、平台差异等关键场景,对目标用户有显著效率提升
Trigger Precision92/100

Highlights

  • 触发词覆盖全面且边界清晰,明确区分适用与不适用场景,有效避免误触发
Structure and Standards95/100

Areas to improve

  • 缺少显式 When to Use 章节 Reported severity: Minor

    文档未设置独立的 When to Use 章节,尽管 frontmatter 中已有描述

    Recommendation: 建议在正文开头增加 When to Use 小节以增强可读性

Highlights

  • 结构清晰,分模块讲解常见错误、平台陷阱和决策框架
  • 包含代码示例、决策表和检查清单,便于开发者快速应用
Execution Reliability90/100

Highlights

  • 全面覆盖关键异常处理(null检查、UI线程限制、流释放)
  • 详细说明 Android 和 iOS 平台特定配置要求,降低运行时崩溃风险
Evidence Verifiability (mean of the first four)89/100

The arithmetic mean of the first four original scores, rounded to a whole number.

Static text checks

100 / 100 · skillpi-20261123-no-r3-v1

No current rules matched the text.

This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.

Permissions and checks before use

Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.

These common operations were not identified in the main document. This does not mean no permissions or risks exist.

These notices grant no permissions. Your host tool must still confirm file changes, secrets, external transfers or costs as needed.

Security rating and access scope

safe · Static evidence review; not a runtime safety guarantee.

Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.