Peking University Jade Bird KTV song system playing principle
Instructor--Yuana Yuming
1. First know there are two classes (PlayList Song)
There is one method in the playlist class
public static bool Addsong (song song)
{
BOOL success = false;//Record added song is successful
for (int i = 0; i < songlist.length; i++)
{
Find the first null position in the array
if (songlist[i] = = null)
{
Songlist[i] = song;
Success = true;
Break
}
}
return success;
}
2. Place the selected song object into an array in the playlist class
Song song = new Song ();
Song. Songname = Dgvsong.selectedrows[0]. cells["Songname"]. Value.tostring (); record the current song
Song. Songurl =ktvunit.songpath+ "\ \" + dgvsong.selectedrows[0]. cells["Songurl"]. Value.tostring ();
MessageBox.Show (song. Songurl);
Playlist.addsong (song);
3. Timer control in Frmmian 1s enable=true tick click event
If (player1.playstate==vmpplayer.stopped)
{
Song=null;
Playlist.moveon ();//When the song plays to the last second of the moment, play the next song
}
4. Public static void MoveOn ()
{
if (Songlist[songindex]! = null && Songlist[songindex]. Playstate = = Songplaystate.again)
If the currently playing song is not empty and the status is replay
{
Songlist[songindex]. Setsongplayed ();//status changed to broadcast
}
Else
{
songindex++;//Execute + + to play the next song
}
}
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? "Not played": "Broadcast";
Item. SubItems.Add (playstate);
LVSONG.ITEMS.ADD (item);
}
}
}
KTV Song System Playback principle