日韩欧美人妻无码精品白浆,夜夜嗨AV免费入口,国产欧美官网在线看,高校回应聋哑女生因长相完美被质疑

LOGO OA教程 ERP教程 模切知識(shí)交流 PMS教程 CRM教程 開發(fā)文檔 其他文檔  
 
網(wǎng)站管理員

WinForm開發(fā)遇到播放聲音的問題,最終采用NAudio實(shí)現(xiàn)

admin
2021年2月1日 10:1 本文熱度 4341

做一個(gè)項(xiàng)目,需要播放聲音,于是找了幾種方法。

首先用的是Soundplayer,它在.NET 自帶的類庫(kù) System.Media 下。

Soundplayer這家伙有一個(gè)特點(diǎn)就是只能播放一個(gè)音頻文件,不論你new出多少個(gè)Soundplayer,它總是播放最后一個(gè)音頻。只要其中任何一個(gè)Soundplayer被停止,馬上就沒聲音了!

后來就換DirectSound,它需要下載并安裝Micrisoft DirectX SDK。

這家伙雖然可以多個(gè)音頻同時(shí)播放,但是,它有一個(gè)怪癖,就是只要窗口沒有被聚焦,它就Shut up了。

后來又試了AxWindowsMediaPlayer,這個(gè)玩意呢它好像只能指定音頻路徑,但是,我想要直接調(diào)用資源文件里面的音頻,所以,我拋棄它!

最后,無意中搜到NAudio,于是就開始研究它!

這玩意也是有點(diǎn)毛病,竟然沒有循環(huán)播放的方法,網(wǎng)上找了老半天也沒有人做過這個(gè),倒是不少人抄那篇“用C#和NAudio解碼庫(kù)播放mp3示例”。

只能自己研究了,最終的MyPlayer代碼:


  1. using System.IO;
  2. using NAudio.Wave;
  3. partial class MyPlayer {
  4. WaveOut player;
  5. WaveFileReader reader;
  6. WaveStream pcmStream;
  7. BlockAlignReductionStream blockAlignedStream;
  8. public Stream Stream {
  9. set {
  10. if(reader != null)
  11. reader.Dispose();
  12. if(pcmStream != null)
  13. pcmStream.Dispose();
  14. if(blockAlignedStream != null)
  15. blockAlignedStream.Dispose();
  16. reader = new WaveFileReader(value);
  17. pcmStream = WaveFormatConversionStream.CreatePcmStream(reader);
  18. blockAlignedStream = new BlockAlignReductionStream(pcmStream);
  19. if(player != null)
  20. player.Dispose();
  21. player = new WaveOut(WaveCallbackInfo.FunctionCallback());
  22. player.PlaybackStopped += new System.EventHandler<StoppedEventArgs>(player_PlaybackStopped);
  23. }
  24. }
  25. public MyPlayer(Stream media) {
  26. Stream = media;
  27. }
  28. public MyPlayer() { }
  29. public int Looping { get; set; }
  30. int timer;
  31. public void Play() {
  32. timer = 0;
  33. if(player != null && player.PlaybackState == PlaybackState.Playing)
  34. return;
  35. if(blockAlignedStream != null) {
  36. blockAlignedStream.Position = 0;
  37. player.Init(blockAlignedStream);
  38. player.Play();
  39. }
  40. }
  41. void player_PlaybackStopped(object sender, StoppedEventArgs e) {
  42. if(timer >= 0 && (Looping == 0 || Looping < timer)) {
  43. blockAlignedStream.Position = 0;
  44. player.Init(blockAlignedStream);
  45. player.Play();
  46. }
  47. timer++;
  48. }
  49. public void Stop() {
  50. timer = int.MinValue;
  51. if(player != null) {
  52. player.Stop();
  53. }
  54. }
  55. public void Dispose() {
  56. if(reader != null)
  57. reader.Dispose();
  58. if(pcmStream != null)
  59. pcmStream.Dispose();
  60. if(blockAlignedStream != null)
  61. blockAlignedStream.Dispose();
  62. if(player != null) {
  63. player.Stop();
  64. player.Dispose();
  65. }
  66. }
  67. }


該文章在 2021/2/1 10:01:40 編輯過
關(guān)鍵字查詢
相關(guān)文章
正在查詢...
點(diǎn)晴ERP是一款針對(duì)中小制造業(yè)的專業(yè)生產(chǎn)管理軟件系統(tǒng),系統(tǒng)成熟度和易用性得到了國(guó)內(nèi)大量中小企業(yè)的青睞。
點(diǎn)晴PMS碼頭管理系統(tǒng)主要針對(duì)港口碼頭集裝箱與散貨日常運(yùn)作、調(diào)度、堆場(chǎng)、車隊(duì)、財(cái)務(wù)費(fèi)用、相關(guān)報(bào)表等業(yè)務(wù)管理,結(jié)合碼頭的業(yè)務(wù)特點(diǎn),圍繞調(diào)度、堆場(chǎng)作業(yè)而開發(fā)的。集技術(shù)的先進(jìn)性、管理的有效性于一體,是物流碼頭及其他港口類企業(yè)的高效ERP管理信息系統(tǒng)。
點(diǎn)晴WMS倉(cāng)儲(chǔ)管理系統(tǒng)提供了貨物產(chǎn)品管理,銷售管理,采購(gòu)管理,倉(cāng)儲(chǔ)管理,倉(cāng)庫(kù)管理,保質(zhì)期管理,貨位管理,庫(kù)位管理,生產(chǎn)管理,WMS管理系統(tǒng),標(biāo)簽打印,條形碼,二維碼管理,批號(hào)管理軟件。
點(diǎn)晴免費(fèi)OA是一款軟件和通用服務(wù)都免費(fèi),不限功能、不限時(shí)間、不限用戶的免費(fèi)OA協(xié)同辦公管理系統(tǒng)。
Copyright 2010-2025 ClickSun All Rights Reserved