question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MediaImplementation.TakeMediaAsync Exception

See original GitHub issue

Bug

Sometimes on Android when taking a photo I get that excpetion.

Version Number of Plugin: 2.6.0.12-beta Device Tested On: LENOVO T2-A7-20F

Package: com.rolsped.TruckerApp Version Code: 27 Version Name: 1.0 Android: 4.4.2 Android Build: T2-A7-20F_S000009_151022_ROW Manufacturer: Lenovo Model: Tab2A7-20F Thread: main-1 Start Date: Wed Oct 26 20:56:22 CEST 2016 Date: Wed Oct 26 21:03:27 CEST 2016 Format: Xamarin

Xamarin caused by: android.runtime.JavaProxyThrowable: System.InvalidOperationException: Only one operation can be active at a time at Plugin.Media.MediaImplementation.TakeMediaAsync (System.String type, System.String action, Plugin.Media.Abstractions.StoreMediaOptions options) [0x00039] in <35066fbd82df477487a6a1e39050b480>:0 at Plugin.Media.MediaImplementation+<PickPhotoAsync>d__17.MoveNext () [0x0008a] in <35066fbd82df477487a6a1e39050b480>:0 — End of stack trace from previous location where exception was thrown — at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <fe5ae17f49cd42d9923d7a78735dd424>:0 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0004e] in <fe5ae17f49cd42d9923d7a78735dd424>:0 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in <fe5ae17f49cd42d9923d7a78735dd424>:0 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in <fe5ae17f49cd42d9923d7a78735dd424>:0 at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in <fe5ae17f49cd42d9923d7a78735dd424>:0 at trucker_rolsped.Pages.MediaPage+<<-ctor>b__5_2>d.MoveNext () [0x001ce] in <097cdfc3784648edab9e909af0f616aa>:0 — End of stack trace from previous location where exception was thrown — at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <fe5ae17f49cd42d9923d7a78735dd424>:0 at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>m__0 (System.Object state) [0x00000] in <fe5ae17f49cd42d9923d7a78735dd424>:0 at Android.App.SyncContext+<Post>c__AnonStorey0.<>m__0 () [0x00000] in <79e6945a2f4a4e2f844e36c860dfb012>:0 at Java.Lang.Thread+RunnableImplementor.Run () [0x0000b] in <79e6945a2f4a4e2f844e36c860dfb012>:0 at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in <79e6945a2f4a4e2f844e36c860dfb012>:0 at (wrapper dynamic-method) System.Object:93cfcaba-4c78-4a88-a4df-f54a276b6364 (intptr,intptr) at mono.java.lang.RunnableImplementor.n_run(Native Method) at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:30) at android.os.Handler.handleCallback(Handler.java:808) at android.os.Handler.dispatchMessage(Handler.java:103) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:5341) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:825) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:641) at dalvik.system.NativeStart.main(Native Method)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ericbrunnercommented, Oct 26, 2016

@sbonello Thanks. My code is from the sample like that. The only difference is that I create a copy of the media stream because xamarin thankfully disposes the stream when loaded with ImageSource.FromStream and I need the stream for upload afterwards to the image preview.

takePhoto.Clicked += async (sender, args) =>
        {
            await CrossMedia.Current.Initialize();

            if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
            {
                await DisplayAlert("Media Info", "Keine Kamera verfügbar.", "OK");
                return;
            }

            SelectedMedia = new TruckerAppMediaFile
            {
                Type = MediaType.Photo,
                File = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
                {
                    PhotoSize = PhotoSize.Medium,
                    CompressionQuality = 92,
                    SaveToAlbum = true,
                    Directory = "TruckerAppPhotos",
                    Name = $"{DateTime.Now}_documenttypeXYZ.jpg"
                })
            };


            if (SelectedMedia?.File == null)
            {
                await DisplayAlert("Media Info", "Es wurde kein Foto erstellt.", "OK");
                return;
            }


            var imageStream = await DependencyService.Get<Interfaces.Media.IMedia>()
                .CopyMediaAsync(SelectedMedia.File.GetStream());
            image.Source = ImageSource.FromStream(() => imageStream);

            SendMedia.IsEnabled = true;
        };
0reactions
jamesmontemagnocommented, Oct 28, 2016

Yes, this is different then what was reported, so would be a different bug, so I suggest opening a new one and reporting what version of the plugin you are using with the info you put on there.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't use Xam.Plugin.Media plugin
I have android application that is built using Xamarin Forms. In order to use camera of the mobile, I install Xam.Plugin.Media plugin and...
Read more >
Error on Xamarin: only one operation can be active at a ...
This is the complete message when I'm debugging the app tha is shown as a dialog: Unhandled Exception: System.InvalidOperationException: Only ...
Read more >
StoreCameraMediaOptions, Plugin.Media.Abstractions C# ...
TakePhotoAsync(imgStoreOptions); } catch (Exception) { await ... VerifyOptions(options); return await TakeMediaAsync("image/*", MediaStore.
Read more >
StoreVideoOptions, Media.Plugin.Abstractions C# ...
File: MediaImplementation.cs Project: Lotpath/Xamarin. ... NotSupportedException(); VerifyOptions (options); return TakeMediaAsync ("video/*", MediaStore.
Read more >
Untitled
InvalidOperationException : Only one operation can be active at a time. Here's the stack trace: MediaImplementation.TakeMediaAsync (System.String …
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found