在.mvc 4中将.caf转换为.mp3时出错 [英] error converting .caf to .mp3 in mvc 4
问题描述
当我使用asp.net时,我曾经使用Wscript.shell和ffmpeg.exe将caf转换为mp3但现在我在mvc 4中使用了web api restful方法,所以我没有.aspx页面我收到以下错误:
描述:System.Web.HttpException(0x80004005):无法创建组件'Wscript.Shell'。公寓线程组件只能在<%@ Page aspcompat = true%>的页面上创建。页面指令。
但我没有aspx页面来添加这个标签...
我在aspx中使用的代码是:
Dim wshShell 作为 对象
wshShell = Server.CreateObject( Wscript.Shell)
cmd = cmd.exe / k & szCAF_PATH& -i& szPhysicalPath& &参数& & szEncodedPath&
wshShell.Run(cmd)
Dim strCommand As String = taskkill / F / IM cmd.exe
wshShell.Run(strCommand,< span class =code-digit> 0 , True )
szDownloadLink = szDownloadLink.Replace( .caf, 。 mp3)
和mvc4中的代码是:
< pre lang =vb> wshShell = HttpContext.Current.Server.CreateObject( Wscript.Shell )
cmd = cmd.exe / k & File.CAF_PATH& -i& File.PhysicalPath& & File.Arguments& & File.EncodedPath&
wshShell.Run(文件。 cmd)
strCommand = taskkill / F / IM cmd.exe
wshShell.Run(strCommand, 0 , True )
File.DownloadLink = File.DownloadLink。替换( .caf, .mp3)
有谁知道我该如何解决这个问题?
请参阅我对该问题的评论。我很震惊。您可以执行以下操作:
使用 System.Diagnostics;
// ...
< span class =code-keyword> string path // ffmpeg.exe的路径,使用MapPath。 ..
string commandLine // ffmpeg的命令行参数; use string.Format(... {0} {1},inputFileName,outputFileName)
Process convertor = Process.Start(path,commandLine);
convertor.WaitForExit();
// 此时,您可以使用outputFileName
请参阅: http://msdn.microsoft.com/ en-us / library / vstudio / system.diagnostics.process [ ^ ]。
-SA
I used to convert caf to mp3 using Wscript.shell and ffmpeg.exe when i was using asp.net but now i'm using a web api restful method in mvc 4, so i don't have a .aspx page i'm getting the following error:
Description:System.Web.HttpException (0x80004005): The component 'Wscript.Shell' cannot be created. Apartment threaded components can only be created on pages with an <%@ Page aspcompat=true %> page directive.
but i don't have an aspx page to add this tag...
the code i was using in aspx is:
Dim wshShell As Object
wshShell = Server.CreateObject("Wscript.Shell")
cmd = "cmd.exe /k """"" & szCAF_PATH & """ -i """ & szPhysicalPath & """ " & Arguments & " """ & szEncodedPath & """"""
wshShell.Run(cmd)
Dim strCommand As String = "taskkill /F /IM cmd.exe"
wshShell.Run(strCommand, 0, True)
szDownloadLink = szDownloadLink.Replace(".caf", ".mp3")
and the code in mvc4 is :
wshShell = HttpContext.Current.Server.CreateObject("Wscript.Shell")
cmd = "cmd.exe /k """"" & File.CAF_PATH & """ -i """ & File.PhysicalPath & """ " & File.Arguments & " """ & File.EncodedPath & """"""
wshShell.Run(File.cmd)
strCommand = "taskkill /F /IM cmd.exe"
wshShell.Run(strCommand, 0, True)
File.DownloadLink = File.DownloadLink.Replace(".caf", ".mp3")
does anyone know how can i fix this?
Please see my comments to the question. I am shocked. Here is what you can do:
using System.Diagnostics; //... string path // path to ffmpeg.exe, use MapPath... string commandLine // command line parameterts for ffmpeg; use string.Format("... {0} {1}", inputFileName, outputFileName) Process convertor = Process.Start(path, commandLine); convertor.WaitForExit(); // at this point, you can use outputFileName
Please see: http://msdn.microsoft.com/en-us/library/vstudio/system.diagnostics.process[^].
—SA
这篇关于在.mvc 4中将.caf转换为.mp3时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!