/// <summary>
/// 文件广播
/// </summary>
/// <param name="fileName"></param>
public void BroadcastFile(string fileName)
{
if (File.Exists(fileName))
{
//播放,单开线程播放文件-----lmy
Thread playThread = new Thread(() =>
{
if (fileName.EndsWith(".mp3"))
{
try
{
byte[] allBytes = System.IO.File.ReadAllBytes(fileName);
byte[] id3v2_data = null;//MP3的id3v2和data
if (allBytes.Length > 128)
{
id3v2_data = new byte[allBytes.Length - 128];
Array.Copy(allBytes, id3v2_data, allBytes.Length - 128);
}
byte[] head = new byte[4];//每一帧的头部
byte[] data = null;//每一帧音频数据
int dataCount = 0;//总共多少帧音频数据
int time = 0;//每帧持续时间(毫秒)
int lenght = 0;//每一帧音频数据长度
for (int i = 0; i < id3v2_data.Length; i++)
{
if (id3v2_data[i].Equals(0xff) && id3v2_data[i + 1] >> 5 == 0x7)
{
head[0] = id3v2_data[i];
i++;
head[1] = id3v2_data[i];
i++;
head[2] = id3v2_data[i];
i++;
head[3] = id3v2_data[i];
i++;
AnalyzeMP3Head(head, ref time, ref lenght);
data = new byte[lenght];
Array.Copy(id3v2_data, i, data, 0, lenght);
dataCount++;
head = new byte[] { head[3], head[2], head[1], head[0] };
LogFactory.Info("MP3音频数据 第【{0}】帧 帧头 {1} ", dataCount, head.ToHexString());
LogFactory.Info("MP3音频数据 第【{0}】帧 数据 {1}", dataCount, data.ToHexString());
//发送信息
try
{
Thread.Sleep(time);
}
catch (Exception exx)
{
Console.WriteLine(exx.Message);
}
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
});
playThread.Priority = ThreadPriority.Highest;//160917,fly设置优先级最高
playThrea
/// 文件广播
/// </summary>
/// <param name="fileName"></param>
public void BroadcastFile(string fileName)
{
if (File.Exists(fileName))
{
//播放,单开线程播放文件-----lmy
Thread playThread = new Thread(() =>
{
if (fileName.EndsWith(".mp3"))
{
try
{
byte[] allBytes = System.IO.File.ReadAllBytes(fileName);
byte[] id3v2_data = null;//MP3的id3v2和data
if (allBytes.Length > 128)
{
id3v2_data = new byte[allBytes.Length - 128];
Array.Copy(allBytes, id3v2_data, allBytes.Length - 128);
}
byte[] head = new byte[4];//每一帧的头部
byte[] data = null;//每一帧音频数据
int dataCount = 0;//总共多少帧音频数据
int time = 0;//每帧持续时间(毫秒)
int lenght = 0;//每一帧音频数据长度
for (int i = 0; i < id3v2_data.Length; i++)
{
if (id3v2_data[i].Equals(0xff) && id3v2_data[i + 1] >> 5 == 0x7)
{
head[0] = id3v2_data[i];
i++;
head[1] = id3v2_data[i];
i++;
head[2] = id3v2_data[i];
i++;
head[3] = id3v2_data[i];
i++;
AnalyzeMP3Head(head, ref time, ref lenght);
data = new byte[lenght];
Array.Copy(id3v2_data, i, data, 0, lenght);
dataCount++;
head = new byte[] { head[3], head[2], head[1], head[0] };
LogFactory.Info("MP3音频数据 第【{0}】帧 帧头 {1} ", dataCount, head.ToHexString());
LogFactory.Info("MP3音频数据 第【{0}】帧 数据 {1}", dataCount, data.ToHexString());
//发送信息
try
{
Thread.Sleep(time);
}
catch (Exception exx)
{
Console.WriteLine(exx.Message);
}
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
});
playThread.Priority = ThreadPriority.Highest;//160917,fly设置优先级最高
playThrea