Code Monkey home page Code Monkey logo

mediadevices's Introduction

MediaDevices

Media Devices is a API to interact with MTP (Media Transfer Protocol), PTP (Picture Transport Protocol) and MSC (Mass Storage Class) devices like cell phones, tablets and cameras.

Download

Future: NuGet Package

Documentation

Donate

You are welcome to support this project.

Donate

mediadevices's People

Contributors

bassman2 avatar chcg avatar dependabot[bot] avatar ronsijm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

mediadevices's Issues

Question: Download file with progress?

Awesome library - I have a quick question:

I'm using MediaDevices.DownloadFile() to download video files from a device. Sometimes these files can be rather large, upto 1GB in size. I'd love to know, is there any way to get download progress from the device?

If there's any way of having a callback to report download progress - that would be awesome or if you can even point me to where I might be able to add this to your project, be happy to write and submit a pull request.

Can not connect again after call method 'MediaDevice.DeleteFile'

Describe the bug
call device.connect() will wait forever after call 'MediaDevice.DeleteFile', and windows explorer can not show any disk and file. it will be recover after pull out device from computer

To Reproduce
device.Connect();
device.DeleteFile("Any file exists in device");
device.Disconnect();

Expected behavior
can call device.connect() again and windows exploer can work correctly

Device
Samsung Galaxy Note 10, SM-N9700, Android 10

Version:
1.9.1

Additional context
Regards

Unable to get the file name containing special characters correctly

Describe the bug
MediaDevice.GetFiles() Unable to get full file name on some special name

To Reproduce
file name exists in media device : princess_connect!_re:dive skirt_lift tail.jpg
call method MediaDevice.GetFiles(), get file name : dive skirt_lift tail.jpg

Calling MediaDevice.GetFileInfo() with an incomplete file name will cause an exception that the file does not exist.

Expected behavior
This file name is legal in Android. hope to get the complete file name

Device
Sanmsung Galaxy Note 10, SM-N9700

Version:
1.9.1

Expose writing Stream on MediaFileInfo

Would it be possible to add Stream OpenWrite() method to the MediaFileInfo class in the same fashion as the Stream OpenRead() is? That would allow us e.g. to use CopyToAsync() for writing to the MTP device.

I am working on abstraction in my project which uses pure Streams for both download/upload transfers across multiple types of devices, so currently I will need to find some workaround, since only the void UploadFile(Stream stream, string path) is available at the moment (as far as I searched the library code).

System.AccessViolationException on Windows 10 (64 Bit) after 64 bit-fix?

Hello Bassman2,

after my successful performance experiments in #7 using a Windows 7 x64 PC I wanted to repeat the same for my main machine running Windows 10 (v1803) x64.

However, my WPF application always crashes during the run with the following exception.

An unhandled exception of type 'System.AccessViolationException' occurred in mscorlib.dll
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Sadly I haven't been able to catch this exception or any corresponding callstack at all and I don't really know, which operations actually fails.

The test does the following:

  1. Enumerate all files using root.EnumerateFileSystemInfos("*", SearchOption.AllDirectories)
  2. Store MediaFileInfo handle for each file in a list
  3. Iterate over that list and copy everything to a folder on my PC using MediaFileInfo.CopyTo

The exception always triggers during this run but sometimes during phase 2 and during phase 3.

One thing I was able to determine: the issue only appears after commit 436ab2e which included the "64-bit fix" for #6. Using the commit before ( 01a6e6a) works fine (albeit slow).

To be honest: I'm uncertain about the code changes you implemented then and what they actually affect. Do you have any suggestions on how to analyze this appropriately?

Best regards,
tale

MediaDevice.GetDevices() returns incomplete MediaDevice-Objects

We are calling MediaDevice.GetDevices() in our program from different threads (but never at the same time) and have noticed that only the first call (from the main thread) provides a complete list of all connected (Android) devices. Although all subsequent calls return a list with the correct number of MediaDevice objects, only the first object of this list is completely filled/initialized correctly. All subsequent objects are uninitialized, the DeviceId and Manufacturer fields are null.

Does something have to be considered when calling MediaDevice.GetDevices() from different threads?

EventHandler

Sorry for being a novice, but how do I code an eventhandler to pick up when a device has been removed?

I can't see any examples anywhere.

Macos / Avalonia issue: COM not supported

Apologies in advance, I'm struggling to grok all of this. Anyway, I have a very small test project using the Avalonian UI (which I've used before to create windows/mac common source projects). This one works fine on windows, and doesn't on macos.
Note on loading project on the mac, I get the message:
/Users/t/Documents/Projects/Tm2/Tm2.csproj: Warning NU1701: Package 'MediaDevices 1.8.0' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETCoreApp,Version=v3.0'. This package may not be fully compatible with your project. (NU1701) (Tm2)

in debug, the statement "var devices = MediaDevice.GetDevices();"
produces a System.TypeInitialization Exception with an innerexception of {System.PlatformNotSupportedException: COM is not supported}

CopyThumbnail cause exception when copy an none Thumbnail media file like .rmvb

Describe the bug
System.Reflection.TargetInvocationException
COMException: 没有群集资源。 (异常来自 HRESULT:0x8007138E)

To Reproduce
call method CopyThumbnail on an none thumbnail file such as .rmvb video file, will cause Exception

Expected behavior
no exception

Device
Samsung galaxy Note 10, SM-N9700, Android 10

Version:
1.9.1

Additional context
Consider add a method to check the file has thumbnail or not

invalid_datatype, when create something in device

i found this article today, and i'm trying to use example at starting page
( about createdirectory(@"\Phone\Documents\Temp"). but i have some problem.

when i using that code, exception appeared about invalid_datatype at createdirectory.
how can i fix them?

i tried device.EnumerateDirectories(@"\Phone\Documents"), but it works well.
and using with galaxy s8.

var devices = MediaDevice.GetDevices();
var myphonename;
using (var device = devices.First(d => d.FriendlyName == myphonename))
{
device.Connect();

device.CreateDirectory(@"\Phone\Documents\Temp");

using(FileStream stream = File.OpenRead(@"C:/Temp/Test.txt"))
{
device.UploadFile(stream, @"\Phone\Documents\Temp\Test.txt");
}
device.Disconnect();
}

MediaDevices.GetDevices() does not refresh

Hi i have recently started using this library and its great and easy to use. The only issue i have had is that the list of attached devices returned by MediaDevices.GetDevices() does not update if a device is plugged in/removed while my application is running.
I also get an error when i mount a drive after launching the application (null exception while enumerating GetDrives()

Cheers

Vendor extensions

I am trying to use this library to send 0x101B (GetPartialObject) request to MTP device and than read the data. I can't find the way to do that. What the inputParams should be? How to read the received data?
Thank you.

2 feature questions

Hi Bassman2,
first of all thank you very much for that awesom library.

I have to questions for you:

  1. I would like to access the IMEI No of smartphones that are connected to my pc. Do you have any idea how to get the number?
  2. I*d also like to open the windows explorer on a specific directory of the smartphone. Can I achieve this somehow with your library?

Thank you again

EnumerateFiles() multiple filters

Hi Ralf

First: great work! Thanks a lot.

Now my "problem":
I have to find and grab all multimedia files (mp4, mp3, jpg, png, gif, wav, ...).
With the given method EnumerateFiles() I only able to search for one extension at a time. e.g. device.GetRootDirectory().EnumerateFiles("*.jpg"). That means I have to do that more or less manually for all files I want to grab.

It would be nice, if there is a way to do it like this:
device.GetRootDirectory().EnumerateFiles("*.jpg|*.png|*.mp4")
or
device.GetRootDirectory().EnumerateFiles(new string[] { "*.jpg", "*.png" })

Thanks for your service

IStream.cs missing in repo

See https://ci.appveyor.com/project/chcg/mediadevices/build/job/eipos0gctt9u16mh

CSC : error CS2001: Source file 'C:\projects\mediadevices\MediaDevicesShare\Internal\IStream.cs' could not be found. [C:\projects\mediadevices\MediaDevicesCore30\MediaDevicesCore30.csproj]
CSC : error CS2001: Source file 'C:\projects\mediadevices\MediaDevicesShare\Internal\IStream.cs' could not be found. [C:\projects\mediadevices\MediaDevicesCore20\MediaDevicesCore20.csproj]
CSC : error CS2001: Source file 'C:\projects\mediadevices\MediaDevicesShare\Internal\IStream.cs' could not be found. [C:\projects\mediadevices\MediaDevicesFramework45\MediaDevicesFramework45.csproj]oj]

DownloadFile NotImplementedException

I was testing out the MediaDevice.DownloadFile method as it was used in your Unit Test:

                using (MemoryStream stream = new MemoryStream())
                {
                    device.DownloadFile(filePath, stream);
                    position = stream.Length;

                    using (FileStream file = File.Create(localPath))
                    {
                        stream.Position = 0;
                        stream.CopyTo(file);
                    }
                }

And I keep getting a NotImplementedException:
at System.Runtime.InteropServices.ComTypes.IStream.Stat(STATSTG& pstatstg, Int32 grfStatFlag)
at MediaDevices.StreamWrapper.get_Length()
at System.IO.Stream.GetCopyBufferSize()
at MediaDevices.MediaDevice.DownloadFile(String path, Stream stream)
at TestAndroidFileTransfer.Program.Main(String[] args) in C:\Users\Jonathan\source\testrepos\TestAndroidFileTransfer\TestAndroidFileTransfer\Program.cs:line 26

Have you seen this issue before? It is not immediately apparent what is going on..

Is it possibe to monitor the gallary?

Hey Bassman,

I have once again a question about your NuGet. Is there a way to monitor the gallary for changes, like adding an Image or deleting one?

Thanks in advance,
Daniel

Avoid operation delay after delete object by setting the COOKIE policy

Is your feature request related to a problem? Please describe.
A potential blocking problem because WUDFHost.exe will cache the file list in MTP device when first connect to the device.

Describe the solution you'd like
Set before open the MTP device

CLSID_WPD_NAMESPACE_EXTENSION ("{35786D3C-B075-49B9-88DD-029876E11C01}")

Add this to MediaDevice.Connect()

var clientInfo = (IPortableDeviceValues)new PortableDeviceValues();

clientInfo.SetStringValue(ref WPD.CLIENT_EVENT_COOKIE, "{35786D3C-B075-49B9-88DD-029876E11C01}");

Describe alternatives you've considered
Explorer use this flag to notify WUDFHost.exe not to cache any file list when we connect to the MTP device. That could be helpful if WUDFHost.exe takes a long time to get the whole list, which will block any operation until it release the lock. It's an important value and that's why explorer will never be blocked by WUDFHost.exe

Additional context
Delay is obviously after we call MediaDevice.DeleteFile(). Set this policy will solve this issue.

Method "UploadFile" uses wrong timestamp

Hello Bassman2,

For my mobile device backup-tool, I am using your library, which works perfect. But when I upload a file to the mobile device using the UploadFile method, I noticed that for the last write time of the fileinfo, the timestamp on which the file was copied is used. If I copy the file directly (using the Windows Explorer), the timestamp of the creation-date from the source-file will be used. Since I am comparing these timestamps in order to create a differential backup, this issue is causing me some difficulties.

I am not sure if it is a bug or just limited by Win MTP. But is there a possibility to subsequently override the "last write time" of a file (simillar to the File.SetLastWriteTime method) on the mobile device?

Best regards,
Ben

Is it possible to download Files / Thumbnails async?

Hey Bassman,

I just want to know if it is possible to download the files from the mobile phone async?
Sorry I'm still new to github and also wanted to know if theres an another way to ask questions, since this one isn't really an Issue.

Thanks in advance
Daniel

Random InteropServices.COMException (0x80004005) while downloading file from MediaDevice

Hi Ralf,

We have successfully integrated this library in our application and it is working pretty well.

While testing this with various devices, sometimes we see COMException while getting downloading file from the device though the file path is valid.

System.Runtime.InteropServices.COMException (0x80004005): Error HRESULT E_FAIL has been returned from a call to a COM component. at MediaDevices.Internal.IPortableDeviceResources.GetStream(String pszObjectID, PropertyKey& key, UInt32 dwMode, UInt32& pdwOptimalBufferSize, IStream& ppStream) at MediaDevices.Internal.Item.OpenRead() at MediaDevices.MediaDevice.DownloadFile(String path, Stream stream) at MTPDevice.<ImportData>d__a.MoveNext()

We are wondering if you have seen this issue at some point or if there is some workaround or fix.
Any help is welcomed!

Thanks & Regards
Pallavi Garg

Application freezes after deleting files from device

Library version: 1.8.0.0 (from Nuget, but tried building the latest version from sources too)
Operating system: Windows 7/10
.NET Framework: 4.5

Made the minimum number of operations:

  • Getting connected devices
  • Connection to device
  • Subscription to device events
  • Display a list of files from the folder I need on the device
  • Deleting each of these files

After the last step, the application completely freezes until I unplug the device (tried different phones, the behaviour is the same). Moreover, if I try to open Explorer, it will freeze too. If there are a lot of files, then the program manages to delete some of them.

Because of what it can be and is it possible to fix it somehow?

Thank you!

Incorrect Device Description

Platform .NET Framework 4.5.2 / 4.6.1, C#, WinForms
Issue:

  • Start application with no device connected.
  • Call MediaDevice.GetDevices();
  • Connect an Android Device.
  • Call MediaDevice.GetDevices(). Description returned for connected device appear to be corrupted, only first character is correct.

If application start with device connected, no issue.

Error when run on x64 CPU

Hi, thank you for spend time to make this great project.
I got error about InteropServices.COMException when run on x64 CPU,
after call MediaDevice.Connect(), I cannot get info about SerialNumber, it throw exception.
Could you help me ?
Tks so much !

NotImplementedException in .NetCore 3.1

Hey,

I am working on a program to manage pictures on a mobile device. So far everything works fine and I love this NuGet. But I noticed that in .NetCore 3.1 the functions "DownloadFile" and "DownloadFileFromPersistentUniqueId" get a "NotImplementedException". I have already seen that enantiomer2000 started an issue for this, but it was not answered / fixed.
So please could you take a look at it.
Thanks in advance.
-Daniel

Is MediaDevice.GetDevices thread safe

I has two device, when I call MediaDevice.GetDevices in a task the second device will become null. If I call in the same thread context MediaDevice.GetDevices return value is normal.

Test code:

    private static readonly object _lock_pad = new object();

    private void Test()
    {
        // second device is null
        var devices = MediaDevice.GetDevices();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        Task.Run(() =>
        {
            lock (_lock_pad)
            {
                for (var i = 0; i < 5; i++)
                {
                    Test();
                }
            }
        });
        
        lock (_lock_pad)
        {
            for (var i = 0; i < 10; i++)
            {
               // when click alwarys normal return value
                var devices = MediaDevice.GetDevices();                    
            }
        }
    }

It alse throw exception int Output window says:

System.Runtime.InteropServices.COMException (0x800706F4): 向占位程序传送了空的索引指针。 (异常来自 HRESULT:0x800706F4)
在 MediaDevices.Internal.IPortableDeviceManager.GetDeviceDescription(String pszPnPDeviceID, StringBuilder pDeviceDescription, UInt32& pcchDeviceDescription)
在 MediaDevices.MediaDevice..ctor(String deviceId)
System.Runtime.InteropServices.COMException (0x800706F4): 向占位程序传送了空的索引指针。 (异常来自 HRESULT:0x800706F4)
在 MediaDevices.Internal.IPortableDeviceManager.GetDeviceFriendlyName(String pszPnPDeviceID, StringBuilder pDeviceFriendlyName, UInt32& pcchDeviceFriendlyName)
在 MediaDevices.MediaDevice..ctor(String deviceId)
System.Runtime.InteropServices.COMException (0x800706F4): 向占位程序传送了空的索引指针。 (异常来自 HRESULT:0x800706F4)
在 MediaDevices.Internal.IPortableDeviceManager.GetDeviceManufacturer(String pszPnPDeviceID, StringBuilder pDeviceManufacturer, UInt32& pcchDeviceManufacturer)
在 MediaDevices.MediaDevice..ctor(String deviceId)

'向占位程序传送了空的索引指针' may translate as 'a null reference pointer was passed to the stub'

.Net Framework 4.7.2
MediaDevices 1.8.0
Thanks!

Memory leak introduced in 1.5

There seems to be a memory leak somewhere in file retrieval.

using System;
using System.Linq;
using MediaDevices;

namespace MediaDevicesLeakRepro {
    class Program {
        static void Main(string[] args) {
            foreach (var device in MediaDevice.GetDevices()) {
                device.Connect();
                while (true) {
                    device.EnumerateFileSystemEntries("/").First();
                    GC.Collect(100, GCCollectionMode.Forced, true, false);
                    GC.WaitForPendingFinalizers();
                }
            }
        }
    }
}

When device is attached and has a drive, this code will leak unmanaged memory, in all version from 1.7 to 1.5. In 1.4 this no longer happens.

GC is there just to confirm that there really is a leak and it isn't just a lazy GC.

I suspect that this causes serious problems during certain file operations, especially when the device itself adds/removes/changes files at the same time, but this is currently only a hunch. This leak caused my application to crash with out of memory error, after leaving it running for a while.

It could be somehow related to #13, but that is just a speculation.

Slow performance when using UploadFile with MemoryStream

Hello,
I have noticed that using a MemoryStream with UploadFile is about 10 times slower than using a filestream. In below example I am copying 500 5MB files to an MTP device either with a FileStream or with a MemoryStream. Note that the FileStream is converted to the MemoryStream in both cases so the conversion time does not matter.

            var devices = MediaDevice.GetDevices();

            if (devices.Count() > 0)
            {
                var device = devices.First();
                device.Connect();

                var stopwatch = new System.Diagnostics.Stopwatch();
                stopwatch.Start();
                foreach (var file in Directory.GetFiles(@"C:\TestFiles"))
                {
                    string filename = Path.GetFileName(file);
                    Console.WriteLine(filename);
                    MemoryStream ms = new MemoryStream();
                    FileStream fs = File.OpenRead(file);
                    fs.CopyTo(ms);
                    ms.Position = 0;
                    fs.Position = 0;
                    //uncomment one to test
                    //device.UploadFile(ms, Path.Combine(@"Internal shared storage\TestFiles", filename));
                    //device.UploadFile(fs, Path.Combine(@"Internal shared storage\TestFiles", filename));
                    ms.Close();
                    fs.Close();
                }
                stopwatch.Stop();
                Console.WriteLine(stopwatch.Elapsed);
            }

For my usecase I need to use memory streams is there a possible workaround?

Access Violation Exception (0xc0000005) | Updated

Hi,

We are using MediaDevices to iterate over any usb device connection via usb port. Please refer to below log from Event Viewer. We use ManagementEventWatcher to detect device attachment.

Application was running and this fatal issue happened just after connecting device with system. This is not very frequent issue, so won’t be able to provide more details.
If someone has fixed or handled this issue, please let us know. Any help would be much appreciated!

Log-
Faulting application name: DummyName.exe, version: 1.1.2.54, time stamp: 0x5dd3fe20
Faulting module name: PresentationCore.ni.dll, version: 4.8.4018.0, time stamp: 0x5d4a6c7c
Exception code: 0xc0000005
Fault offset: 0x0067876d
Faulting process id: 0x3050
Faulting application start time: 0x01d5a3a6a32299f8
Faulting application path: C:\Program Files (x86)\DummyName.exe
Faulting module path: C:\WINDOWS\assembly\NativeImages_v4.0.30319_32\PresentationCore\431135a1fa749be763773e77963c87b4\PresentationCore.ni.dll
Report Id: 8cffc963-5e5f-4fca-adbf-f2dc3244f83c

Thanks
Pallavi Garg

How to distinguish between phone or USB or tab connected on USB port

Hi,

I need to filter out only mobile devices ie, android phones connected on USB port. I tried using MediaDevice.DeviceType, but it does not give "DeviceType.Phone" value.
For onePlus, pen drive it gave - DeviceType.Generic
For Samsung phone it gave - DeviceType.MediaPlayer

Is there any way to actually filter these devices?

Best
Pallavi

image thumbnail

could someone tell me how to download a thumbnail of a image?

i want to download the thumbnail not the image first;

Device cannot connect again

Describe the bug
Device cannot EnumerateFiles when reconnected. It gives exception "System.Runtime.InteropServices.COMException (0x802A0002): Shutdown was already called on this object or the object that owns it. (Exception from HRESULT: 0x802A0002)"

To Reproduce

  1. Connect device "device.connect();"
  2. EnumerateFiles
  3. Device removed from PC
  4. Device reconnected to PC
  5. Repeat through step 1. and you will get exception on point 2.

Expected behavior
It should connect and enumerate files or any other operation.

Device
Any MTP device

Version:
1.9.1

Additional context
Add any other context about the problem here.

Checksum

I would like to be able to Checksum a given file in a given location. Can this be part of the MediaFileInfo class? I tried to implement this but I was not successful.

Reusing the same MemoryStream object for UploadFile throws COMException with HRESULT 0x800704C7

Problematic scenario:

  1. Create a byte[] array of fixed length and populate it with some pattern
  2. Create a MemoryStream object with that byte[] array as a backing buffer
  3. Invoke MediaDevice.UploadFile multiple times using the same MemoryStream object (but diffferent destination file name)

Result: Every invocation after the first throws COMException with HRESULT 0x800704C7.

No-problem scenario:

  1. Create a byte[] array of fixed length and populate it with some pattern
  2. Invoke MediaDevice.UploadFile multiple times using the new MemoryStream object each time, but backed by the very same byte[] array.

Result: Everything works fine.

I use the second scenario as a workaround, but there might be some COM object marshaling problems in the library (I'm not familiar with COM interop).

Tested with MediaDevices 1.9.1, .NET 4.7.2, x86 profile, Windows 10 21H2 and Samsung Galaxy J5.

Fast Thumbnails Loading

Hi there!
Before I ask, the effort spent on that library is incredible, I respect it a lot.

I'm creating a photo explorer for MTP devices. The explorer must show image thumbnails as fast as possible. Currently I'm facing the biggest problem with performance. I'm trying to load images in explorer as fast as possible, but min time to get usable files tream is 70ms - 140ms. You can imagine that when loading e.g. 25 images it takes about 2.5s. It is a lot, when you have thousands of pictures on mobile phone, and you want to browse images. My target would be Windows Explorer loading performance. I cannot get, how they did it?

I wonder if this delay is because of .NET wrapper? C++ solutions are much faster, e.g. I saw pictures browser written in Qt where thumbnail were loaded as fast as in win. explorer.

I was checking you code, I see some small improvements, to skip some wrapping code of getting children objects without wrapping them up in Item etc. But I doubt it will help...

Did you have maybe similar situation, or have you some ideas how to load thumbnails of images AFAP?

Any help is welcome!

PS: You can close this issue if it breaks you issue statistics... It is not a bug or problem. Just another use case.

All best,
Paul

Requested resource is in use

OS Win 7 x64
.Net Framework 4.5.1
MediaDevices 1.9.0 (from github)

I use 1.8.0 from Nuget first and that worked well till I hit a road block in using the function
OpenReadFromPersistentUniqueId()

Now I'm using 1.9.0, with worked will for an hour or so, and then i'm getting this exception.

image

I can manually access images and videos on the Camera via windows explorer.
I tried restarted the computer, however that didn't change anything.

Don't work with Unity - NullReferenceException

I need to retrieve the path to my phone from the computer to copy/paste backup files to it.
After adding the nuget package to unity, it can't find my devices.
So I have this error:

NullReferenceException: Object reference not set to an instance of an object
MediaDevices.MediaDevice.GetDevices () (at <016781043aa441d5b0169b9d5116ee77>:0)
ManageSaves.CopySaveFromDevice () (at Assets/Scripts/ManageSaves.cs:65)
ManageSaves.Testing () (at Assets/Scripts/ManageSaves.cs:57)
MainMenu.Testing () (at Assets/Scripts/MainMenu.cs:69)
UnityEngine.Events.InvokableCall.Invoke () (at <23a7799da2e941b88c6db790c607d655>:0)
UnityEngine.Events.UnityEvent.Invoke () (at <23a7799da2e941b88c6db790c607d655>:0)
UnityEngine.UI.Button.Press () (at C:/Program Files/Unity/Hub/Editor/2019.3.14f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/Button.cs:68)
UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at C:/Program Files/Unity/Hub/Editor/2019.3.14f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/Button.cs:110)
UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at C:/Program Files/Unity/Hub/Editor/2019.3.14f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/ExecuteEvents.cs:50)
UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) (at C:/Program Files/Unity/Hub/Editor/2019.3.14f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/ExecuteEvents.cs:261)
UnityEngine.EventSystems.EventSystem:Update() (at C:/Program Files/Unity/Hub/Editor/2019.3.14f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/EventSystem.cs:377)

A possible solution... that you know ?

Not an issue but rather a thank you

I published a console app using your library which helps back up contents of a media device (iPhone) to another storage repository. Anyone that wants to use it as reference or as a baseline for their own app, please feel free to do so. https://github.com/jchristn/PhotoSync

Thank you so much for producing this outstanding library!

Restored using .NET Framework 4.6.1 instead of .NET Core 2.2

Hi!

Thank You for this great library!

I would like to use the NuGet package (1.8.0) in a .NET Core 2.2 application but i get this warning:

D:\GitHub\---\---.csproj : warning NU1701: Package 'MediaDevices 1.8.0' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.2'. This package may not be fully compatible with your project.

I am not really familiar with multi-targeting but could this be fixed with that so NuGet could automatically restore as a .NET Core 2.1 library instead of a .NET Framework 4.6.1?

I added this repository as a submodule to temporary fix this warning.

Stream Length property not implemented

Hi

Os Win 7
.Net Framework 4.5.1
Media Devices DLL Version 1.8.0 (Downloaded from NuGet)

I'm trying to copy a large video file from a DSLR camera, and at the same time show a progress bar in WinForms, C#.
I try to use this method

using (Stream srcStream = device.OpenReadFromPersistentUniqueId(mediainfo.PersistentUniqueId)) {
}

However when I try to access the "Length" property of the Stream it throws an exception saying "Not Implemented"

Is this by design?

I can see other methods in the Documentation like DownloadFile, however they read the whole file into the stream and I don't have control to show a progress bar.

I see that "OpenReadFromPersistentUniqueId" is the most suitable since it returns a Stream to the underlying file.

Am I missing something here!
Thanks in advance.

Hello~Bassman2 :) How can I get some values?

Hello. I like your MTP Library.

But I can't get some value..

That is..

  1. Size of total Storage.
  2. Size of free Storage.

I was replace your some code, but there are not connected error..

If you can add this logic, I feel so good.

Thank you Bass man.

  1. public static PropertyKey WPD_STORAGE_CAPACITY = new PropertyKey(0x01A3057A, 0x74D6, 0x4E80, 0xBE, 0xA7, 0xDC, 0x4C, 0x21, 0x2C, 0xE5, 0x0A, 4);

  2. public static PropertyKey WPD_STORAGE_FREE_SPACE_IN_BYTES = new PropertyKey(0x01A3057A, 0x74D6, 0x4E80, 0xBE, 0xA7, 0xDC, 0x4C, 0x21, 0x2C, 0xE5, 0x0A, 5);

API hangs when accessing file path after FileDelete method.

Hi,
I'm using MediaDevices 1.8.0 on .NET 4.5, connected MTP devices are Android phones (tried Android 4.3, 7.0 and 9).
API hangs are discovered in the following situations, when trying to access a filepath after its file has been deleted:

Example 1:
MediaDevice.DeleteFile(filepath)
if MediaDevice.FileExists(filepath) then ...

The DeleteFile method will correctly delete the file on the device but the FileExists method will not produce a result nor an exception. Instead program execution goes into hang within the method.
Eventually the processing will continue after 3 minutes or so but typically nothing happens for at least 5 minutes.
Same behaviour has been observed when the UploadFile method is used after the DeleteFile.

Interestingly, renaming the file before delete will not help.
Example 2:
MediaDevice.RenameFile(filepath, newfilename)
MediaDevice.DeleteFile(newfilepath)
if MediaDevice.FileExists(filepath) then ...

RenameFile renames the file and DeleteFile also works as expected, but FileExists will hang in this situation again - both when used on filepath as well as on newfilepath.
Without the DeleteFile line, the FileExists method works fine after RenameFile (false on filepath and true on newfilepath).

Has this behaviour been recognized before?

Thanks and best regards
Kai

NotImplementedException on console in .NetCore 3.1 project

Describe the bug
I'm using the plugin to copy files from a connected USB camera to disk. Everything works great. But for each file I try to copy to the disk, I get a NotImplementedException printed on the console. The program is not interrupted and each file seems to be copied correctly. But I'm unsure if there are any further downsides?

Exception:
System.NotImplementedException: The method or operation is not implemented. at System.Runtime.InteropServices.ComTypes.IStream.Seek(Int64 dlibMove, Int32 dwOrigin, IntPtr plibNewPosition) at MediaDevices.Internal.StreamWrapper.Seek(Int64 offset, SeekOrigin origin)

To Reproduce
The following code snippet logs the exception on console:
Device.DownloadFile(filePathOld, filePathNew);

It also happens if I implement the streamwriter on my own.

Expected behavior
There shouldn't be an exception on the console.

Device
Microsoft Windows 10 21H1 64bit

Version:
MediaDevices 1.9.1 (NuGet package)

Additional context
IDE: Visual Studio Community 2019
Project: .NetCore 3.1
Target platform: win-x64

NuGet repo updates

Thanks for this awesome library 👍 . Really like to see the NuGet package repo gets updated with latest fixes and enhancements.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.