MAUI MediaPicker always open front camera

Bhuwan 716 Reputation points
2024-09-13T07:33:44.72+00:00

n my .NET MAUI application for both Android and iOS, I want to open the front camera by default when capturing images, and I am using the following code.

public async void TakePhoto()
{
    if (MediaPicker.Default.IsCaptureSupported)
    {
        FileResult photo = await MediaPicker.Default.CapturePhotoAsync();

        if (photo != null)
        {
            // save the file into local storage
            string localFilePath = Path.Combine(FileSystem.CacheDirectory, photo.FileName);

            using Stream sourceStream = await photo.OpenReadAsync();
            using FileStream localFileStream = File.OpenWrite(localFilePath);

            await sourceStream.CopyToAsync(localFileStream);
        }
    }
}

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,419 questions
0 comments No comments
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 42,081 Reputation points Microsoft Vendor
    2024-09-16T02:52:24.2033333+00:00

    Hello,

    For the issue of MediaPicker using the front camera, there is already the same problem and a solution in the GitHub community.

    You can refer to Specify Front or Back Camera - MediaPicker CapturePhotoAsync() #9520 for more information.

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.