Yuebon.NetCore/Yuebon.Commons/Device/SoundPlayerHelper.cs
(开头部分) 4KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.IO;
using System.Text;
using System.Runtime.InteropServices;
namespace Yuebon.Commons.Device
{
/// <summary>
///声音文件播放操作辅助类。除了MP3声音文件外,还可以播放WAV格式、midi格式声音文件。
/// </summary>
public class SoundPlayerHelper
{
[DllImport("winmm.dll")]
private static extern long mciSendString(string strCommand, StringBuilder strReturn, int iReturnLength, IntPtr hwndCallback);
[DllImport("winmm.dll")]
private static extern int waveOutGetVolume(IntPtr hwo, out uint dwVolume);
[DllImport("winmm.dll")]
private static extern int waveOutSetVolume(IntPtr hwo, uint dwVolume);
/// <summary>
/// 播放声音文件
/// </summary>
/// <param name="soundFileName">声音文件路径(可以是MP3、WAV、Midi等声音文件)</param>
/// <param name="Repeat">是否重复播放</param>
public static void Play(string soundFileName,bool Repeat)
{
mciSendString("open \"" + soundFileName + "\" type mpegvideo alias MediaFile", null, 0, IntPtr.Zero);
mciSendString("play MediaFile" + (Repeat ? " repeat" :String.Empty), null, 0, IntPtr.Zero);
}
/// <summary>
/// 播放声音嵌入资源字节数组
/// </summary>
/// <param name="soundEmbeddedResource">声音文件嵌入资源字节数组(可以是MP3、WAV、Midi等声音格式)</param>
/// <param name="Repeat">是否重复播放</param>
public static void Play(byte[] soundEmbeddedResource, bool Repeat)
{
extractResource(soundEmbeddedResource, Path.GetTempPath() + "resource.tmp");
mciSendString("open \"" + Path.GetTempPath() + "resource.tmp" + "\" type mpegvideo alias MediaFile", null, 0, IntPtr.Zero);
mciSendString("play MediaFile" + (Repeat ? " repeat" : String.Empty), null, 0, IntPtr.Zero);
}
/// <summary>
/// 暂停播放
/// </summary>
public static void Pause()
{
mciSendString("stop MediaFile", null, 0, IntPtr.Zero);
}
/// <summary>
/// 停止播放
/// </summary>
public static void Stop()
{
mciSendString("close MediaFile", null, 0, IntPtr.Zero);
}
后面还有 83 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。