Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use LAME (lame_enc.dll) in my C# web site

Tags:

c#

.net

lame

I am trying to use the lame_enc.dll in my C# .NET website and I am stuck.

I am working with: .NET Framework 3.5 / Visual Web Developer 2008 Express Edition / (Anything else you'd need to know?)

The first thing I did was get the code from C# MP3 Compressor on The Code Project. One thing I noted is that this project/post is from January 2004 (so, it's old)

I put the folders "yeti.mmedia" and "yeti.mp3" in my "App_Code" directory and deleted the "Bin" and "obj" directories within each. Then I tried to build the project. When I got errors I ended up excluding from the project the following files:

  • yeti.mmedia/AssemblyInfo.cs
  • yeti.mmedia/EditWaveWriter.cs
  • yeti.mmedia/EditWaveWriter.resx
  • yeti.mmedia/InFormatEdit.cs
  • yeti.mmedia/InFormatEdit.resx
  • yeti.mmedia/NumericTextBox.cs
  • yeti.mmedia/NumericTextBox.resx
  • yeti.mmedia/Win32Functions.cs
  • yeti.mp3/AssemblyInfo.cs
  • yeti.mp3/EditMp3Writer.cs
  • yeti.mp3/EditMp3Writer.resx

These seem to me to be the code files related to the Windows UI (which I don't need sonce I'm doing this on the web).

I also put the file "lame_enc.dll" in the Bin directory.

I created a test page based on the example on the page linked above:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using WaveLib;
using Yeti.MMedia;
using Yeti.MMedia.Mp3;

public partial class Documents : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        WaveStream InStr = new WaveStream(Server.MapPath(@"Temp/SomeFile.wav"));
        try {
            Mp3Writer writer = new Mp3Writer(new FileStream(Server.MapPath(@"Temp/SomeFile.mp3"), FileMode.Create), InStr.Format);
            try {
                byte[] buff = new byte[writer.OptimalBufferSize];
                int read = 0;
                while ((read = InStr.Read(buff, 0, buff.Length)) > 0) {
                    writer.Write(buff, 0, read);
                }
            }
            finally {
                writer.Close();
            }
        }
        finally {
            InStr.Close();
        }
    }
}

So, then I load this page and the error I get is:

Unable to load DLL 'Lame_enc.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

(I can't add the DLL as a reference in my project because it says "...This is not a COM component.") I have also tried getting the latest and greatest (lame3.98.4) dll and had the same problems. So, I assume there is something different about using this code in a website rather than another type of project. What it is I don't know though.

like image 994
Hewins Avatar asked Nov 13 '22 22:11

Hewins


1 Answers

My guess, having not used LAME, is you have to install in on the box in question. After that, you should be able to use the code project code successfully. If that does not work, it appears Lame_Enc.dll is a native component and you will have to PInvoke methods.

like image 80
Gregory A Beamer Avatar answered Dec 15 '22 01:12

Gregory A Beamer