Forum Xamarin.Forms

Uncaught Exception when using plugin.media

I get an Uncaught Exception Cannot throw 'Plugin.Media.Abstractions.MediaPermissionExceptions' on thread... (im using live player can see the whole massage) I followed a video

I have also given permission in andriod for CAMERA, READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE. I dont know how to continue any leads?

XAML:

    </Button>

    <Button BackgroundColor="Red" Clicked="Browsephoto_onclick" Text="Browse" x:Name="Browsephoto">

    </Button>

    <Image x:Name="MainImage">


    </Image>

</StackLayout>

CS:

public partial class NewitemPage : ContentPage
{
public NewitemPage ()
{
InitializeComponent ();
}

    private async void Takephoto_onclick(object sender, EventArgs e)
    {



        await CrossMedia.Current.Initialize();

        if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
        {
            await DisplayAlert("Error", "(Camera not avalible.", "OK");
            return;

        }

        var file = await CrossMedia.Current.TakePhotoAsync(
            new StoreCameraMediaOptions
            {
                SaveToAlbum = true,
                Name = "Annons_bild.jpg"

            });

        if (file == null)
        {
            return;

        }



        MainImage.Source = ImageSource.FromStream(() => file.GetStream());

    }

    private async void browsephoto_onclick(object sender, EventArgs e)
    {
        await CrossMedia.Current.Initialize();

        if (!CrossMedia.Current.IsPickPhotoSupported)
        {
            await DisplayAlert("Error", "Cant browse photo", "okbye");
            return;
        }

        var file = await CrossMedia.Current.PickPhotoAsync();

        if (file == null)
        {
            return;
        }



        MainImage.Source = ImageSource.FromStream(() =>
        {
            var stream = file.GetStream();
            file.Dispose();
            return stream;

        });
    }

}

}

Best Answer

Answers

Sign In or Register to comment.