KTV点歌系统————北大青鸟 指导老师:原玉明
1 public enum SongPlayState 2 { 3 //未播放,播放,重播,切歌 4 unplayed, played, again, cut 5 } 6 public class Song 7 { 8 public string SongName { get; set; }//歌曲名称 9 10 public string SongURL { get; set; }//歌曲路径11 12 13 public SongPlayState playState = SongPlayState.unplayed;//默认未播放14 internal SongPlayState PlayState { get; set; }15 16 //状态为已播17 public void SetSongPlayed()18 {19 this.PlayState = SongPlayState.played;20 }21 //重唱22 public void SetPlayAgain()23 {24 this.playState = SongPlayState.again;25 }26 //切歌27 public void SetSongCut()28 {29 this.playState = SongPlayState.cut;30 }
PlayList类中实现切歌 重唱 下一首 等.....
1 public class PlayList 2 { 3 //定义一个长度为、50的歌曲数组,默认存储50首歌曲 4 public static Song[] SongList = new Song[50]; 5 public static int SongIndex = 0;//当前播放的歌曲在数组中的索引 6 //点播一首歌曲,其实是将歌曲对象添加到歌曲数组中 7 public static bool AddSong(Song song) 8 { 9 bool success = false;//记录添加歌曲是否成功 10 for (int i = 0; i < SongList.Length; i++) 11 { 12 //找到数组中第一个为null的位置 13 if (SongList[i] == null) 14 { 15 SongList[i] = song; 16 success = true; 17 break; 18 } 19 } 20 return success; 21 } 22 //获取当前播放的歌曲::既然是获取当前播放的歌曲,返回值肯定是Song类型 23 public static Song GetPlaySong() 24 { 25 if (SongList[SongIndex] != null) 26 { 27 return SongList[SongIndex]; 28 } 29 else 30 { 31 return null; 32 } 33 } 34 /// <summary> 35 /// 播放下一首 36 /// </summary> 37 public static void MoveOn() 38 { 39 if (SongList[SongIndex] != null && SongList[SongIndex].PlayState == SongPlayState.again) 40 { 41 SongList[SongIndex].SetSongPlayed(); 42 } 43 else 44 { 45 SongIndex++; 46 } 47 } 48 /// <summary> 49 /// 当前播放的歌曲名称 50 /// </summary> 51 /// <returns>歌曲名称</returns> 52 public static string PlayingSongName() 53 { 54 string songName = ""; // 歌曲名称 55 if (SongList[SongIndex] != null) 56 { 57 songName = SongList[SongIndex].SongName; 58 } 59 60 return songName; 61 } 62 /// <summary> 63 /// 下一首要播放的歌曲名称 64 /// </summary> 65 /// <returns>歌曲名称</returns> 66 public static string NextSongName() 67 { 68 string songName = ""; // 歌曲名称 69 if (SongList[SongIndex + 1] != null) 70 { 71 songName = SongList[SongIndex + 1].SongName; 72 } 73 74 return songName; 75 } 76 //重放当前歌曲 77 public static void PlayAgain() 78 { 79 if (SongList[SongIndex] != null) 80 { 81 SongList[SongIndex].SetPlayAgain(); 82 } 83 } 84 //切歌 85 public static void CutSong(int index) 86 { 87 int i;//循环变量,代表切歌的位置 88 if (index == -1)//循环变量,代表切割的位置 89 { 90 i = SongIndex; 91 } 92 else 93 { 94 i = index;//从切歌的位置开始,将歌曲逐个向前移一个位置 95 } 96 SongList[i].SetSongCut(); 97 while (SongList[i] != null) 98 { 99 SongList[i] = SongList[i + 1];100 i++; 101 //如果达到数组最后一个元素,就将最后一个元素指向空102 if (i == SongList.Length)103 {104 SongList[i] = null;105 }106 }107 }108 }
实现歌手点歌
1 public FrmMain frmMain; 2 string connectionStr = "server=.;database=MyKTV;uid=sa"; 3 DBHelp db = new DBHelp(); 4 PRivate SqlConnection con; 5 //首先要查出数据库中的图片路径和歌曲路径 6 private void FrmCountry_Load(object sender, EventArgs e) 7 { 8 9 con = new SqlConnection(connectionStr); 10 con.Open(); 11 string sql = "select resource_path from resource_path where resource_id=1"; 12 13 string sqlsongpath = "select resource_path from resource_path where resource_id=2"; 14 SqlCommand cmd = new SqlCommand(sql,con); 15 16 SqlCommand cmd2 = new SqlCommand(sqlsongpath, con); 17 KtvUnit.ImagePath = cmd.ExecuteScalar().ToString(); 18 KtvUnit.SongPath = cmd2.ExecuteScalar().ToString(); 19 con.Close(); 20 } 21 //点击歌手男女或组合时 22 private void LvOne_Click(object sender, EventArgs e) 23 { 24 25 LoadSingerArea(); 26 } 27 public string singer_type { get; set; } 28 private void LoadSingerArea() 29 { 30 if (this.LvOne.SelectedItems[0] != null) 31 { 32 LvOne.Visible = false; 33 LvTwo.Location = LvOne.Location; 34 LvTwo.Dock = DockStyle.Fill; 35 LvTwo.Visible = true; 36 this.singer_type=Convert.ToString(LvOne.SelectedItems[0].Text); 37 } 38 39 con = new SqlConnection(connectionStr); 40 string sql = "select singertype_id,singertype_name from singer_type"; 41 SqlCommand cmd = new SqlCommand(sql, con); 42 SqlDataReader dr; 43 try 44 { 45 con.Open(); 46 LvTwo.Items.Clear(); 47 dr = cmd.ExecuteReader(); 48 if (dr.HasRows) 49 { 50 int index = 0; 51 while (dr.Read()) 52 { 53 ListViewItem lvItem = new ListViewItem(); 54 int typeid = Convert.ToInt32(dr["singertype_id"]); 55 string typename = Convert.ToString(dr["singertype_name"]); 56 lvItem.Text = typename; 57 lvItem.Tag = typeid; 58 lvItem.ImageIndex = index; 59 LvTwo.Items.Add(lvItem); 60 index++; 61 } 62 } 63 dr.Close(); 64 } 65 catch (Exception ex) 66 { 67 68 MessageBox.Show("系统出现异常" + ex.Message); 69 } 70 finally 71 { 72 con.Close(); 73 } 74 } 75 public string singertype_id { get; set; } 76 /// <summary> 77 /// 点击地区类型时 78 /// </summary> 79 /// <param name="sender"></param> 80 /// <param name="e"></param> 81 private void LvTwo_Click(object sender, EventArgs e) 82 { 83 if (this.LvTwo.SelectedItems[0] != null) 84 { 85 LvTwo.Visible = false; 86 Lvthree.Location = LvTwo.Location; 87 Lvthree.Dock = DockStyle.Fill; 88 Lvthree.Visible = true; 89 this.singertype_id = Convert.ToString(LvTwo.SelectedItems[0].Tag); 90 } 91 string result = singer_type; 92 if (result != "组合") 93 { 94 result
新闻热点
疑难解答