資源簡介
C#控制 指定系統音頻輸出設備播放音樂,C#控制音量大小,C# 調用 winmm.dll

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Linq;
using?System.Text;
using?System.IO;
namespace?WaveLib
{
????public?class?WaveMain
????{
????????private?WaveOutPlayer?m_Player;
????????private?Stream?m_AudioStream;
????????private?WaveFormat?m_Format;
????????private?int?_DevId;
????????public?int?DevId
????????{
????????????get?{?return?_DevId;?}
????????????set?{?_DevId?=?value;?}
????????}
????????public?WaveMain()
????????{
????????????CloseFile();
????????????try
????????????{
????????????????WaveStream?S?=?new?WaveStream(“Data/ringin.wav“);
????????????????if?(S.Length?<=?0)
????????????????????throw?new?Exception(“Invalid?WAV?file“);
????????????????m_Format?=?S.Format;
????????????????if?(m_Format.wFormatTag?!=?(short)WaveFormats.Pcm?&&?m_Format.wFormatTag?!=?(short)WaveFormats.Float)
????????????????????throw?new?Exception(“Olny?PCM?files?are?supported“);
????????????????m_AudioStream?=?S;
????????????}
????????????catch?(Exception?e)
????????????{
????????????????CloseFile();
????????????}
????????}
????????private?void?Filler(IntPtr?data?int?size)
????????{
????????????byte[]?b?=?new?byte[size];
????????????if?(m_AudioStream?!=?null)
????????????{
????????????????int?pos?=?0;
????????????????while?(pos?????????????????{
????????????????????int?toget?=?size?-?pos;
????????????????????int?got?=?m_AudioStream.Read(b?pos?toget);
????????????????????if?(got?????????????????????????m_AudioStream.Position?=?0;?//?loop?if?the?file?ends
????????????????????pos?+=?got;
????????????????}
????????????}
????????????else
????????????{
????????????????for?(int?i?=?0;?i?????????????????????b[i]?=?0;
????????????}
????????????System.Runtime.InteropServices.Marshal.Copy(b?0?data?size);
????????}
????????public?void?Play()
????????{
????????????Stop();
????????????if?(m_AudioStream?!=?null)
????????????{
????????????????m_AudioStream.Position?=?0;
????????????????m_Player?=?new?WaveOutPlayer(DevId?m_Format?16384?3?new?BufferFillEventHandler(Filler));
????????????}
????????}
????????public?void?Stop()
????????{
????????????if?(m_Player?!=?null)
????????????????try
????????????????{
????????????????????m_Player.Dispose();
????????????????}
????????????????finally
????????????????{
????????????????????m_Player?=?null;
????????????????}
????????}
????????private?void?CloseFile()
????????{
????????????Stop();
????????????if?(m_AudioStream?!=?null)
????????????????try
????????????????{
????????????????????m_AudioStream.Close();
????????????????}
????????????????finally
????????????????{
????????????????????m_AudioStream?=?null;
????????????????}
????????}
????}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2013-01-04?14:42??振鈴測試\
?????目錄???????????0??2013-01-07?13:38??振鈴測試\WaveLib\
?????目錄???????????0??2013-01-04?14:42??振鈴測試\WaveLib\bin\
?????目錄???????????0??2013-01-04?10:47??振鈴測試\WaveLib\bin\Debug\
?????目錄???????????0??2013-01-04?14:42??振鈴測試\WaveLib\bin\Release\
?????文件???????14848??2013-01-07?13:38??振鈴測試\WaveLib\bin\Release\WaveLib.dll
?????文件???????38400??2013-01-07?13:38??振鈴測試\WaveLib\bin\Release\WaveLib.pdb
?????目錄???????????0??2013-01-04?14:42??振鈴測試\WaveLib\obj\
?????目錄???????????0??2013-01-04?14:42??振鈴測試\WaveLib\obj\Debug\
?????文件????????5651??2013-01-04?10:47??振鈴測試\WaveLib\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????目錄???????????0??2013-01-04?10:47??振鈴測試\WaveLib\obj\Debug\TempPE\
?????目錄???????????0??2013-01-07?13:38??振鈴測試\WaveLib\obj\Release\
?????文件????????5655??2013-01-04?14:38??振鈴測試\WaveLib\obj\Release\DesignTimeResolveAssemblyReferencesInput.cache
?????文件??????100112??2013-01-07?12:49??振鈴測試\WaveLib\obj\Release\ResolveAssemblyReference.cache
?????目錄???????????0??2013-01-04?10:47??振鈴測試\WaveLib\obj\Release\TempPE\
?????文件?????????743??2013-01-04?15:04??振鈴測試\WaveLib\obj\Release\WaveLib.csproj.FileListAbsolute.txt
?????文件???????14848??2013-01-07?13:38??振鈴測試\WaveLib\obj\Release\WaveLib.dll
?????文件???????38400??2013-01-07?13:38??振鈴測試\WaveLib\obj\Release\WaveLib.pdb
?????目錄???????????0??2013-01-04?14:42??振鈴測試\WaveLib\Properties\
?????文件????????1364??2013-01-04?10:47??振鈴測試\WaveLib\Properties\AssemblyInfo.cs
?????文件????????2378??2013-01-04?15:04??振鈴測試\WaveLib\WaveLib.csproj
?????文件????????2761??2013-01-04?11:20??振鈴測試\WaveLib\WaveMain.cs
?????文件????????5333??2013-01-07?13:38??振鈴測試\WaveLib\WaveNative.cs
?????文件????????8264??2013-01-04?14:26??振鈴測試\WaveLib\WaveOut.cs
?????文件????????4574??2013-01-04?11:15??振鈴測試\WaveLib\WaveStream.cs
?????目錄???????????0??2013-01-07?15:05??振鈴測試\WaveTest\
?????目錄???????????0??2013-01-04?14:57??振鈴測試\WaveTest\bin\
?????目錄???????????0??2013-01-04?14:56??振鈴測試\WaveTest\bin\Debug\
?????目錄???????????0??2013-01-04?14:56??振鈴測試\WaveTest\bin\Debug\Data\
?????文件?????2155792??2013-01-04?14:55??振鈴測試\WaveTest\bin\Debug\Data\ringin.wav
?????文件???????15360??2013-01-04?14:56??振鈴測試\WaveTest\bin\Debug\WaveLib.dll
............此處省略51個文件信息
- 上一篇:asp(C#+sql)網上購物系統
- 下一篇:C#在線考試系統
評論
共有 條評論