Save video file to camera roll in xamarin ios

MahigaruMahigaru INMember
Hi All,

How to save video file to camera roll in xamarin ios. I tried using AlASSETLibrary but it is not working in sikulator. Can you please help me in that?

Thanks,
Mahipal

Answers

  • ChrisJohnsonChrisJohnson ✭✭ USMember ✭✭

    I am saving a UIImage to an album which also adds to camera roll. You can probably adapt this code.

        void AddAssetToAlbum(UIImage image, PHAssetCollection album, string imageName)
                {
                    try
                    {
                        PHPhotoLibrary.SharedPhotoLibrary.PerformChanges(() =>
                        {
                            // Create asset request
                            var creationRequest = PHAssetCreationRequest.CreationRequestForAsset();
                            var options = new PHAssetResourceCreationOptions
                            {
                                OriginalFilename = imageName
                            };
                            creationRequest.AddResource(PHAssetResourceType.Photo, image.AsJPEG(), options);
                            // Change asset request (change album by adding photo to it)
                            var addAssetRequest = PHAssetCollectionChangeRequest.ChangeRequest(album);
                                addAssetRequest.AddAssets(new PHObject[] { creationRequest.PlaceholderForCreatedAsset });
                        }, (success, error) =>
                     {
                            if (!success)
                                Console.WriteLine("Error adding asset to album");
                        });
                    }
                    catch (Exception ex)
                    {
                        string h = ex.Message;
                    }
                }
    
Sign In or Register to comment.