英文:
.net Maui MediaPicker.CaptureVideoAsync returns null for Android
问题
我正在尝试在Android上使用默认的媒体捕获工具MediaPicker来拍摄视频。
以下是我的代码:
if (MediaPicker.Default.IsCaptureSupported)
{
if (await Permissions.CheckStatusAsync<Permissions.Camera>() != PermissionStatus.Granted)
{
var result = await Permissions.RequestAsync<Permissions.Camera>();
if (result != PermissionStatus.Granted)
{ return; }
}
var video = await MediaPicker.CaptureVideoAsync();
string localFilePath = Path.Combine(FileSystem.CacheDirectory, video.FileName);
}
相机启动没有任何问题,我可以拍摄视频,但是当调用CaptureVideoAsync()函数时,它始终返回null作为Fileresult:
在使用Android模拟器(API 33,Android 13.0)和硬件设备进行调试时,情况相同。
我正在使用.NET 7 MAUI项目。
英文:
I'm trying to use default media capture tool MediaPicker to shoot video on android.
Here's my code:
if (MediaPicker.Default.IsCaptureSupported)
{
if (await Permissions.CheckStatusAsync<Permissions.Camera>() != PermissionStatus.Granted)
{
var result = await Permissions.RequestAsync<Permissions.Camera>();
if (result != PermissionStatus.Granted)
{ return; }
}
var video = await MediaPicker.CaptureVideoAsync();
string localFilePath = Path.Combine(FileSystem.CacheDirectory, video.FileName);
};
The camera starts without any problem, i can shoot the video, but when the function CaptureVideoAsync() always returns Fileresult as a null:
Works same way for debugging with android emulator (API 33 (Android 13.0) and on a hardware device.
I'm using .net 7 maui project
答案1
得分: 0
我可以在我的项目中重现您的问题。但是相同的代码在Android模拟器(API 31(Android 12.0))中运行良好。
我已经检查了有关Android上的媒体选择器的源代码,发现当用户取消视频捕获操作时,它将返回null。
我还进行了调试以检测它。在我停止录制视频并立即返回我的应用程序后,代码将进入return null
。但在Android模拟器(API 31(Android 12.0))上,它将显示保存和取消操作的按钮。如果用户点击✔按钮,它将返回结果。
所以这应该是Android 13中MediaPicker.CaptureVideoAsync()
的一个新问题。您可以在GitHub上发布一个新问题。
英文:
I can reproduce your problem in my project. But the same code worked well in the android emulator (API 31 (Android 12.0).
And I have check the source code about the media picker on the android and fond that it will return null when user cancel the operation about the video capture.
And I also debugged to detect it. The cod will go to the return null
after I stop the video recording and then get back to my app immediately. But on the android emulator (API 31 (Android 12.0), it will show the buttons about save and cancel operation. If user taps ✔ button, it will return the result.
So this should be a new issue for the MediaPicker.CaptureVideoAsync()
in the android 13. You can post a new issue on the github.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论