1

我正在尝试使用 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();
            }
        }
    }
}

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

4

1 回答 1

5

BASS.NET 是 BASS 的精简包装器,这意味着它bass.dll是必需的。您提供的链接明确警告:

本机 BASS 库不包括在内,需要单独下载 - 因此请确保将 BASS 库和所需的附加库放置到您的项目可执行目录中(例如,将 bass.dll 放置到您的 .\bin\Debug 文件夹中) .

您不需要自己复制bass.net.dll到该Debug文件夹​​,因为您已经将它添加为对项目的引用。

于 2014-10-07T07:17:27.080 回答