标题:
c#播放MP3源程序
[打印本页]
作者:
西欧阿虎
时间:
2019-3-4 09:55
标题:
c#播放MP3源程序
c# 调用winmm.dll 播放mp3
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
namespace DMS
{
// Token: 0x02000016 RID: 22
public static class MP3Player
{
// Token: 0x060000F8 RID: 248 RVA: 0x00027F08 File Offset: 0x00026108
private static void PlayWait(string file)
{
bool flag = !File.Exists(file);
if (!flag)
{
MP3Player.mciSendString(string.Format("open \"{0}\" type mpegvideo alias media", file), null, 0, 0);
MP3Player.mciSendString("play media wait", null, 0, 0);
MP3Player.mciSendString("close media", null, 0, 0);
}
}
// Token: 0x060000F9 RID: 249 RVA: 0x00027F58 File Offset: 0x00026158
private static void PlayRepeat(string file)
{
bool flag = !File.Exists(file);
if (!flag)
{
MP3Player.mciSendString(string.Format("open \"{0}\" type mpegvideo alias media", file), null, 0, 0);
MP3Player.mciSendString("play media repeat", null, 0, 0);
}
}
// Token: 0x060000FA RID: 250 RVA: 0x00027F98 File Offset: 0x00026198
public static void Play(string file, int times)
{
bool flag = file.Trim() == "";
if (!flag)
{
bool flag2 = file.Contains("..\\");
if (flag2)
{
file = Application.StartupPath + file.Substring("..".Length);
}
DataManageInfo.IsPlaying = 0;
bool flag3 = !File.Exists(file);
if (!flag3)
{
DataManageInfo.IsPlaying = 1;
MP3Player.thread = new Thread(delegate ()
{
bool flag4 = times == 0;
if (flag4)
{
MP3Player.PlayRepeat(file);
}
else
{
bool flag5 = times > 0;
if (flag5)
{
int num;
for (int i = 0; i < times; i = num + 1)
{
MP3Player.PlayWait(file);
num = i;
}
}
}
while (DataManageInfo.IsPlaying == 1)
{
Thread.Sleep(100);
}
MP3Player.mciSendString("stop media", null, 0, 0);
MP3Player.mciSendString("close media", null, 0, 0);
DataManageInfo.IsPlaying = 0;
});
MP3Player.thread.SetApartmentState(ApartmentState.STA);
MP3Player.thread.IsBackground = true;
MP3Player.thread.Start();
}
}
}
// Token: 0x060000FB RID: 251 RVA: 0x0002806C File Offset: 0x0002626C
public static void Stop()
{
bool flag = MP3Player.thread != null;
if (flag)
{
try
{
DataManageInfo.IsPlaying = 2;
while (DataManageInfo.IsPlaying == 2)
{
Thread.Sleep(100);
}
MP3Player.thread.Abort();
}
catch
{
}
MP3Player.thread = null;
}
}
// Token: 0x060000FC RID: 252
[DllImport("winmm.dll", CharSet = CharSet.Auto)]
private static extern int mciSendString(string lpstrCommand, string lpstrReturnString, int uReturnLength, int hwndCallback);
// Token: 0x04000227 RID: 551
private static Thread thread;
}
}
复制代码
MP3Player.rar
2019-3-4 09:55 上传
点击文件名下载附件
下载积分: 黑币 -5
1.04 KB, 下载次数: 11, 下载积分: 黑币 -5
c#播放MP3的类库
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1