如何获取媒体设备信息?

时间:2018-03-16 05:26:38

标签: c# nuget mediadevices

我正在使用MediaDevices NuGet包来识别连接到计算机的所有媒体设备。我不确定如何获得MediaStorageInfo,例如它可容纳多少空间或可用空间。

我的代码片段:

var mediadevices = mediadevice.GetDevices();
MediaStorageInfo info = new MediaStorageInfo();
foreach (var device in mediadevices)
{
    ulong cap = info.Capacity
    ulong freespace = info.FreespaceInObjects;   
}

手册建议:

var devicess = MediaDevice.GetDevices();
using (var device = devicess.First(d => d.FriendlyName == "My Cell Phone"))
{
    device.Connect();

    // get list of available storages (SD-Card, Internal Flash, ...)
    var objects = device.FunctionalObjects(FunctionalCategory.Storage);
    MediaStorageInfo infoss = GetStorageInfo(objects.First());
    ulong size = infoss.FreeSpaceInBytes;

    device.Disconnect();
}

GetStorageInfo似乎丢失,因为错误声明无法解决且当前联系中不存在。我不知道如何将MediaDevice传递给{ {1}}。任何建议都有帮助。谢谢!

1 个答案:

答案 0 :(得分:0)

只需更改:

string[]

GetStorageInfo(objects.First());

它看起来应该像这样:

device.GetStorageInfo(objects.First())