Windows平台错误上的MAUI媒体选择器
我创建了一个非常基本的Mauiapp,因为我想在Windows平台上尝试MediaPicker。
因此,我从官方文档并尝试运行我的应用程序
,但是,如果我添加< uap:功能名称=“ webCam”/>
到package> package.appxmanifest
file file如文档中所建议的,并运行应用程序给我以下错误:
Error DEP0700: Registration of the app failed. [0x80080204] error 0xC00CE169: App
manifest validation error: The app manifest must be valid as per schema: Line 39, Column
21, Reason: 'webcam' violates enumeration constraint of 'documentsLibrary
picturesLibrary videosLibrary musicLibrary enterpriseAuthentication
sharedUserCertificates userAccountInformation removableStorage appointments contacts
phoneCall blockedChatMessages objects3D voipCall chat'.
The attribute 'Name' with value 'webcam' failed to parse. MauiApp3
因此,为了解决此问题,我尝试将功能从< uap:功能名称=“ webcam”/> to
< devicecapibility name =“ WebCam”/>
。
这样,我可以无错误地运行应用程序,但是photo
始终为null:
public async void TakePhoto(object sender, EventArgs e)
{
if (MediaPicker.Default.IsCaptureSupported)
{
FileResult photo = await MediaPicker.Default.CapturePhotoAsync();
if (photo != null)
{
// save the file into local storage
string localFilePath = Path.Combine(FileSystem.CacheDirectory, photo.FileName);
using Stream sourceStream = await photo.OpenReadAsync();
using FileStream localFileStream = File.OpenWrite(localFilePath);
await sourceStream.CopyToAsync(localFileStream);
}
else
{
// *** IT ALWAYS ENTERS IN THE ELSE CLAUSE ***
// *** BECAUSE photo IS ALWAYS NULL ***
CounterBtn.Text = $"Capture is supported but {photo} is null";
}
}
}
注意:当我单击我在mainpage.xaml <我单击此按钮时,上述函数被调用。 /代码>文件:
<Button
x:Name="ImageBtn"
Text="Take Photo"
SemanticProperties.Hint="Take Image"
Clicked="TakePhoto"
HorizontalOptions="Center" />
I have created a very basic MauiApp because I wanted to try the MediaPicker on the Windows Platform.
Thus I copied the code from the official documentation and tried to run my application
However if I add <uap:Capability Name="webcam"/>
to the Package.appxmanifest
file as suggested in the documentaion, and run the application it gives me the following error:
Error DEP0700: Registration of the app failed. [0x80080204] error 0xC00CE169: App
manifest validation error: The app manifest must be valid as per schema: Line 39, Column
21, Reason: 'webcam' violates enumeration constraint of 'documentsLibrary
picturesLibrary videosLibrary musicLibrary enterpriseAuthentication
sharedUserCertificates userAccountInformation removableStorage appointments contacts
phoneCall blockedChatMessages objects3D voipCall chat'.
The attribute 'Name' with value 'webcam' failed to parse. MauiApp3
So in order to solve this problem I tried to change the capability from <uap:Capability Name="webcam"/>
to <DeviceCapability Name="webcam"/>
.
In this way I can run the application without errors, but photo
is always null:
public async void TakePhoto(object sender, EventArgs e)
{
if (MediaPicker.Default.IsCaptureSupported)
{
FileResult photo = await MediaPicker.Default.CapturePhotoAsync();
if (photo != null)
{
// save the file into local storage
string localFilePath = Path.Combine(FileSystem.CacheDirectory, photo.FileName);
using Stream sourceStream = await photo.OpenReadAsync();
using FileStream localFileStream = File.OpenWrite(localFilePath);
await sourceStream.CopyToAsync(localFileStream);
}
else
{
// *** IT ALWAYS ENTERS IN THE ELSE CLAUSE ***
// *** BECAUSE photo IS ALWAYS NULL ***
CounterBtn.Text = quot;Capture is supported but {photo} is null";
}
}
}
Note: The function above is called when I click to this button that I've defined in MainPage.xaml
file:
<Button
x:Name="ImageBtn"
Text="Take Photo"
SemanticProperties.Hint="Take Image"
Clicked="TakePhoto"
HorizontalOptions="Center" />
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,这是Winui3的古老而已知的错误。
microsoft/windowsappsdk#1034
作为一种可行的方法,您可以从用于Android,iOS和催化剂的毛伊岛。
然后,为Windows实现自定义媒体挑选器,并在所有
capture ...
方法中使用capture> capturephotoasync
使用自定义类用于摄像机捕获:这是新的
camerAcaptureui
class:也在package.appxmanifest中添加以下功能:
摄像头类的学分
编辑:
修改的代码允许视频捕获,
Unfortunately this is a old and known bug for WinUI3.
microsoft/WindowsAppSDK#1034
As a workaround you can create a custom mediapicker that inherit everything from the MAUI one for Android, iOS and Catalyst.
Then implement a custom mediapicker for Windows, intheriting all the
Capture...
methods and reimplementing theCapturePhotoAsync
using a custom class for camera capture:This is the new
CameraCaptureUI
class:Also in the Package.appxmanifest add these capabilities:
Credits for the CameraCapture class
Edit:
Modified code to allow video capturing, credits here