Skip to content
This repository was archived by the owner on May 15, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Samples/Samples.iOS/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>MinimumOSVersion</key>
<string>10.0</string>
<string>14.5</string>
<key>CFBundleDisplayName</key>
<string>Xamarin.Essentials</string>
<key>CFBundleIdentifier</key>
Expand Down
32 changes: 20 additions & 12 deletions Samples/Samples/View/MediaPickerPage.xaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
<views:BasePage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:views="clr-namespace:Samples.View"
xmlns:viewmodels="clr-namespace:Samples.ViewModel"
x:Class="Samples.View.MediaPickerPage"
Title="Media Picker">
<views:BasePage
x:Class="Samples.View.MediaPickerPage"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:viewmodels="clr-namespace:Samples.ViewModel"
xmlns:views="clr-namespace:Samples.View"
Title="Media Picker">
<views:BasePage.BindingContext>
<viewmodels:MediaPickerViewModel />
</views:BasePage.BindingContext>

<ScrollView>
<StackLayout Padding="10">
<Button Text="Pick photo" Command="{Binding PickPhotoCommand}" />
<Button Text="Capture photo" Command="{Binding CapturePhotoCommand}" />
<Button Text="Pick video" Command="{Binding PickVideoCommand}" />
<Button Text="Capture video" Command="{Binding CaptureVideoCommand}" />
<Button Command="{Binding PickPhotoCommand}" Text="Pick photo" />
<Button Command="{Binding PickPhotosCommand}" Text="Pick photos" />
<Button Command="{Binding CapturePhotoCommand}" Text="Capture photo" />
<Button Command="{Binding PickVideoCommand}" Text="Pick video" />
<Button Command="{Binding CaptureVideoCommand}" Text="Capture video" />

<Image VerticalOptions="FillAndExpand" Source="{Binding PhotoPath}" IsVisible="{Binding ShowPhoto}" />
<MediaElement VerticalOptions="FillAndExpand" Source="{Binding VideoPath}" IsVisible="{Binding ShowVideo}" />
<Image
IsVisible="{Binding ShowPhoto}"
Source="{Binding PhotoPath}"
VerticalOptions="FillAndExpand" />
<MediaElement
IsVisible="{Binding ShowVideo}"
Source="{Binding VideoPath}"
VerticalOptions="FillAndExpand" />
</StackLayout>
</ScrollView>

Expand Down
21 changes: 21 additions & 0 deletions Samples/Samples/ViewModel/MediaPickerViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Input;
using Xamarin.Essentials;
Expand All @@ -18,6 +19,7 @@ public class MediaPickerViewModel : BaseViewModel
public MediaPickerViewModel()
{
PickPhotoCommand = new Command(DoPickPhoto);
PickPhotosCommand = new Command(DoPickPhotos);
CapturePhotoCommand = new Command(DoCapturePhoto, () => MediaPicker.IsCaptureSupported);

PickVideoCommand = new Command(DoPickVideo);
Expand All @@ -26,6 +28,8 @@ public MediaPickerViewModel()

public ICommand PickPhotoCommand { get; }

public ICommand PickPhotosCommand { get; }

public ICommand CapturePhotoCommand { get; }

public ICommand PickVideoCommand { get; }
Expand Down Expand Up @@ -72,6 +76,23 @@ async void DoPickPhoto()
}
}

async void DoPickPhotos()
{
try
{
var photos = await MediaPicker.PickPhotosAsync();
var photo = photos.FirstOrDefault();

await LoadPhotoAsync(photo);

Console.WriteLine($"PickPhotosAsync COMPLETED: {PhotoPath}");
}
catch (Exception ex)
{
Console.WriteLine($"PickPhotosAsync THREW: {ex.Message}");
}
}

async void DoCapturePhoto()
{
try
Expand Down
180 changes: 90 additions & 90 deletions Xamarin.Essentials.sln

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions Xamarin.Essentials/MediaPicker/MediaPicker.android.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Android.Content;
using Android.Content.PM;
Expand All @@ -15,6 +16,9 @@ static bool PlatformIsCaptureSupported
static Task<FileResult> PlatformPickPhotoAsync(MediaPickerOptions options)
=> PlatformPickAsync(options, true);

static Task<IEnumerable<FileResult>> PlatformPickPhotosAsync(MediaPickerOptions options, MultiPickerOptions pickerOptions = null)
=> PlatformPicksAsync(options, pickerOptions);

static Task<FileResult> PlatformPickVideoAsync(MediaPickerOptions options)
=> PlatformPickAsync(options, false);

Expand Down Expand Up @@ -105,5 +109,8 @@ void OnCreate(Intent intent)
return null;
}
}

static async Task<IEnumerable<FileResult>> PlatformPicksAsync(MediaPickerOptions options, MultiPickerOptions pickerOptions)
=> await Task.FromResult(new List<FileResult>());
}
}
Loading