MvvmCross picturechoosen plugin and camera stuck i

2019-09-02 02:39发布

问题:

Hi I'm experiencing a strange problem with a MvvmCross picturechooser plugin for iOS development using Xamarin. I am developing a form where user can choose/take multiple photos and a video.

My app allow users to add multiple photos either from the camera roll or to be captured directly from form.

For capturing video, i use Xamarin.Mobile api.

I'm using the MvvmCross picture choosen to do this. The problem occurs when 1 or 2 images / videos are taken with the camera.

Once 1 or 2 images / videos are captured when the camera screen is re-entered for a third time the image is static and doesn't update the camera view finder. The view is stuck at the last frame of whatever was captured last.

I have the same problem described here but only difference is that I used MvvmCross picture choosen plugin.

in my code i used to bind the command with my button as follow:

// MyView is inherited from MvxViewController (of mvvmcross) 
var set = this.CreateBinding<MyView,MyViewModel>();

//Binding button to picture chooser command
set.Bind(this.TakePhotoButton).To(vm=>vm.TakePictureCommand);

and in my view model:

public MvxCommand TakePictureCommand 
{ 
  get 
  { 
    this.takePictureCommand => this.takePictureCommand ?? new MvxCommand(()=>
           this.pictureChooserTask.TakePicture(300,95,this.OnPictureSelected,
           ()=>{}),,this.CanTakeOrChoosePicture); 
  } 
}

private void OnPictureSelected(Stream stream) 
{ 
   using(var memoryStream = new MemoryStream())
   { 
     stream.CopyTo(memoryStream); 
     // PictureBytes is a property which i am using to bind with image view
     this.PictureBytes= memoryStream.ToArray(); 
   } 
}

  private bool CanTakeOrChoosePicture() 
  { 
   return this.PictureBytes= null; 
  } 

can any one guide me what am i doing wrong?

回答1:

Looking at iOS Monotouch UIImagePickerController multiple photos / videos from camera, it looks like this is either an issue in Xamarin.iOS or in iOS/UIKit.

Do you see the same problem in the main MvvmCross sample apps?

If you do, then you can try changing the MvvmCross code to use delegates instead of the Xamarin.iOS C# events as suggested in iOS Monotouch UIImagePickerController multiple photos / videos from camera - the Mvx code is in https://github.com/MvvmCross/MvvmCross/blob/v3.1/Plugins/Cirrious/PictureChooser/Cirrious.MvvmCross.Plugins.PictureChooser.Touch/MvxImagePickerTask.cs

Another thing you can perhaps try, is to use a separate task for each image request - e.g. using var task = Mvx.Resolve<IMvxPictureChooserTask(); to get a new task each time instead of using the same constructor injection task every time.

If nothing else helps, then maybe try contacting Xamarin support to see if they are aware of the issue and have any suggestions.