maui icon indicating copy to clipboard operation
maui copied to clipboard

MediaPicker.Default.CapturePhotoAsync missing important option like SaveToAlbum, PhotoSize, CompressionQuality

Open cdavidyoung opened this issue 2 years ago • 9 comments

Description

I am re-engineering my Xamarin app for Maui. I know the latter is still under development so I would like to request these features. In the meanwhile if there is a workaround for the SaveToAlbum option I would appreciate a pointer. Thanks.

Public API Changes

MediaPicker.Default.CapturePhotoAsync(new StoreCameraMediaOptions() { DefaultCamera = Plugin.Media.Abstractions.CameraDevice.Rear, SaveToAlbum = true, PhotoSize = PhotoSize.Medium, CompressionQuality = 92, });

Intended Use-Case

The user can take a photo from within my app at which point I also record an audio snippet that corresponds with the moment the photo is taken. In addition to the app DB, it is important that the photo be stored in the user gallery so that they can easily access the photo later.

cdavidyoung avatar Nov 14 '22 21:11 cdavidyoung

I will be putting out a proposal for this soon! However, this won't be implemented until .NET 8.

In the meanwhile have a look at https://github.com/dimonovdd/Xamarin.MediaGallery which should have all this and supports .NET MAUI.

As for the implementation of this, are you missing anything that you wish the Xamarin MediaPicker had? Or things that should work differently? Anything of which you think: if there was a newer version I wish this would be better?

jfversluis avatar Nov 15 '22 09:11 jfversluis

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

ghost avatar Nov 15 '22 09:11 ghost

Thanks for the quick response, Gerald! The description of this package does not look encouraging. It indicates that it does not support Maui in particular. Should I just ignore that and forge ahead with it?

This Xamarin MediaPicker had the features I needed. About the only thing that I can think of is access to the photo editor so that it would be possible to easily rotate and crop a photo that was just taken (without going to the gallery).

This plugin is designed for picking and saving photos and video files from the native gallery of Android and iOS devices and capture photo.

Unfortunately, at the time of the release of this plugin, MediaPlugin https://github.com/jamesmontemagno/MediaPlugin by @jamesmontemagno https://github.com/jamesmontemagno is no longer supported, and Xamarin.Essentials https://github.com/xamarin/Essentials has not received updates for about 2 months. This plugin has fixed bugs and added some features that are missing in Xamarin.Essentials https://github.com/xamarin/Essentials. I hope that in the future it will be ported to MAUI https://github.com/dotnet/maui so that developers have an easy way to add these features to their apps.

On Tue, Nov 15, 2022 at 2:54 AM msftbot[bot] @.***> wrote:

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process https://github.com/dotnet/maui/blob/main/docs/TriageProcess.md.

— Reply to this email directly, view it on GitHub https://github.com/dotnet/maui/issues/11353#issuecomment-1315062433, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHE7K5CWJYRRQETL4ID2TDWINMTZANCNFSM6AAAAAASAIQT6U . You are receiving this because you authored the thread.Message ID: @.***>

cdavidyoung avatar Nov 15 '22 12:11 cdavidyoung

@cdavidyoung I think you're reading the description wrong. The author of MediaGallery is stating that other plugins don't seem to be maintained and lacking .NET MAUI support. This is the reason that he created MediaGallery.

MediaGallery, as far as I know, has everything that is in our MediaPicker and more.

jfversluis avatar Nov 16 '22 11:11 jfversluis

Thanks for the advice, Gerald! Now that you pointed it out, the description is ambiguous and it could very well be as you say. I'll give it a try!

Charles

On Wed, Nov 16, 2022 at 4:27 AM Gerald Versluis @.***> wrote:

@cdavidyoung https://github.com/cdavidyoung I think you're reading the description wrong. The author of MediaGallery is stating that other plugins don't seem to be maintained and lacking .NET MAUI support. This is the reason that he created MediaGallery.

MediaGallery, as far as I know, has everything that is in our MediaPicker and more.

— Reply to this email directly, view it on GitHub https://github.com/dotnet/maui/issues/11353#issuecomment-1316843959, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHE7K77XMPCXX5A3QI24BTWITAKJANCNFSM6AAAAAASAIQT6U . You are receiving this because you were mentioned.Message ID: @.***>

cdavidyoung avatar Nov 16 '22 12:11 cdavidyoung

After adding the NativeMedia.Platform.Init it gives me a MSBUILD : java.exe error JAVA0000. I wonder if it has to do with net7.0 that I am using.

using Android.App; using Android.Content.PM; using Android.OS;

namespace jiffyLog;

[Activity(Theme = @.***/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)] public class MainActivity : MauiAppCompatActivity { protected override void OnCreate(Bundle savedInstanceState) { //... base.OnCreate(savedInstanceState); NativeMedia.Platform.Init(this, savedInstanceState); //... } }

1>jiffyLog -> C:\Users\charl\source\repos\GitHub\jiffyLog\bin\Debug\net7.0-android\ZipidyDo.dll 1>MSBUILD : java.exe error JAVA0000: Error in C:\Users\charl.nuget\packages\xamarin.google.guava.listenablefuture\1.0.0.9\buildTransitive\net6.0-android31.0....\jar\guava-listenablefuture.jar:com/google/common/util/concurrent/ListenableFuture.class: 1>MSBUILD : java.exe error JAVA0000: Type com.google.common.util.concurrent.ListenableFuture is defined multiple times: C:\Users\charl.nuget\packages\xamarin.google.guava.listenablefuture\1.0.0.9\buildTransitive\net6.0-android31.0....\jar\guava-listenablefuture.jar:com/google/common/util/concurrent/ListenableFuture.class, obj\Debug\net7.0-android\lp\184\jl\libs\E0614835FEE16B6F.jar:com/google/common/util/concurrent/ListenableFuture.class 1>MSBUILD : java.exe error JAVA0000: Compilation failed

On Wed, Nov 16, 2022 at 5:09 AM Charles David Young < @.***> wrote:

Thanks for the advice, Gerald! Now that you pointed it out, the description is ambiguous and it could very well be as you say. I'll give it a try!

Charles

On Wed, Nov 16, 2022 at 4:27 AM Gerald Versluis @.***> wrote:

@cdavidyoung https://github.com/cdavidyoung I think you're reading the description wrong. The author of MediaGallery is stating that other plugins don't seem to be maintained and lacking .NET MAUI support. This is the reason that he created MediaGallery.

MediaGallery, as far as I know, has everything that is in our MediaPicker and more.

— Reply to this email directly, view it on GitHub https://github.com/dotnet/maui/issues/11353#issuecomment-1316843959, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHE7K77XMPCXX5A3QI24BTWITAKJANCNFSM6AAAAAASAIQT6U . You are receiving this because you were mentioned.Message ID: @.***>

cdavidyoung avatar Nov 18 '22 12:11 cdavidyoung

I can't get past the Android Required Setup. I get the following error. One problem is that there is no AndroidResource now in Maui and I have tried the other types or Resource but can't get by this.

Error APT2260 resource xml/file_paths (aka com.CatchAll:xml/file_paths) not found.

This error is likely caused by an issue with the AndroidManifest.xml file or an Android manifest generation attribute in a source code file. jiffyLog C:\Users\charl\source\repos\GitHub\jiffyLog\Platforms\Android\AndroidManifest.xml 1

cdavidyoung avatar Dec 05 '22 21:12 cdavidyoung

Any advice on getting past this error? The copy to album is literally the last feature I need to publish my Maui app on 4 platforms, although this feature is really only needed on Android and iPhone. I have considered delving into the Xamarin code to port this feature from there to Maui. Any advice on the feasibility of this?

cdavidyoung avatar Dec 21 '22 21:12 cdavidyoung

Well, with Gerald's encouragement I finally got https://github.com/dimonovdd/Xamarin.MediaGallery to work for my app. I started by cloning the repo and building the sample app, which works. It demonstrates that it is possible to copy files to the gallery.

Knowing that, I followed the README.md file closely. After installing the Xamarin.MediaGallery nuget and doing the things required in README.md for Android (iOS does not need any special initialization because I was already taking photos in my app) you basically add at the beginning of the file where you want to use this:

using NativeMedia;

Then make sure this is only used for iOS and Android. Note that I am using standard Maui code for taking the photos. I am only using this to copy the photo to the gallery. I may look into MediaGallery to take the photo as well if it allows a compression option.

         // MediaGallery only works for these platforms.
         if (   (DeviceInfo.Current.Platform == DevicePlatform.iOS)
             || (DeviceInfo.Current.Platform == DevicePlatform.Android))
         {
            MediaFileType type = MediaFileType.Image;
            await MediaGallery.SaveAsync(MediaFileType.Image, newFile);
         }

cdavidyoung avatar Dec 22 '22 13:12 cdavidyoung

C:\Users\charl.nuget\packages\xamarin.google.guava.listenablefuture\1.0.0.9\buildTransitive\net6.0-android31.0....\jar\guava-listenablefuture.jar:com/google/common/util/concurrent/ListenableFuture.class: 1>MSBUILD : java.exe error JAVA0000: Type com.google.common.util.concurrent.ListenableFuture is defined multiple times: C:\Users\charl.nuget\packages\xamarin.google.guava.listenablefuture\1.0.0.9\buildTransitive\net6.0-android31.0....\jar\guava-listenablefuture.jar:com/google/common/util/concurrent/ListenableFuture.class, obj\Debug\net7.0-android\lp\184\jl\libs\E0614835FEE16B6F.jar:com/google/common/util/concurrent/ListenableFuture.class 1>MSBUILD : java.exe error JAVA0000: Compilation failed

You are using old version of nuget

Explicitly add latest version of Xamarin.Google.Guava.ListenableFuture

<PackageReference Include="Xamarin.Google.Guava.ListenableFuture" Version="1.0.0.17" />

That should help.

And please report here if that helps. if not I will need list of PackageReferences.

moljac avatar Feb 16 '24 09:02 moljac

there's any workaround?

Saccomani avatar Aug 02 '24 12:08 Saccomani

What's the score with this? The comments above said this was going to be implemented in .Net 8 however we're running .Net 8 and it's still not possible to set these properties. Just yet another bug in Maui which there seems to be no urgency to fix.

danbrannanavontus avatar Aug 08 '24 08:08 danbrannanavontus