Create Music Player App using C Sharp (C#) Programming Language |
In this tutorial, we'll create a simple music player app in Microsoft Visual Studio using C# (C sharp) Programming language.
The App will be able to
1. Create playlists
2. And play songs based on the selection of the song in playlist
Music Player App Design
The final design of our app will look as followsMusic Player App Design in Visual Studio |
1. Header [Top Bar]
In this section, a panel was added from the tool box. Then a label as a logo and a close icon was added on top of it.Follow the steps below to create header
a. Go to the toolbox
b. Search for panel and drag into the form
c. Then select the panel and go to properties and look for dock properties, select top position here.
d. Now adjust the size as per your requirement.
e. You can also change background color from properties tab.
f. Now you can drag a label in your top bar and change its font properties (size, type, etc.)
g. on the right top, a picture box was added and a close icon was selected on it.
2. Main Content [Center]
This section contains two parts i.e. Left part with windows media player components and Right part with song select button and track list section.Right Part
Here, A window media player component was added. To get this componenet
a. Go to the tool box and Right click and and then select Choose Items
b. A panel will pop up, Go to COM components here
c. Search for Windows Media Player (usually at the bottom).
d. Check the Windows Medial Player and click on OK
e. Now, You will see Windows Media Player in your Tool Box.
f. Just Drag it to your form.
Left Part
Here, a list box was dragged from the toolbox to display the list of selected songs.
And a button was added at the bottom of the list box to select the songs.
3. Footer
Footer contains a label with the name of a developer.Coding the App
On the top, two global variables of string type array were created as follows
//Create Global Variables of String Type Array to save the titles or name of the //Tracks and path of the track
String[] paths, files;
First, button clicked event was created on close icon, so that the app would be closed when the close icon is clicked.
To create the event, just double click on the icon. And the code to close the app is as follows
private void pictureBox1_Click(object sender, EventArgs e)
{
//Code to Close the App
this.Close();
}
Second, Button clicked event was created to select the songs. For this, Select Button was double clicked and the event was created.
private void btnSelectSongs_Click(object sender, EventArgs e)
{
//Code to SElect Songs
OpenFileDialog ofd = new OpenFileDialog();
//Code to select multiple files
ofd.Multiselect = true;
if(ofd.ShowDialog()==System.Windows.Forms.DialogResult.OK)
{
files = ofd.SafeFileNames; //Save the names of the track in files array
paths = ofd.FileNames; //Save the paths of the tracks in path array
//Display the music titles in listbox
for (int i = 0; i < files.Length; i++)
{
listBoxSongs.Items.Add(files[i]); //Display Songs in Listbox
}
}
}
Third, Selected Index Change Event was created by double clicking on list box, to play the music. And the code to play the song with this event is as follows
private void listBoxSongs_SelectedIndexChanged(object sender, EventArgs e)
{ //Write a code to play music
axWindowsMediaPlayerMusic.URL = paths[listBoxSongs.SelectedIndex];
}
You can also watch the video tutorial here
Download Code [button_primary]
Donate
If the project was helpful to you and want to support me to create more free projects and free courses, then consider donating from the links (button) below.
PayPal[button_primary] Buy Me a Coffee ☕️[button_warning] Patreon[button_dark]
Also Check Other Software Development Courses & Projects [ Free ]
1. Create a Billing System with C#
2. Software Development for Beginners (Create e-Contact App)
3. Create a Blood Bank Management System with C#
4. Bug Tracking Application with C#
Comments
give us the source code
ReplyDelete