zoukankan      html  css  js  c++  java
  • c# 叫号小程序

    写个叫号的小demo

    长相如下

    代码如下

     1 using System;
     2 using System.Collections.Generic;
     3 using System.ComponentModel;
     4 using System.Data;
     5 using System.Drawing;
     6 using System.IO;
     7 using System.Linq;
     8 using System.Media;
     9 using System.Text;
    10 using System.Threading;
    11 using System.Windows.Forms;
    12 using NAudio.Wave;
    13 
    14 namespace VoiceDemo
    15 {
    16     public partial class Form1 : Form
    17     {
    18         public Form1()
    19         {
    20             InitializeComponent();
    21         }
    22 
    23         private void button1_Click(object sender, EventArgs e)
    24         {
    25             string[] lstMp3s = Directory.GetFiles(Application.StartupPath + "\mp3", "*.mp3");
    26             Dictionary<string, string> lstDicMp3 = new Dictionary<string, string>();
    27             for (int i = 0; i < lstMp3s.Length; i++)
    28             {
    29                 lstDicMp3.Add(Path.GetFileNameWithoutExtension(lstMp3s[i]), lstMp3s[i]);
    30             }
    31             lstDicMp3 = lstDicMp3.OrderByDescending(p => p.Key.Length).ToDictionary(p => p.Key, o => o.Value);
    32 
    33             string strText = textBox1.Text;
    34             List<string> lst = new List<string>();
    35             GetPlayList(lstDicMp3, strText, ref lst);
    36             foreach (var item in lst)
    37             {
    38                 using (var ms = File.OpenRead(lstDicMp3[item]))
    39                 using (var rdr = new Mp3FileReader(ms))
    40                 using (var wavStream = WaveFormatConversionStream.CreatePcmStream(rdr))
    41                 using (var baStream = new BlockAlignReductionStream(wavStream))
    42                 using (var waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback()))
    43                 {
    44                     waveOut.Init(baStream);
    45                     waveOut.Play();
    46                     while (waveOut.PlaybackState == PlaybackState.Playing)
    47                     {
    48                         Thread.Sleep(10);
    49                     }
    50                 }
    51             }
    52         }
    53 
    54         private void GetPlayList(Dictionary<string, string> lstDicMp3, string strText, ref  List<string> lst)
    55         {
    56             foreach (var item in lstDicMp3)
    57             {
    58                 if (strText.StartsWith(item.Key))
    59                 {
    60                     lst.Add(item.Key);
    61                     strText = strText.Remove(0, item.Key.Length);
    62                     break;
    63                 }
    64             }
    65             if (strText.Length > 0)
    66                 GetPlayList(lstDicMp3, strText, ref lst);
    67         }
    68     }
    69 }
    View Code

    demo地址

    https://pan.baidu.com/s/1eSiy98m

  • 相关阅读:
    最佳内存缓存框架Caffeine
    18个Java8日期处理的实践,太有用了
    windows 2003 IIS FTP 530 home directory inaccessible
    关闭应用程序(主程序)(WPF)
    解决Win8.1 IE11兼容性问题的方法
    Web页面性能测试工具浅析
    JS模板引擎handlebars.js的简单使用
    mvc4+entityFramework5 发布时遇到的纠结问题
    sqlserver 导入数据出现 无法创建 OLE DB 取值函数。请查看列元数据是否有效
    正则基础之——贪婪与非贪婪模式
  • 原文地址:https://www.cnblogs.com/bfyx/p/8042635.html
Copyright © 2011-2022 走看看