你的位置:首页 > ASP.net教程

[ASP.net教程]KTV点歌系统播放原理


北大青鸟KTV点歌系统播放原理

指导老师--原玉明

 

1.首先知道有两个类(PlayList   Song)

PlayList类中有一方法

public static bool AddSong(Song song)

        {

            bool success = false;//记录添加歌曲是否成功

            for (int i = 0; i < SongList.Length; i++)

            {

                //找到数组中第一个为null的位置

                if (SongList[i] == null)

                {

                    SongList[i] = song;

                    success = true;

                    break;

                }

            }

            return success;

        }

 

2.将选中的歌曲对象放到PlayList类中的数组

Song song = new Song();

song.SongName = dgvSong.SelectedRows[0].Cells["songName"].Value.ToString();记录当前歌曲

song.SongURL =KtvUnit.SongPath+"\\"+ dgvSong.SelectedRows[0].Cells["songURL"].Value.ToString(); 

//MessageBox.Show(song.SongURL);

PlayList.AddSong(song);

 

3.在FrmMian中的Timer控件 1s Enable=true   Tick点击事件

If(Player1.playstate==Vmpplayer.stopped)

{

         Song=null;

         PlayList.MoveOn();//当歌曲播放到最后一秒的那一瞬间,进行播放下一首

}

4. public static void MoveOn()

        {

            if (SongList[SongIndex] != null && SongList[SongIndex].PlayState == SongPlayState.again)

//如果当前播放歌曲不为空并且状态为重播

            {

                SongList[SongIndex].SetSongPlayed();//状态改为已播

            }

            else

            {

                SongIndex++;//执行++进行下一首播放

            }

        }

5. public  void SongList()        `       

        {

            lvSong.Items.Clear();

            for (int i = 0; i < PlayList.SongList.Length; i++)

            {

                if (PlayList.SongList[i]!=null)

                {

                    ListViewItem item = new ListViewItem();

                    item.Text = PlayList.SongList[i].SongName;

                    item.Tag = i;

                    string playstate = PlayList.SongList[i].PlayState == SongPlayState.unplayed ? "未播放" : "已播";

                    item.SubItems.Add(playstate);

                    lvSong.Items.Add(item);

                }

            }

        }