Xamarin iOS ALAssetsLibrary WriteVideoToSavedPhotosAlbum doesn't save to library

593 views Asked by At

I am writing an iOS application using Xamarin and am having an issue getting videos to save to my photo library. I am using the WriteVideoToSavedPhotosAlbum method of the ALAssetsLibrary (code below), but the video is never saved. I do no receive an error, but I also do not receive an asset URL in the completion block either.

Does anyone have any idea what could be going on here?

var url = NSUrl.FromFilename (this.FilePath);
ALAssetsLibrary library = new ALAssetsLibrary ();
library.WriteVideoToSavedPhotosAlbum (url, delegate(NSUrl u, NSError e)
    {
        if (e != null)
        {
            new UIAlertView ("Error", "Unable to save video to library", null, "Ok").Show();
        }
    });

One thing to note is the FilePath value is a video stored in the applications document directory.

Thanks

1

There are 1 answers

0
Divyesh On

One thing to note is the FilePath value is a video stored in the applications document directory? What you are looking for exactly? as WriteVideoToSavedPhotosAlbum is use to store video capture using camera because directly we can not get its url so we have to store video or image captured using camera to device first then we can get its url and other information using ALAssetsLibrary

I have done like this and its working for me hope this might help you:

ALAssetsLibrary library = new ALAssetsLibrary();
library.WriteImageToSavedPhotosAlbum(originalImage.CGImage, meta, (assetUrl, error) =>
{
    library.AssetForUrl(assetUrl, delegate (ALAsset asset)
    {
        ALAssetRepresentation representation = asset.DefaultRepresentation;
        if (representation != null)
        {
            string fileName = representation.Filename != null ? representation.Filename : string.Empty;
            var filePath = assetUrl.ToString();
            var extension = filePath.Split('.')[1].ToLower();
            var mimeData = string.Format("image/{0}", extension);
            var mimeType = mimeData.Split('?')[0].ToLower();
            var documentName = assetUrl.Path.ToString().Split('/')[1];

        }
    }, delegate (NSError err) {
        Console.WriteLine("User denied access to photo Library... {0}", err);
    });
});