-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
MediaPicker.shared.cs
112 lines (98 loc) · 4.74 KB
/
MediaPicker.shared.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#nullable enable
using System.Threading.Tasks;
using Microsoft.Maui.Storage;
namespace Microsoft.Maui.Media
{
/// <summary>
/// The MediaPicker API lets a user pick or take a photo or video on the device.
/// </summary>
public interface IMediaPicker
{
/// <summary>
/// Gets a value indicating whether capturing media is supported on this device.
/// </summary>
bool IsCaptureSupported { get; }
/// <summary>
/// Opens the media browser to select a photo.
/// </summary>
/// <param name="options">Pick options to use.</param>
/// <returns>A <see cref="FileResult"/> object containing details of the picked photo. When the operation was cancelled by the user, this will return <see langword="null"/>.</returns>
Task<FileResult?> PickPhotoAsync(MediaPickerOptions? options = null);
/// <summary>
/// Opens the camera to take a photo.
/// </summary>
/// <param name="options">Pick options to use.</param>
/// <returns>A <see cref="FileResult"/> object containing details of the captured photo. When the operation was cancelled by the user, this will return <see langword="null"/>.</returns>
Task<FileResult?> CapturePhotoAsync(MediaPickerOptions? options = null);
/// <summary>
/// Opens the media browser to select a video.
/// </summary>
/// <param name="options">Pick options to use.</param>
/// <returns>A <see cref="FileResult"/> object containing details of the picked video. When the operation was cancelled by the user, this will return <see langword="null"/>.</returns>
Task<FileResult?> PickVideoAsync(MediaPickerOptions? options = null);
/// <summary>
/// Opens the camera to take a video.
/// </summary>
/// <param name="options">Pick options to use.</param>
/// <returns>A <see cref="FileResult"/> object containing details of the captured video. When the operation was cancelled by the user, this will return <see langword="null"/>.</returns>
Task<FileResult?> CaptureVideoAsync(MediaPickerOptions? options = null);
}
/// <summary>
/// The MediaPicker API lets a user pick or take a photo or video on the device.
/// </summary>
public static class MediaPicker
{
/// <summary>
/// Gets a value indicating whether capturing media is supported on this device.
/// </summary>
public static bool IsCaptureSupported =>
Default.IsCaptureSupported;
/// <summary>
/// Opens the media browser to select a photo.
/// </summary>
/// <param name="options">Pick options to use.</param>
/// <returns>A <see cref="FileResult"/> object containing details of the picked photo. When the operation was cancelled by the user, this will return <see langword="null"/>.</returns>
public static Task<FileResult?> PickPhotoAsync(MediaPickerOptions? options = null) =>
Default.PickPhotoAsync(options);
/// <summary>
/// Opens the camera to take a photo.
/// </summary>
/// <param name="options">Pick options to use.</param>
/// <returns>A <see cref="FileResult"/> object containing details of the captured photo. When the operation was cancelled by the user, this will return <see langword="null"/>.</returns>
public static Task<FileResult?> CapturePhotoAsync(MediaPickerOptions? options = null) =>
Default.CapturePhotoAsync(options);
/// <summary>
/// Opens the media browser to select a video.
/// </summary>
/// <param name="options">Pick options to use.</param>
/// <returns>A <see cref="FileResult"/> object containing details of the picked video. When the operation was cancelled by the user, this will return <see langword="null"/>.</returns>
public static Task<FileResult?> PickVideoAsync(MediaPickerOptions? options = null) =>
Default.PickVideoAsync(options);
/// <summary>
/// Opens the camera to take a video.
/// </summary>
/// <param name="options">Pick options to use.</param>
/// <returns>A <see cref="FileResult"/> object containing details of the captured video. When the operation was cancelled by the user, this will return <see langword="null"/>.</returns>
public static Task<FileResult?> CaptureVideoAsync(MediaPickerOptions? options = null) =>
Default.CaptureVideoAsync(options);
static IMediaPicker? defaultImplementation;
/// <summary>
/// Provides the default implementation for static usage of this API.
/// </summary>
public static IMediaPicker Default =>
defaultImplementation ??= new MediaPickerImplementation();
internal static void SetDefault(IMediaPicker? implementation) =>
defaultImplementation = implementation;
}
/// <summary>
/// Pick options for picking media from the device.
/// </summary>
public class MediaPickerOptions
{
/// <summary>
/// Gets or sets the title that is displayed when picking media.
/// </summary>
/// <remarks>This title is not guaranteed to be shown on all operating systems.</remarks>
public string? Title { get; set; }
}
}