Search code examples
c#mediadetectplaybackalarm

Keeping a log file related to a media files usage


I would like detect and act when a spesific mp3 file is used(played as an alarm in another application) in c#.

Waiting for ideas, Thanks all.


Solution

  • Windows does not update the lastaccesstime when a file is opened for reading, so that cannot be used.

    There are two ways I can think of doing this, but both involving polling the system.

    1. Loop every X seconds and try to open the file for write. If this fails then the file is open.

    2. Loop every X seconds and use a WMI Query to see if the file is in use.

    Either way, you will then have to handle consecutive "opens" within a certain period of time count as only a single instance.