jamesmontemagno / MediaPlugin

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

Awaiting for TakeVideoAsync is not enough for having the video saved #221

Open PierreCourt opened 7 years ago

PierreCourt commented 7 years ago

Please fill out either the bug or feature request section and remove whatever section you are not using.

Bug

Version Number of Plugin: 2.6.2 Device Tested On: Samsung galaxy S4, OnePlus X

Expected Behavior

When using "await CrossMedia.Current.TakeVideoAsync" I expect to have the video saved at the path in the Media File

Actual Behavior

When using "await CrossMedia.Current.TakeVideoAsync" and trying to read the file, there is sometimes a null returned, because the file wasn't already saved. After adding a Task.Delay of some seconds, it is possible to read the file.

Steps to reproduce the Behavior


using (var file = await CrossMedia.Current.TakeVideoAsync(new Plugin.Media.Abstractions.StoreVideoOptions()
            {
                Quality = Plugin.Media.Abstractions.VideoQuality.Medium
            }))
            {
                if (file == null || string.IsNullOrEmpty(file.Path))
                    return;
               // Working with that delay
               // await Task.Delay(6000);
                byte[] videoAsByte = ByteArraysHelpers.ReadToEnd(file.GetStream());
                if (videoAsByte .Count() <= 0) {
                                var s = "sadness";
                }else{
                                var s = "happiness";
                }
}

Thanks for your help

levivas commented 6 years ago

Also have this problem, and adding await Task.Delay(6000); helps me. I think this problem bind with synchronization threads.

JayMansel commented 6 years ago

Same problem, however only happens on Android for myself (probably due to the device's low spec), and only when taking videos less than 5 seconds long. Otherwise it works fine. Adding the Task.Delay helps.

miguelon76 commented 6 years ago

Have a similiar problem. In my case, i can get the video stream but video length is 0 bytes until i close the app.

Thanks for your help and for this great plugin.

urosmil commented 6 years ago

Any news about this? We are also facing this issue. Await Task.Delay is not solving the problem as well.