dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.02k stars 1.73k forks source link

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

Open cdavidyoung opened 1 year ago

cdavidyoung commented 1 year ago

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.

jfversluis commented 1 year ago

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?

ghost commented 1 year ago

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.

cdavidyoung commented 1 year ago

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: @.***>

jfversluis commented 1 year ago

@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.

cdavidyoung commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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);
         }
moljac commented 7 months ago

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.

Saccomani commented 1 month ago

there's any workaround?

danbrannanavontus commented 1 month ago

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.

erviss commented 2 weeks ago

We are forced to migrate from Xamarin to Maui since there is no longer support for new Android and iOS versions, I would have expected at least equal functionality to Xamarin instead Maui is years of development far away! Xamarin support should be ended at least in 2030 given how Maui is evolving