Using system;
Using system. Collections. Generic;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. LINQ;
Using system. text;
Using system. Windows. forms;
Namespace Media
{
Public Enum state
{
// Single Loop
Singleplay = 0,
// Unordered playback
Unorderloopplay = 1,
// List Loop
Listplay = 2
}
Public partial class form1: Form
{
Public form1 ()
{
Initializecomponent ();
}
Private void button#click (Object sender, eventargs E)
{
System. Windows. Forms. folderbrowserdialog browser = new folderbrowserdialog ();
Dialogresult diares = browser. showdialog ();
If (diares = dialogresult. OK)
{
String pathname = browser. selectedpath;
System. Io. directoryinfo dir = new system. Io. directoryinfo (pathname );
Foreach (system. Io. fileinfo F in Dir. getfiles ())
{
If (F. extension = ". MP3 "| f. extension = ". MP4 "| f. extension = ". avi "| f. extension = ". WMV "| f. extension = ". 3GP "| f. extension = ". FLV ")
{
Playlist. Items. Add (F. fullname );
}
}
}
}
Private void form1_load (Object sender, eventargs E)
{
Playlist. Items. Clear ();
}
// Add a song
Private void button2_click (Object sender, eventargs E)
{
Openfiledialog songfile = new openfiledialog ();
Songfile. multiselect = true;
Songfile. filter = "playable song files | *. rmvb ;*. MP3 ;*. MP4 ;*. avi ;*. WMV ;*. 3GP ;*. FLV | all files *. * | *. *";
Dialogresult diares = songfile. showdialog ();
If (diares = dialogresult. OK)
{
Foreach (string F in songfile. filenames)
{
Playlist. Items. Add (f );
}
}
}
// Clear the list
Private void button3_click (Object sender, eventargs E)
{
Playlist. Items. Clear ();
}
// Double-click the playback file in the playlist to play the video.
Private void playlist_doubleclick (Object sender, eventargs E)
{
If (playlist. selectedindex> = 0)
{
// Axwindowsmediaplayer1.url = playlist. selecteditem. tostring ();
Axwindowsmediaplayer1.url = playlist. items [playlist. selectedindex]. tostring ();
This. Text = "my player" + playlist. selecteditem. tostring ();
}
Else
{
MessageBox. Show ("select a song ");
}
}
// Next song
Private void btnnext_click (Object sender, eventargs E)
{
Next ();
}
// Previous song
Private void btnprew_click (Object sender, eventargs E)
{
If (this. playlist. selectedindex = 0)
{
Axwindowsmediaplayer1.url = This. playlist. items [playlist. selectedindex]. tostring ();
This. Text = "my player" + playlist. items [playlist. selectedindex]. tostring ();
}
Else if (this. playlist. selectedindex> 0)
{
Axwindowsmediaplayer1.url = This. playlist. items [playlist. selectedindex-1]. tostring ();
This. Text = "my player" + playlist. items [playlist. selectedindex-1]. tostring ();
This. playlist. selectedindex-= 1;
}
}
// Next Method
Public void next ()
{
If (playlist. selectedindex <this. playlist. Items. Count-1)
{
Axwindowsmediaplayer1.url = This. playlist. items [playlist. selectedindex + 1]. tostring ();
// Axwindowsmediaplayer1.url = (playlist. selectedvalue + 1). tostring ();
This. Text = "my player" + playlist. items [playlist. selectedindex + 1]. tostring ();
This. playlist. selectedindex + = 1;
}
Else
{
// The last song. The next song starts from the first song.
Axwindowsmediaplayer1.url = This. playlist. items [0]. tostring ();
This. Text = "my player" + playlist. items [0]. tostring ();
}
}
// Automatic playback
// Record the current status
Int state =-1;
Private void timereffectick (Object sender, eventargs E)
{
If (axwindowsmediaplayer1.playstate = wmplib. wmpplaystate. wmppsstopped)
{
If (State = 0)
{
// Single Loop
This. axwindowsmediaplayer1.url = This. playlist. items [This. playlist. selectedindex]. tostring ();
This. Text = "my player" + playlist. items [playlist. selectedindex]. tostring ();
}
Else if (State = 1)
{
// Unordered playback
Random RD = new random ();
Int random = RD. Next (0, this. playlist. Items. Count-1 );
This. axwindowsmediaplayer1.url = This. playlist. items [random]. tostring ();
This. playlist. selectedindex = random;
This. Text = "my player" + playlist. items [random]. tostring ();
}
Else
{
// Automatic playback and list Loop
Next ();
}
}< br>
}< br> // single loop
private void btnloop_click (Object sender, eventargs E)
{< br> state = 0;
}
// List Loop
Private void btnlistloop_click (Object sender, eventargs E)
{
State = 2;
}
// Unordered playback
Private void btnwuxu_click (Object sender, eventargs E)
{
State = 1;
}
}
}