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

Access the camera does not work - Error - " Only one operation can be active at at time error"

$
0
0

Hello, i've make a simple app with xamarin.forms that access to photo camera or take picture. I've used the service of Xamarin-Forms-Labs , iv've configurated all, ioc... ecc.. but when i use the service it go in exception nad said to me "{System.InvalidOperationException: Only one operation can be active at at time at XLabs.Platform.Services.Media.MediaPicker.GetMediaAsync (UIImagePickerControllerSourceType sourceType, System.String mediaType, XLabs.Platform.Services.Media.MediaStorageOptions options) .."

This only happen a first time that i run the app, when i allow the app to access to camera, then if i close the app and reopen the window camera or camera roll appear.

this is my code():

In AppDelegate

private void SetIoc()
{
var resolverContainer = new SimpleContainer();
resolverContainer
.Register (t => AppleDevice.CurrentDevice)
.Register (t => t.Resolve ().Display)
.Register<IMediaPicker, MediaPicker>()
.Register (resolverContainer);
Resolver.SetResolver(resolverContainer.GetResolver());
}

In contentPage

private readonly TaskScheduler scheduler = TaskScheduler.FromCurrentSynchronizationContext();
private IMediaPicker mediaPicker;
...
var btn = new Button
{

Text = "Test",
Font = Font.SystemFontOfSize(NamedSize.Large),
BackgroundColor = Color.FromHex("#3CB371"),
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.CenterAndExpand,
TextColor =Color.White 

};

btn.Clicked += async (sender, e) => {

await SelectPicture();
};

...
private void Setup()
{
if (mediaPicker != null)
{
mediaPicker= return;
}

var device = Resolver.Resolve();

mediaPicker = DependencyService.Get() ;

if (mediaPicker == null)
{
mediaPicker = device.MediaPicker;
}
}

...

private async Task SelectPicture()
{

Setup();

return await this.mediaPicker.SelectPhotoAsync(new CameraMediaStorageOptions { MaxPixelDimension = 1024 }).ContinueWith(t =>
{
if (t.IsFaulted)
{
DisplayAlert("Error !",t.Exception.InnerException.ToString(), "OK");
}
else if (t.IsCanceled)
{

}
else
{
    var mediaFile = t.Result;


    return mediaFile;
}
return null;

} , scheduler);
}

How can i resolve it ?

Thanks
Alex


Viewing all articles
Browse latest Browse all 91519

Trending Articles



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