Skip to content

Commit 00b5258

Browse files
committed
MediaPicker (.NET 10): add multi-select docs with PickPhotosAsync/PickVideosAsync, examples, and platform notes; moniker split maintained
1 parent 77073a8 commit 00b5258

File tree

1 file changed

+74
-6
lines changed
  • docs/platform-integration/device-media

1 file changed

+74
-6
lines changed

docs/platform-integration/device-media/picker.md

Lines changed: 74 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,21 +99,89 @@ No setup is required.
9999

100100
## Using media picker
101101

102-
The <xref:Microsoft.Maui.Media.IMediaPicker> interface has the following methods that all return a <xref:Microsoft.Maui.Storage.FileResult>, which can be used to get the file's location or read it.
102+
::: moniker range="<=net-maui-9.0"
103103

104-
- <xref:Microsoft.Maui.Media.MediaPicker.PickPhotoAsync%2A>\
104+
The <xref:Microsoft.Maui.Media.IMediaPicker> interface has the following methods that return a <xref:Microsoft.Maui.Storage.FileResult>, which can be used to get the file's location or read it.
105+
106+
- <xref:Microsoft.Maui.Media.MediaPicker.PickPhotoAsync%2A> \
105107
Opens the media browser to select a photo.
106108

107-
- <xref:Microsoft.Maui.Media.MediaPicker.CapturePhotoAsync%2A>\
109+
- <xref:Microsoft.Maui.Media.MediaPicker.CapturePhotoAsync%2A> \
108110
Opens the camera to take a photo.
109111

110-
- <xref:Microsoft.Maui.Media.MediaPicker.PickVideoAsync%2A>\
112+
- <xref:Microsoft.Maui.Media.MediaPicker.PickVideoAsync%2A> \
111113
Opens the media browser to select a video.
112114

113-
- <xref:Microsoft.Maui.Media.MediaPicker.CaptureVideoAsync%2A>\
115+
- <xref:Microsoft.Maui.Media.MediaPicker.CaptureVideoAsync%2A> \
116+
Opens the camera to take a video.
117+
118+
Each method optionally takes a <xref:Microsoft.Maui.Media.MediaPickerOptions> parameter that allows the <xref:Microsoft.Maui.Media.MediaPickerOptions.Title> to be set on some operating systems, which is displayed to the user.
119+
120+
::: moniker-end
121+
122+
::: moniker range=">=net-maui-10.0"
123+
124+
In .NET 10, the media picker adds multi-select support and new processing options. Use the following methods:
125+
126+
- <xref:Microsoft.Maui.Media.MediaPicker.PickPhotosAsync%2A> (returns `List<FileResult>`) \
127+
Opens the media browser to select one or more photos.
128+
129+
- <xref:Microsoft.Maui.Media.MediaPicker.CapturePhotoAsync%2A> (returns `FileResult?`) \
130+
Opens the camera to take a photo.
131+
132+
- <xref:Microsoft.Maui.Media.MediaPicker.PickVideosAsync%2A> (returns `List<FileResult>`) \
133+
Opens the media browser to select one or more videos.
134+
135+
- <xref:Microsoft.Maui.Media.MediaPicker.CaptureVideoAsync%2A> (returns `FileResult?`) \
114136
Opens the camera to take a video.
115137

116-
Each method optionally takes in a <xref:Microsoft.Maui.Media.MediaPickerOptions> parameter type that allows the <xref:Microsoft.Maui.Media.MediaPickerOptions.Title> to be set on some operating systems, which is displayed to the user.
138+
The <xref:Microsoft.Maui.Media.MediaPickerOptions> parameter exposes additional fields such as <xref:Microsoft.Maui.Media.MediaPickerOptions.SelectionLimit>, <xref:Microsoft.Maui.Media.MediaPickerOptions.MaximumWidth>, <xref:Microsoft.Maui.Media.MediaPickerOptions.MaximumHeight>, <xref:Microsoft.Maui.Media.MediaPickerOptions.CompressionQuality>, <xref:Microsoft.Maui.Media.MediaPickerOptions.RotateImage>, and <xref:Microsoft.Maui.Media.MediaPickerOptions.PreserveMetaData>.
139+
140+
> [!IMPORTANT]
141+
> When the user cancels a multi-select operation, the returned list is empty. On Android, some picker UIs may not enforce <xref:Microsoft.Maui.Media.MediaPickerOptions.SelectionLimit>; on Windows, `SelectionLimit` isn't supported. Implement your own logic to enforce limits or notify the user on these platforms.
142+
143+
### Pick multiple photos
144+
145+
```csharp
146+
var results = await MediaPicker.PickPhotosAsync(new MediaPickerOptions
147+
{
148+
// Default is 1; set to 0 for no limit
149+
SelectionLimit = 10,
150+
// Optional processing for images
151+
MaximumWidth = 1024,
152+
MaximumHeight = 768,
153+
CompressionQuality = 85,
154+
RotateImage = true,
155+
PreserveMetaData = true,
156+
});
157+
158+
foreach (var file in results)
159+
{
160+
using var stream = await file.OpenReadAsync();
161+
// Process the stream
162+
}
163+
```
164+
165+
### Pick multiple videos
166+
167+
```csharp
168+
var results = await MediaPicker.PickVideosAsync(new MediaPickerOptions
169+
{
170+
SelectionLimit = 3,
171+
Title = "Select up to 3 videos",
172+
});
173+
174+
foreach (var file in results)
175+
{
176+
using var stream = await file.OpenReadAsync();
177+
// Process the stream
178+
}
179+
```
180+
181+
> [!TIP]
182+
> For single selection, prefer `PickPhotosAsync`/`PickVideosAsync` as well. Set `SelectionLimit = 1` (the default) and read the first item if present.
183+
184+
::: moniker-end
117185

118186
> [!IMPORTANT]
119187
> All methods must be called on the UI thread because permission checks and requests are automatically handled by .NET MAUI.

0 commit comments

Comments
 (0)