FIleSystemWatcher 对媒体文件的上次访问(读取)不起作用

发布于 2025-01-04 18:33:00 字数 1363 浏览 3 评论 0原文

我正在将媒体内容传送到客户端系统(从互联网下载),并想确认媒体文件是否已被操作员打开(和查看)。 我正在使用文件系统观察程序(C# 3.5)来检查文件的上次访问时间(因此每当播放媒体文件时我都应该收到该事件)并发送确认。

我已在 Windows 7 计算机的注册表中启用了上次访问时间 此处并重新启动了我的系统。文件系统观察器在打开的目录上触发事件,但不在媒体播放时触发事件。

这是我的代码:

private FileSystemWatcher fsWatcher = null;
private static Object objLock = new Object();

private void StartAccessWatcher(string _folderPath)
{
  fsWatcher = new FileSystemWatcher(_folderPath, "*.*");
  fsWatcher.Changed += new FileSystemEventHandler(fsWatcher_Changed);
  fsWatcher.IncludeSubdirectories = true;
  fsWatcher.NotifyFilter = NotifyFilters.LastAccess;
  fsWatcher.EnableRaisingEvents = true;
}

private void fsWatcher_Changed(object sender, FileSystemEventArgs e)
{
  lock (objLock)
  {
    fsWatcher.EnableRaisingEvents = false;
    DisplayMessage(string.Concat(e.ChangeType, "  ", e.FullPath));
    fsWatcher.EnableRaisingEvents = true;
  }
}

private void btn_StartWatcher_Click(object sender, EventArgs e)
{
  StartAccessWatcher(@"E:\Surewaves\Media-Store\MP1 Videos");
}

您还可以从此处下载我的代码示例。

请告诉我怎样才能最好地实现它?我需要获取最后一次访问时间(任何播放器播放视频、音频、图像或 .swf 文件时)?

I am delivering media contents to a client system (download from internet) and want to acknowledge if the media file was opened (and viewed) by the operator.
I am using a file system watcher (C# 3.5) to check for the last access time of file (so whenever the media file is played I should get the event) and I send an acknowledgement.

I have enabled the last access time in registry of my Windows 7 machine here and rebooted my system. File system watcher fires events on directory opened but not on media play.

Here is my code :

private FileSystemWatcher fsWatcher = null;
private static Object objLock = new Object();

private void StartAccessWatcher(string _folderPath)
{
  fsWatcher = new FileSystemWatcher(_folderPath, "*.*");
  fsWatcher.Changed += new FileSystemEventHandler(fsWatcher_Changed);
  fsWatcher.IncludeSubdirectories = true;
  fsWatcher.NotifyFilter = NotifyFilters.LastAccess;
  fsWatcher.EnableRaisingEvents = true;
}

private void fsWatcher_Changed(object sender, FileSystemEventArgs e)
{
  lock (objLock)
  {
    fsWatcher.EnableRaisingEvents = false;
    DisplayMessage(string.Concat(e.ChangeType, "  ", e.FullPath));
    fsWatcher.EnableRaisingEvents = true;
  }
}

private void btn_StartWatcher_Click(object sender, EventArgs e)
{
  StartAccessWatcher(@"E:\Surewaves\Media-Store\MP1 Videos");
}

You may also download my code sample from here.

Please tell me how best can I achieve it ? I need to get the the last access time (when ever the video or audio or image or .swf file was played by any player) ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

如果没结果 2025-01-11 18:33:00

作为对这个三年前问题的更新,给出的代码现在可以正常工作*,可以在本地计算机上播放视频。

计算机必须使用

fsutil behavior set DisableLastAccess 0

问题中所述的以下命令成功启用lastAccess。


*- 在撰写本文时,使用 Windows Server 2012 R2

As an update to this three year old question, the code given works correctly now* with videos played on the local machine.

The machine must have lastAccess successfully enabled with the following command

fsutil behavior set DisableLastAccess 0

as noted in the question.


*- at the time of this post, using Windows Server 2012 R2

痴情换悲伤 2025-01-11 18:33:00

FileSystemWatcher 用于监视指定目录中的更改。您可以监视指定目录的文件和子目录的变化。在您的情况下,媒体文件没有发生任何更改。我建议尝试扩展 FileSystemWatcher 类并为媒体文件读取创建新事件,然后触发这些事件。

The FileSystemWatcher is used to watch for changes in a specified directory. You can watch for changes in files and subdirectories of the specified directory. In your case there is no change being made on media files. I would suggest try extending FileSystemWatcher class and create new events for media file reading and then fire those events.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文