static WavHelper() { //默认加载插件 LoadPlugins(NativeMethods.DllDir); //默认初始化 int device = 0; BASS_DEVICEINFO_INTERNAL info = new BASS_DEVICEINFO_INTERNAL(); for (int i = 0; ; i++) { if (!GetDeviceInfo(i, ref info)) { break; } if (info.driver != IntPtr.Zero && info.flags == (BASSDeviceInfo.BASS_DEVICE_DEFAULT | BASSDeviceInfo.BASS_DEVICE_ENABLED | BASSDeviceInfo.BASS_DEVICE_TYPE_SPEAKERS)) { device = -1; break; } } Init(device, 48000, BASSInit.BASS_DEVICE_DEFAULT); }
/// <summary> /// 获取设备信息 /// </summary> /// <param name="device"></param> /// <param name="info"></param> /// <returns></returns> public static bool BASS_GetDeviceInfo(int device, ref BASS_DEVICEINFO_INTERNAL info) { if (Environment.Is64BitProcess) { return(BassX64.BASS_GetDeviceInfo(device, ref info)); } else { return(BassX86.BASS_GetDeviceInfo(device, ref info)); } }
/// <summary> /// 重写OnCreateControl /// </summary> protected override void OnCreateControl() { base.OnCreateControl(); try { //加载默认目录存放的bass插件 if (WavePlayer._instanceCount == 1) { Bass.BASS_PluginLoad(); } //创建默认双缓冲 this.CreateBufferedGraphics(); //初始化 if (this.DesignMode) { return; } //bass.dll版本验证 if (this.IsVersionValidate && !Bass.BASS_VersionValidate()) { MessageBox.Show("bass.dll版本不匹配,可能会导致程序运行异常", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } //查找是否有声音驱动 int iDevice = 0; BASS_DEVICEINFO_INTERNAL info = new BASS_DEVICEINFO_INTERNAL(); for (int i = 0; Bass.BASS_GetDeviceInfo(i, ref info); i++) { if (info.driver != IntPtr.Zero && info.flags == (BASSDeviceInfo.BASS_DEVICE_DEFAULT | BASSDeviceInfo.BASS_DEVICE_ENABLED | BASSDeviceInfo.BASS_DEVICE_TYPE_SPEAKERS)) { iDevice = -1; break; } } bool ret = Bass.BASS_Init(iDevice, this._freq, BASSInit.BASS_DEVICE_CPSPEAKERS, this.Handle, IntPtr.Zero); if (!ret) { this.OnRaiseLog(new Exception("初始化失败" + BassErrorCode.GetErrorInfo())); } } catch (Exception ex) { this.OnRaiseLog(ex); } }
/// <summary> /// 获取设备数 /// </summary> /// <returns>设备数</returns> public static int GetDeviceCount() { int deviceCount = 0; BASS_DEVICEINFO_INTERNAL info = new BASS_DEVICEINFO_INTERNAL(); for (int i = 0; ; i++) { if (WavHelper.GetDeviceInfo(i, ref info)) { deviceCount++; } else { break; } } return(deviceCount); }
/// <summary> /// Retrieves information on an output device /// </summary> /// <param name="device">The device to get the information of... 0 = first. </param> /// <param name="info">Pointer to a structure to receive the information</param> /// <returns>If successful, then TRUE is returned, else FALSE is returned. Use BASS_ErrorGetCode to get the error code</returns> public static bool GetDeviceInfo(int device, ref BASS_DEVICEINFO_INTERNAL info) { return(NativeMethods.BASS_GetDeviceInfo(device, ref info)); }
public static extern bool BASS_GetDeviceInfo([In] int device, [In, Out] ref BASS_DEVICEINFO_INTERNAL info);