我正在尝试使用来自 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();
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我猜代码没问题,但我的计算机的输出设备是导致错误的原因。
BASS.NET 是对 BASS 的一个薄包装,这意味着它bass.dll是必需的。您提供的链接明确警告:
本机 BASS 库不包括在内,需要单独下载 - 因此请确保将 BASS 库和所需的附加库放在您的项目可执行目录中(例如,将 bass.dll 放在您的 .\bin\Debug 文件夹中) .
您不需要自己复制bass.net.dll到该Debug文件夹,因为您已经将其添加为对项目的引用。