using Autofac; using Entity.DbModel.Station; using HybirdFrameworkCore.Autofac; using HybirdFrameworkCore.Autofac.Attribute; using Repository.Station; using log4net; namespace Service.Sound.SoundClient; [Scope] public class SoundClient { private static readonly ILog Log = LogManager.GetLogger(typeof(SoundClient)); EquipInfoRepository equipInfoRepository = AppInfo.Container.Resolve(); EquipNetInfoRepository netInfoRepository = AppInfo.Container.Resolve(); public static string soundIp = ""; /// /// //0-播放停止状态 //1-播放中 //2-播放暂停状态 /// private uint m_nPlayStatus = 3; public string SoundConn() { //设备编码 2 - 音响IP "192.168.3.77" EquipInfo equipInfo = equipInfoRepository.QueryByClause(u => u.Code == "2"); if (equipInfo != null) { EquipNetInfo equipNetInfo = netInfoRepository.QueryByClause(u => u.Code == equipInfo.Code); if (equipNetInfo != null) { NAudioClientDll.na_add_play_device(0, 0, equipNetInfo.NetAddr); IntPtr[] devlist = new IntPtr[512]; int devcnt = 0; NAudioClientDll.na_get_play_device(0, 0, devlist, ref devcnt); if (devcnt == 1) { soundIp = equipNetInfo.NetAddr; Log.Info("音响设备" + equipNetInfo.NetAddr + "添加成功"); return "音响设备" + equipNetInfo.NetAddr + "添加成功"; } else { Log.Info("音响设备" + equipNetInfo.NetAddr + "添加失败"); return "音响设备" + equipNetInfo.NetAddr + "添加失败"; } } return "数据库设备IP不存在"; } return "数据库设备信息不存在"; } /// /// 设置音量 /// /// 0-100 public void ControlSound(byte soundValue) { if (soundIp != "") { //更新播放设备音量 NAudioClientDll.na_set_device_volume(soundIp, soundValue); } } /// /// 播放声音文件 /// /// mp3 文件所在路径 /// 例如:"D:\\Desktop\\Sound\\电池拆卸中请稍后.mp3" public bool SoundPlay(string fileLoad) { int result = NAudioClientDll.na_start_play_1(0, 0, fileLoad, 10); if (NAudioClientDll.RET_SUCCESS == result) return true; return false; } /// /// 当前设备是否允许播放 /// /// public bool EnableSoundPlay() { NAudioClientDll.na_get_play_status(0, 0, ref m_nPlayStatus); //当前 播放状态:播放中 if (m_nPlayStatus == NAudioClientDll.PS_PLAYING) return false; return true; } }