[英]MediaInfo not able to get details of uploaded file in the same manner it can when pointed to local file
我一直在嘗試獲取使用MediaInfo.dll(已添加到應用程序作為參考)上傳到MVC4應用程序的一段視頻內容的durationstring。
使用以下代碼在本地輸入文件的位置時,我能夠成功查看文件的詳細信息:
MediaFile uploadedFile = new MediaFile("C:\\Users\\jp\\Desktop\\Quarry.mp4");
string duration = uploadedFile.General.DurationString.ToString();
但是,當我嘗試在上傳的文件上使用此功能時,我沒有得到我所期望的信息。 我的控制器如下:
[HttpPost, ValidateInput(true)]
public ActionResult NewContent(HttpPostedFileBase postedFile, string username, FormCollection form)
{
if (postedFile != null)
{
HttpPostedFileBase postedFileCopy = postedFile;
postedFileCopy.InputStream.Position = 0;
Stream stream = postedFile.InputStream;
MediaFile uploadedFile = new MediaFile(Server.MapPath(postedFile.FileName));
string duration = uploadedFile2.General.DurationString.ToString();
string[] name = form.GetValues("name");
string[] author = form.GetValues("author");
string[] description = form.GetValues("description");
TimeSpan videoDuration = TimeSpan.Parse(duration);
try
{
avm.AddContent(postedFile, stream, Convert.ToString(name[0]), Convert.ToString(author[0]), Convert.ToString(description[0]), videoDuration);
return RedirectToAction("Contents", "Admin");
}
catch (Exception ex)
{
System.Diagnostics.EventLog.WriteEntry("Application", ex.Message, System.Diagnostics.EventLogEntryType.Error);
return RedirectToAction("Unsuccessful", "Admin");
}
}
else
return RedirectToAction("NewCourse", "Admin");
}
我努力了:
MediaFile uploadedFile = new MediaFile(Server.MapPath(postedFile.FileName));
MediaFile uploadedFile = new MediaFile(postedFile.FileName);
MediaFile uploadedFile = new MediaFile(postedFile.toString());
MediaFile uploadedFile = new MediaFile(System.IO.Path.GetFullPath(postedFile.FileName);
關於如何讓MediaInfo以能夠讀取本地文件的相同方式來識別postedFile的任何想法。 或如何檢索客戶端計算機文件位置的路徑。
您有一種方法可以使用流而不是文件來解析文件。
查看以下方法:
Open_Buffer_Init(..)
Open_Buffer_Continue(..)
Open_Buffer_Continue_GoTo_Get(..)
Open_Buffer_Init(..)
我花了一段時間才弄清楚如何獲取緩沖區的IntPtr。.請記住使用GCHandle和AddrOfPinnedObject
如果您需要更多幫助,我的示例到處都是,我將嘗試使我的代碼再次正常工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.