Error when reading audio file?

女生的网名这么多〃 提交于 2019-12-11 02:16:07

问题


I have the following function that I am attempting to use to determine the length of an MP3 file:

public static string GetMP3DurationBackup(string Filename)
{
    string Duration = null;
    WMPLib.WindowsMediaPlayer w = new WMPLib.WindowsMediaPlayer();
    WMPLib.IWMPMedia m = w.newMedia(Filename);
    if (m != null)
    {
        Duration = m.durationString;
    }
    w.close();
    return Duration;
}

I have run into an issue where I get the following error:

Retrieving the COM class factory for component with CLSID {6BF52A52-394A-11D3-B153-00C04F79FAA6} failed due to the following error: 80040154..

when I call the above function from my web application (call below):

string test = MediaUtil.GetMP3DurationBackup(@"C:\Temp\Audio\bad.mp3");

But when I call it from a console application test harness I created (exact same call as above) it works fine. I have set the project that contains the function to target x86 in the Build properties, but that did not fix the issue.

Does anyone know why this would happen? Suggestions on where to start to debug this?

UPDATED FOR BOUNTY:

Ok, I've tried a number of things but I am still getting this error. Among other things I have tried the steps below which I felt were the most promising, but no dice:

  1. Went into my registry and confirmed that the value at: HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{6BF52A52-394A-11d3-B153-00C04F79FAA6}\InprocServer32 is refering to C:\WINDOWS\SysWOW64\wmp.dll
  2. Opened command prompt, navigated to C:\WINDOWS\SysWow64, ran: regsvr32.exe wmp.dll

I have created a console app test harness and I am able to reproduce the error if I run the test project in x64. If I switch it to x86 it works fine.

Does anyone have any idea of why the above would not resolve the issue? Suggestions on where to look next?


回答1:


You say it doesn't work in x64, but you try to register the 32-bit version of wmp.dll (C:\Windows\SysWow64 contains 32-bit assemblies).

Try to register the x64 version of wmp.dll, which is located in C:\Windows\System32 on a 64-bit platform.

If you don't have this file then there probably is no 64bit Windows Media Player available for your platform. But there is a workaround:

Create a 32-bit console application that takes the mp3 filename as command line argument and outputs the duration to stdout using Console.WriteLine, then in the webapp, you call the console application and capture the output like in this example on MSDN




回答2:


Give this lib a whirl. Its fast and has no special requirements for software to be installed on the machine.

http://naudio.codeplex.com/



来源:https://stackoverflow.com/questions/16048877/error-when-reading-audio-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!