Music Player Making with C#
In this lesson, I will tell you how to make a simple music player which can play files like mp3, wav, wmv, avi by using Windows Media Player which is the Windows music player of Windows.
First, we are launching a new c # windows form application project.
The design phase of the form
design phase of form: Toolbox does not come with Windows Media Player as standard. We need to add this later. Right-click on an empty area of the Toolbox and click on the Choose Items option.
Then, in the window that opens, point to Com Components, select Windows Media Player, and then say OK.
Added Windows Media Player to Toolbox. You can now use this item when designing the form. I have designed a form as follows.
The operation of the project will be as follows: The user will select any playable file by clicking the Select button and we will need the openFileDialog object. The selected music will be shown in the textbox. The user can control the flow of music with the control keys on Media Player.
Now let’s get to the code. You already have one Button on the project.
public partial class Form1 : Form
private void button1_Click(object sender, EventArgs e)
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "Media File(*.mpg,*.dat,*.avi,*.wmv,*.wav,*.mp3)|*.wav;*.mp3;*.mpg;*.dat;*.avi;*.wmv";
//Müzik çaların çalabileceği dosyaları FileDialog sayesinde filtreledik.
openFileDialog1.InitialDirectory = Application.StartupPath;
openFileDialog1.Title = "Dosya Seç";
textBox1.Text = openFileDialog1.FileName;
//Seçilen dosyanın ismini TextBox içerisine aktardık.
axWindowsMediaPlayer1.URL = textBox1.Text;
If the music starts playing automatically, the operation is complete. If you want to interfere with the code yourself, you can use the following code.
If you already have a bit more Media Player, you will find that it has very different and useful elements.
MP3 and Audio File Playback with C#
Of course, to use the WMPLib library, you need to add Windows Media Player to the Reference.
I’ve made a simple music player with C #. Now you can play your mp3 and audio files, play your video files.
if you have question do not forget to write from the chat button next to it or from the comment