Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Uncaught Exception when using plugin.media

$
0
0

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 image

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;

        });
    }

}

}


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>