IOS - video fails to write to file after photo taken
jamesingreersc opened this issue · 1 comments
ONLY Post issues against Latest Beta!!!
Make sure you follow all of the setup directions before posting an issue: https://github.com/jamesmontemagno/MediaPlugin#important-permission-information
If you are creating an issue for a BUG please fill out this information. If you are asking a question or requesting a feature you can delete the sections below.
Failure to fill out this information will result in this issue being closed. If you post a full stack trace in a bug it will be closed, please post it to http://gist.github.com and then post the link here.
Bug Information
After taking a zoomed in photo the next video will fail to write to disk. No errors returned from take video call.
Version Number of Plugin: 5.0.1
Device Tested On: IPhone XR with software version 14.4
Simulator Tested On:N/A
Version of VS: Microsoft Visual Studio Enterprise 2019
Version of Xamarin: 16.8.000.262 (d16-8@4d60f9c)
Versions of other things you are using: Using Xamarin Forms 4.8.0.1821 and Essentials 1.5.3.2
Steps to reproduce the Behavior
- Open camera panel with TakePhotoAsync command
- Zoom in as far as it will go. I am using an IPhone XR and it uses the pinch zoom.
- Take the photo and use it.
- Open video panel with TakeVideoAsync
- Take a 5 second video.
At step 5 the video is not on the disk(will fail a File.Exists(filePath) check. If the first time it doesn't fail try a second time. I have never had to go more than twice.
Expected Behavior
Video is created and written to disk
Actual Behavior
File fails get written to disk, subsequently our file upload fails.
Code snippet
public async Task<string> TakeVideoAsync(StoreVideoOptions options)
{
var videoQuality = options.Quality;
if (options.Quality == VideoQuality.Low)
{
options.Quality = VideoQuality.Medium;
}
else
{
options.Quality = VideoQuality.High;
}
var mediaFile = await CrossMedia.Current.TakeVideoAsync(options);
if(mediaFile == null)
{
return string.Empty;
}
string sourcePath = mediaFile.Path;
var outputName = sourcePath.Replace(".mov", ".mp4");
var nsOutput = NSUrl.FromFilename(outputName);
AVAssetExportSessionPreset presetQuality;
switch (videoQuality)
{
case VideoQuality.High:
presetQuality = AVAssetExportSessionPreset.Preset1280x720;
break;
case VideoQuality.Medium:
presetQuality = AVAssetExportSessionPreset.Preset960x540;
break;
default:
presetQuality = AVAssetExportSessionPreset.Preset640x480;
break;
}
var exportSession = new AVAssetExportSession(AVAsset.FromUrl(NSUrl.FromFilename(sourcePath)), presetQuality)
{
OutputUrl = nsOutput,
OutputFileType = AVFileType.Mpeg4,
ShouldOptimizeForNetworkUse = true,
};
exportSession.ExportTaskAsync().Wait();
exportSession.Dispose();
exportSession = null;
nsOutput.Dispose();
nsOutput = null;
if (File.Exists(outputName))
{
File.Delete(sourcePath);
}
return outputName;
}
public async Task<MediaFile> TakePhotoAsync(StoreCameraMediaOptions options)
{
var mediaFile = await CrossMedia.Current.TakePhotoAsync(options);
return mediaFile;
}
Screenshots
Here is the test app I created
CameraTest.zip
Was unable to reproduce in latest beta