Environment:
Visual Studio 2012,sql Server
- vs toolbar to add the Player control, follow these steps:
Open toolbar → Select any control right click → select "Select items ..." To open → select "COM components" → find "Windows Media Player" tick check box → Click OK
- Add the Windows Media Player control to the main interface, modify the property name, and then build the playback interface to complete
Main:
Open the previously written program to the song Add Interface ():
When you click on a song, add the song to the Cellclick event in the Datagirdview control to the well-defined array of objects, with the following code:
Here, Songtype is judged because a form is shared in both the point list and the song list interface, but not if the shared form is not required, and dgv_list. Selectedrows[0]. Cells[""] is the value of the first row of the selected rowset (that is, the subscript 0), a string conversion, and finally assigns the value of each item to the corresponding item in the object array, and calls the previously defined method (such as) to get the song that needs to be played, Since this method needs to get a song object, you need to give him an object parameter when calling the method
At this point, you need to add a timer control to the main interface, in his tick event to determine whether the song object is empty, if it is empty call the Playsong method () to play
To call the method that plays the current song
If the current song object is not empty, then the player is also determined to be in a stopped state, and if it stops, it plays the next song ()
When calling the MoveNext method, you need to determine whether the subscript plus one of the array object is empty, in other words, is to determine if there is still the next song, if you let the index of the array plus one, to play the next song, it should be noted here, if you have started to play the next song, So is it time to erase the last song information, because if you do not do the cleanup, then his object array will always keep the previous song, that is, "song==null" This condition has been false, it will not automatically play the next song, so it is necessary to force the value of his song object to null So that the next song will be played automatically under the Timer control's auto-refresh.
In fact, the main thing in this process is to get the URL address of the song that needs to be played, so when it comes time to get the Datagirdview control, get the URL address of the song, hide it in the object array, and then call it back in the method of playing the current song.
Song Playback interface principle