jamesmontemagno / MediaPlugin

Take & Pick Photos and Video Plugin for Xamarin and Windows
MIT License
711 stars 360 forks source link

TakeVideoAsync doesn't save recorded video to the gallery with SaveToAlbum = true #937

Open CodeToKillBug opened 3 years ago

CodeToKillBug commented 3 years ago

I've tried recording video on Xamarin Forms Application and found the problem when I try to picking up the video I've recorded. The video that is just recorded doesn't show in video picker As it showing recorded videos path :- App Memory (/storage/emulated/0/Android/data/com.companyname.AppName/files/Movies/) but While we try to Pick the same Video, we are unable to find the actual video which is not getting saved in device. But if I switch to taking picture and pick it the picture to upload in firebase storage up there's no problem.

Code :-

async void OnCaremaIconClicked(object sender, EventArgs e) { await CrossMedia.Current.Initialize();

if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakeVideoSupported)
{
    DisplayAlert("No Camera", ":( No camera avaialble.", "OK");
    return;
}

var file = await Plugin.Media.CrossMedia.Current.TakeVideoAsync(new Plugin.Media.Abstractions.StoreVideoOptions
{
    Directory = "DefaultVideos",
    Name = "video.mp4",
    SaveToAlbum = true
});
//await Task.Delay(6000);
if (file == null)
    return;

await DisplayAlert("Video Recorded", "Location: " + file.AlbumPath, "OK");
file.Dispose();
//=====================================Picture==================================

//if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
//{
//    DisplayAlert("No Camera", ":( No camera available.", "OK");
//    return;
//}

//var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
//{
//    Directory = "Sample",
//    Name = "test.jpg",
//    SaveToAlbum = true
//});

//if (file == null)
//    return;

//await DisplayAlert("File Location", file.AlbumPath, "OK");

}

async void OnVideoPickerIconClicked(object sender, EventArgs e) { await CrossMedia.Current.Initialize();

if (!CrossMedia.Current.IsPickVideoSupported)
{
    DisplayAlert("Videos Not Supported", ":( Permission not granted to videos.", "OK");
    return;
}
var file = await Plugin.Media.CrossMedia.Current.PickVideoAsync();

if (file == null)
    return;

await DisplayAlert("Video Selected", "Location: " + file.AlbumPath, "OK");
//file.Dispose();

//================================PICTURE==============================

//if (!CrossMedia.Current.IsPickPhotoSupported)
//{
//    DisplayAlert("Photos Not Supported", ":( Permission not granted to photos.", "OK");
//    return;
//}
//var file = await Plugin.Media.CrossMedia.Current.PickPhotoAsync(new Plugin.Media.Abstractions.PickMediaOptions
//{
//    PhotoSize = Plugin.Media.Abstractions.PhotoSize.Medium,

//});

//if (file == null)
//    return;
//await DisplayAlert("Video Selected", "Location: " + file.AlbumPath, "OK");

}

boris-df commented 2 years ago

On Android this library doesn't seem to store the video in the public gallery - it works on iOS and it works with Photos on Android but with Video in Android. Don't know why yet :'(

boris-df commented 2 years ago

See my answer here: https://github.com/jamesmontemagno/MediaPlugin/issues/940#issuecomment-1040227818