【问题标题】:Retrieveing video/audio duration using WindowsAPICodecPack and Shell使用 WindowsAPICodePack 和 Shell 检索视频/音频持续时间
【发布时间】:2013-09-16 15:51:25
【问题描述】:

我有以下代码来检索上传视频的时长:

HttpPostedFileBase postedFileCopy = postedFile;
postedFileCopy.InputStream.Position = 0;
Stream stream = postedFile.InputStream;

LocalResource tempDirectory = RoleEnvironment.GetLocalResource("TempZipDirectory");
postedFile.SaveAs(tempDirectory.RootPath + @"\" + postedFile.FileName);

ShellFile so = ShellFile.FromFilePath(tempDirectory.RootPath + @"\" + postedFile.FileName);
string durationString;
double nanoseconds;                
double.TryParse(so.Properties.System.Media.Duration.Value.ToString(),out nanoseconds);

if (nanoseconds > 0)
{
  int totalSeconds = (int)Math.Round((nanoseconds / 10000000), 0);
  int seconds = totalSeconds % 60;
  int minutes = totalSeconds / 60;
  int hour = totalSeconds / (60 * 60);
  durationString = "" + hour + ":" + minutes + ":" + seconds;
}
else
{
  System.Diagnostics.EventLog.WriteEntry("Application", "BLANK DURATION STRING", System.Diagnostics.EventLogEntryType.Error);
  durationString = "00:00:00";
}

这在 localhost 上按预期工作,但是当放到 Azure 存储中时,它似乎无法检索文件的详细信息。

postedFile.SaveAs(tempDirectory.RootPath + @"\" + postedFile.FileName);

将上传保存到目录,以便我可以获取这些详细信息,但无论我尝试什么,当存储在天蓝色时,我似乎都无法返回纳秒。这是一个已部署的 MVC 应用程序,临时目录存储在服务器的 C:/ 驱动器上。

【问题讨论】:

    标签: azure fileinfo httppostedfilebase windows-api-code-pack


    【解决方案1】:

    您引用的代码使用本机(Shell)函数。由于 AzureWebSites 作为高密度共享环境运行,因此您的代码会进入非完全信任模式。在 Azure 网站中,对本机函数的调用受到限制,即使您扩展到保留模式实例也是如此。

    更新

    让应用程序在 FULL TRUST 下执行的唯一方法是使用 Web Role(用于 Web 项目)或 Worker Role(用于后台任务)。

    阅读更多关于cloud services here的信息。

    【讨论】:

    • 您是否有任何解决方法可以让我在 Azure 上使用它,或者是否应该排除作为解决方案的问题?我已经部署了 WindowsAPICodepack dll 和 shell,它们不应该以完全信任的方式与应用程序一起运行吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-08
    • 2020-12-11
    • 1970-01-01
    • 1970-01-01
    • 2015-05-29
    • 2015-02-08
    相关资源
    最近更新 更多