Im trying to make my own C# mp3 playingf library I am using mci, but dont like it - it is bad quality. I dont like using the windows media player or directx stuff either, because they are also bad quality when it works, and you need more stuff installed to run them.
So I look around for open source mp3 playing libraries and the best one out there seems to be mpg123. They have a win32 library call mpglib.dll which plays very well. Unfortunately, its in C, and Im using C#. C# can call functions in C though, so I think it is quite possible. I also have a sample C program that uses the library and it works well.
The C example is at http://www.inet.hr/~zcindori/download/rawmp3_source_dll_version.zip
mpglib.dll is at
http://www.rz.uni-frankfurt.de/~pesch/mpglibdll.zip
or
http://www.lancs.ac.uk/postgrad/ramdhany/code/mp3lib/mpglibdll.zip
Here is my problem and code:
using System;
using System.Runtime.InteropServices;
namespace csmpglibtest
{
/// <summary>
/// Summary description for csMpgLib.
/// </summary>
public class csMpgLib
{
[StructLayout(LayoutKind.Sequential)]
private struct mpstr
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst=40000)]
private char[] c;
}
[DllImport("mpglib.dll", EntryPoint="_InitMP3", CharSet=CharSet.Ansi)]
private static extern bool InitMp3(mpstr mp);
[DllImport("mpglib.dll", EntryPoint="_ExitMP3", CharSet=CharSet.Ansi)]
private static extern void ExitMp3(mpstr mp);
[DllImport("mpglib.dll", EntryPoint="_decodeMp3", CharSet=CharSet.Ansi)]
private static extern int DecodeMp3(mpstr mp, char[] inmemory, int inmemsize, char[] outmemory, int outmemsize, out int done);
public csMpgLib()
{
//
// TODO: Add constructor logic here
//
}
public void Test()
{
mpstr something = new mpstr();
InitMp3(something);
//ExitMp3(something);
}
}
}
the error I get when running is:
An unhandled exception of type System.NullReferenceException occurred in csmpglibtest.exe
Additional information: Object reference not set to an instance of an object.
and the line it yellows is InitMp3(something);
what am I doing wrong? are my functions modified incorrectly? do I need to do something to the class before InitMp3?
I think this is a good project because there are really no good C# mp3 playing libraries out there.
Thanks all,
So I look around for open source mp3 playing libraries and the best one out there seems to be mpg123. They have a win32 library call mpglib.dll which plays very well. Unfortunately, its in C, and Im using C#. C# can call functions in C though, so I think it is quite possible. I also have a sample C program that uses the library and it works well.
The C example is at http://www.inet.hr/~zcindori/download/rawmp3_source_dll_version.zip
mpglib.dll is at
http://www.rz.uni-frankfurt.de/~pesch/mpglibdll.zip
or
http://www.lancs.ac.uk/postgrad/ramdhany/code/mp3lib/mpglibdll.zip
Here is my problem and code:
using System;
using System.Runtime.InteropServices;
namespace csmpglibtest
{
/// <summary>
/// Summary description for csMpgLib.
/// </summary>
public class csMpgLib
{
[StructLayout(LayoutKind.Sequential)]
private struct mpstr
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst=40000)]
private char[] c;
}
[DllImport("mpglib.dll", EntryPoint="_InitMP3", CharSet=CharSet.Ansi)]
private static extern bool InitMp3(mpstr mp);
[DllImport("mpglib.dll", EntryPoint="_ExitMP3", CharSet=CharSet.Ansi)]
private static extern void ExitMp3(mpstr mp);
[DllImport("mpglib.dll", EntryPoint="_decodeMp3", CharSet=CharSet.Ansi)]
private static extern int DecodeMp3(mpstr mp, char[] inmemory, int inmemsize, char[] outmemory, int outmemsize, out int done);
public csMpgLib()
{
//
// TODO: Add constructor logic here
//
}
public void Test()
{
mpstr something = new mpstr();
InitMp3(something);
//ExitMp3(something);
}
}
}
the error I get when running is:
An unhandled exception of type System.NullReferenceException occurred in csmpglibtest.exe
Additional information: Object reference not set to an instance of an object.
and the line it yellows is InitMp3(something);
what am I doing wrong? are my functions modified incorrectly? do I need to do something to the class before InitMp3?
I think this is a good project because there are really no good C# mp3 playing libraries out there.
Thanks all,