question

WeiWen-3421 avatar image
0 Votes"
WeiWen-3421 asked LeonLu-MSFT commented

How to access native camera that give the users the options to either take photo or video?

In Xamarin.Essentials.MediaPicker, it can do both photo and video. But I have to explicitly call CapturePhotoAsync() or CaptureVideoAsync() to achieve either. But in my app, I need the functionality of the native camera that once the user clicks the camera, he can see the options both Photo and Video, as well as other functionalities. If I use MediaPicker.CapturePhotoAsync() or MediaPicker.CaptureVideoAsync(), it does not give the users the options of choosing the other one. Is it possible to achieve what I want in Xamarin.forms?

dotnet-xamarin
· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

he can see the options both Photo and Video, as well as other functionalities

Do you want to open the system Camera application? For Android, you can use Intent to open directly like following code. However, if you finish take photo or video, you need back to your application manually, then use pick Photo and pick video api to get the photo or video.

Intent intent = new Intent();  
intent.SetAction("android.media.action.STILL_IMAGE_CAMERA");
StartActivity(intent);


Or you want to create a custom camera by yourself(Add take photo or video, other functionalities), you can use custom renderer like this thread:

https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/custom-renderer/view

0 Votes 0 ·

@LeonLu-MSFT Thanks for your reply. Your code is only for Android. I want the functionality for iOS too. I did some search and came up with CameraView from Xamarin Community Toolkit that may be useful. But I also see that it asks to fill out CaptureMode. Not sure if I can choose both video and photo for it. I will look more closely on it later on.

0 Votes 0 ·

I test with simiple of CameraView from Xamarin Community, when i change the take photo to video, this view will hang on. https://github.com/xamarin/XamarinCommunityToolkit/blob/main/samples/XCT.Sample/Pages/Views/CameraViewPage.xaml

0 Votes 0 ·
Show more comments

0 Answers