“我的第一个BASS应用程序”BASS.NET应用程序错误

时间:2014-10-07 06:09:34

标签: c# bass

我正在尝试使用BASS.NET库中的音频创建一个应用程序,但是我在“我的第一个BASS应用程序”中遇到了一些错误。样品。我按照http://bass.radio42.com/help/上的给定说明进行操作,但是当我尝试运行粘贴的代码时,此行出现错误:

if ( Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero) )

我收到的错误是:

An unhandled exception of type 'System.TypeInitializationException' occurred in Bass Test.exe

我试图遵循所有指示,但对于#4,我没有添加bass.dll,而是添加了bass.net.dll,认为这是错误的。

4.Copy the 'bass.dll' to your executable directory (e.g. .\bin\Debug).

示例代码为:

using System;
using Un4seen.Bass;

namespace MyFirstBass
{
    class Program
    {
        static void Main(string[] args)
        {
            // init BASS using the default output device 
            if (Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero))
            {
                // create a stream channel from a file 
                int stream = Bass.BASS_StreamCreateFile("test.mp3", 0, 0, BASSFlag.BASS_DEFAULT);
                if (stream != 0)
                {
                    // play the stream channel 
                    Bass.BASS_ChannelPlay(stream, false);
                }
                else
                {
                    // error creating the stream 
                    Console.WriteLine("Stream error: {0}", Bass.BASS_ErrorGetCode());
                }

                // wait for a key 
                Console.WriteLine("Press any key to exit");
                Console.ReadKey(false);

                // free the stream 
                Bass.BASS_StreamFree(stream);
                // free BASS 
                Bass.BASS_Free();
            }
        }
    }
}

我猜测代码很好,但我的计算机的输出设备是什么导致错误。

1 个答案:

答案 0 :(得分:4)

BASS.NET是一个比BASS更薄的包装器,这意味着需要bass.dll。您提供的链接明确警告:

  

原生BASS库不包含在内,需要单独下载 - 因此请确保将BASS库和所需的附加库放在项目可执行目录中(例如将bass.dll放到。\ bin \调试文件夹)。

您无需自己将bass.net.dll复制到Debug文件夹,因为您已将其添加为项目的参考。