You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
3.0 KiB

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<EquipInfoRepository>();
EquipNetInfoRepository netInfoRepository = AppInfo.Container.Resolve<EquipNetInfoRepository>();
public static string soundIp = "";
/// <summary>
/// //0-播放停止状态 //1-播放中 //2-播放暂停状态
/// </summary>
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 "数据库设备信息不存在";
}
/// <summary>
/// 设置音量
/// </summary>
/// <param name="soundValue">0-100</param>
public void ControlSound(byte soundValue)
{
if (soundIp != "")
{
//更新播放设备音量
NAudioClientDll.na_set_device_volume(soundIp, soundValue);
}
}
/// <summary>
/// 播放声音文件
/// </summary>
/// <param name="fileLoad">mp3 文件所在路径</param>
/// 例如:"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;
}
/// <summary>
/// 当前设备是否允许播放
/// </summary>
/// <returns></returns>
public bool EnableSoundPlay()
{
NAudioClientDll.na_get_play_status(0, 0, ref m_nPlayStatus);
//当前 播放状态:播放中
if (m_nPlayStatus == NAudioClientDll.PS_PLAYING)
return false;
return true;
}
}