[Windows] MediaPicker.CaptureVideoAsync keeps handle to file after capturing video
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 23.3k
- Forks
- 2k
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 296
Description
Description
Using MediaPicker.Default.CaptureVideoAsync on the Windows platform keeps a handle to the capture.mp4 that gets created in the cache of the app. This doesn't clear, even after closing and reopening of the app, so operations on that file, such as recursively deleting your cache directory, will cause an exception.
Steps to Reproduce
- Consume the MediaPicker.Default.CapturePhotoAsync() somewhere in your app, following the example in the docs
- Use code such as System.IO.Directory.Delete(FileSystem.CacheDirectory, true), to delete the captured media - see exception at that point due to file lock
- Close the app and navigate to the cache directory in File Explorer and attempt to delete the file manually - see prompt the file is in use by another process.
In the repro project, launch it, click the button, record a video, then click the button again.
Link to public reproduction project repository
https://github.com/thomasphillipsgb/Windows-CaptureVideoAsync-Bug
Version with bug
9.0.40 SR4
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
Windows
Affected platform versions
Windows SDK 10.0.22000.0
Did you find any workaround?
Opening and closing the camera app forces the handle to be released.
Relevant log output
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the Windows implementation behind MediaPicker.Default.CaptureVideoAsync and compare its capture lifecycle with the repro project linked in the issue. Reproduce the second capture and Directory.Delete(FileSystem.CacheDirectory, true) failure, then verify the capture.mp4 handle is released so the cache file can be deleted after capture and app restart.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100