Hello,
You could refer to the following code to implement this feature on Android and iOS:
For Android
public static class SaveVideoService
{
public static bool SaveVideo(byte[] arr, string imageName)
{
var contentValues = new ContentValues();
contentValues.Put(MediaStore.IMediaColumns.DisplayName, imageName);
contentValues.Put(MediaStore.Files.IFileColumns.MimeType, "video/mp4");
contentValues.Put(MediaStore.IMediaColumns.RelativePath, "Pictures/relativePath");
try
{
var uri = MainActivity.Instance.ContentResolver.Insert(MediaStore.Video.Media.ExternalContentUri, contentValues);
var output = MainActivity.Instance.ContentResolver.OpenOutputStream(uri);
output.Write(arr, 0, arr.Length);
output.Flush();
output.Close();
}
catch (System.Exception ex)
{
Console.Write(ex.ToString());
return false;
}
contentValues.Put(MediaStore.IMediaColumns.IsPending, 1);
return true;
}
}
For iOS:
public static class SaveVideoService
{
public static void SavePicture(string path)
{
var videoCompatible = UIVideo.IsCompatibleWithSavedPhotosAlbum(path);
//Check that the video can be saved to an album
if (videoCompatible)
{
UIVideo.SaveToPhotosAlbum(path, (s, e) => {
});
}
else
{
Console.WriteLine("The video cannot be saved to an album");
}
}
}
You could invoke those services on MAUI as the following code:
#if ANDROID
MauiApp22.Platforms.Android.SaveVideoService.SaveVideo(b, "test.mp4");
#elif IOS
SaveVideoService.SaveVideo(localFilePath);
#endif
Best Regards,
Alec Liu.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.