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

Camera access with the media plugin

$
0
0

Hi,

I do my first steps in Xamarin Forms following a Udemy course.
In order to access the the phone camera I was getting some ideas from a youtube tutorial using
the media plugin. After pressing a button a photo shout be shot.

When deploying the code on the my phone via Visual Studio 2017 and the live player
I get the message "The method or operation is not implemented".

The plugin is installed and no errors are present in the editor window.

Can someone point me to a possible error?
The line the gives the error is indicated in the code-behind file.

Thanks in advance,
Tim

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="xxx://xamarin.com/schemas/2014/forms"
             xmlns:x="xxx://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:PhotoApp01"
             x:Class="PhotoApp01.MainPage">

    <StackLayout>
        <Button x:Name="TakePictureButton"
                Clicked="TakePictureButton_Clicked" 
                Text="Take from Camera"/>
        <Button x:Name="UploadPictureButton"
                Clicked="UploadPictureButton_Clicked"
                Text="Pick a photo"/>
        <Image x:Name="Image1" HeightRequest="240" />
    </StackLayout>
</ContentPage>




        using System;
        using System.Collections.Generic;
        using System.Linq;
        using System.Text;
        using System.Threading.Tasks;
        using Plugin.Media;
        using Plugin.Media.Abstractions;
        using Xamarin.Forms;

        namespace PhotoApp01
        {
            public partial class MainPage : ContentPage
            {
                public MainPage()
                {
                    InitializeComponent();
                }

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

                    if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
                    {
                        await DisplayAlert("No camera", "No camera available", "OK");
                        return;
                    }

        ///////////////////////////////////////////////////////
                    // THE NEXT LINE CAUSES THE ERROR MESSAGE
        ///////////////////////////////////////////////////////            

                    var file = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions
                    {
                        SaveToAlbum = true,
                        Name = "test.jpg"
                    });

                    if (file == null)
                        return;

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

                }

                private async void UploadPictureButton_Clicked(object sender, EventArgs e)
                {
                    if (!CrossMedia.Current.IsPickPhotoSupported)
                    {
                        await DisplayAlert("No camera", "No camera available", "OK");
                        return;
                    }

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

                    if (file == null)
                        return;

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

                }                        
            }
        }

Viewing all articles
Browse latest Browse all 77050

Trending Articles



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