2014-10-07 70 views
0

我正尝试使用BASS.NET库中的音频创建应用程序,但我在“我的第一个BASS应用程序”示例中收到了一些错误。我也跟着上http://bass.radio42.com/help/给定的方向,但是当我尝试运行粘贴代码,错误出现在这条线:“我的第一个BASS应用程序”BASS.NET应用程序错误

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(); 
      } 
     } 
    } 
} 

我猜测的代码是不错,但我的电脑的输出设备是什么导致错误。

+0

您是否尝试调试应用程序?错误发生在哪里?例外说.NET不能创建一个类型,可能是因为它找不到所有需要的dll。如果'bass.net.dll'只是'bass.dll'的一个包装文件,那么你的程序就需要两个DLL来工作 – 2014-10-07 07:04:15

回答

3

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

本机BASS库不包含,需要单独下载 - 所以一定要放置BASS库和需要的附加库到您的项目可执行目录(例如地方将bass.dll添加到。\ bin \ Debug文件夹中)。

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

+0

谢谢,我应该真的阅读手册而不是跳到示例。 – 2014-10-07 18:12:37

相关问题