Search code examples
c#xamarinxamarin.formsxamarin.iosuiimagepickercontroller

How to disable video compression - UIImagePickerController, Xamarin.IOS, C#


Program: I am currently using an UIImagePickerController that lets the user select a video on their device. It then retrieves the URL for the video and stores it.

Problem: When a user selects a video, it compresses the video. How can I disable the compressing part? Because I am only interested in the url, and if the video is large it takes a long time.

I found this answer - https://stackoverflow.com/a/48643954/9764182

However, for me the "VideoExportPreset" property takes a string.

Code: I don't think my code will be helpful, I do have a function that is subscribed to the finished picking event of the picker. However, the compression happens before that event is fired.

MediaPicker = new UIImagePickerController();
MediaPicker.SourceType = UIImagePickerControllerSourceType.PhotoLibrary;
MediaPicker.MediaTypes = UIImagePickerController.AvailableMediaTypes(UIImagePickerControllerSourceType.PhotoLibrary);
MediaPicker.ImageExportPreset = UIImagePickerControllerImageUrlExportPreset.Current;
MediaPicker.VideoQuality = UIImagePickerControllerQualityType.High;
MediaPicker.FinishedPickingMedia += Handle_FinishedPickingMedia;
MediaPicker.Canceled += Handle_Canceled;

Solution

  • AVAssetExportSessionPreset provides a convenience enum that you can use to get the NSString from and then you can convert it to a C# string.

    Example:

    var MediaPicker = new UIImagePickerController
    {
        ~~~~
        VideoExportPreset = AVAssetExportSessionPreset.Passthrough.GetConstant().ToString(),
        ~~~~
    };