Introduction
Here we are going to create a sound player called “MultiPlayer” which is able to play all audio format files and some video format files also that’s why it’s called “Multiplayer”
And the most important thing about this player is simple programmig of c-# and a simple user interface provide better interactivity of users
A “Time” showing fesility which shows time in Minutes and seconds of playing files some buttons which provide better commands for using this player.
Download the whole project from here :
Programming
Here I import two.dll for playing these audio and video files
1- Interop.Shell32.dll
2- Interop.WMPLib.dll
I have commented the whole program which helps to understand it.
So now the time for programming:
Here is the program of c#___
//These Namespace which are to be used in this program
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
// ^_^–^_^–^_^–READ CAREFULLY
// COMMENTS _^_^_———_^_^_—– @
namespace MP3_PLAYER
{
public partial class Form1 : Form
{
private int masterVolumn;
int sec;
int min;
string Command;
// Here the 128 is the default pitch of
StringBuilder sb = new StringBuilder(128);
// Here the simple method to import the Dll file of the wimdows media player for all systems…
[DllImport("winmm.dll")]
//You can’t use any other word in place of
// mciSendString because this is imported from winmm.dll …
// You can’t change the sequence of this initialization (_______)…if u will change this will show the error(s)…
public static extern long mciSendString(string rCommand, StringBuilder rReturn, int back, int length);
public Form1()
{
InitializeComponent();
//this.MasterVolume=5*100;
}
// This is the mouseover event for the browse button this is used for change the size
// of the button dynamically. . .
private void BTBROWSE_MouseMove(object sender, MouseEventArgs e)
{
BTBROWSE.Width = 115;
BTBROWSE.Height = 40;
BTBROWSE.BackColor = Color.Red;
BTBROWSE.ForeColor = Color.DarkTurquoise;
}
// This is a leave event for the browse button
// this will return the size of the button when u leave the button …
private void BTBROWSE_MouseLeave(object sender, EventArgs e)
{
BTBROWSE.Width = 110;
BTBROWSE.Height = 23;
BTBROWSE.BackColor = Color.Transparent;
BTBROWSE.ForeColor = Color.Black;
}
private void BTPLAY_MouseMove(object sender, MouseEventArgs e)
{
BTPLAY.Width = 115;
BTPLAY.Height = 40;
BTPLAY.BackColor = Color.Red;
BTPLAY.ForeColor = Color.DarkTurquoise;
}
private void BTPLAY_MouseLeave(object sender, EventArgs e)
{
BTPLAY.Width = 110;
BTPLAY.Height = 23;
BTPLAY.BackColor = Color.Transparent;
BTPLAY.ForeColor = Color.Black;
}
private void BTPAUSE_MouseMove(object sender, MouseEventArgs e)
{
BTPAUSE.Width = 115;
BTPAUSE.Height = 40;
BTPAUSE.BackColor = Color.Red;
BTPAUSE.ForeColor = Color.DarkTurquoise;
}
private void BTPAUSE_MouseLeave(object sender, EventArgs e)
{
BTPAUSE.Width = 110;
BTPAUSE.Height = 23;
BTPAUSE.BackColor = Color.Transparent;
BTPAUSE.ForeColor = Color.Black;
}
private void BTCLOSE_MouseMove(object sender, MouseEventArgs e)
{
BTCLOSE.Width = 115;
BTCLOSE.Height = 40;
BTCLOSE.BackColor = Color.Red;
BTCLOSE.ForeColor = Color.DarkTurquoise;
}
private void BTCLOSE_MouseLeave(object sender, EventArgs e)
{
BTCLOSE.Width = 110;
BTCLOSE.Height = 23;
BTCLOSE.BackColor = Color.Transparent;
BTCLOSE.ForeColor = Color.Black;
}
private void BTCLOSE_Click(object sender, EventArgs e)
{
System.Windows.Forms.DialogResult answer;
{
answer = MessageBox.Show(”Do You Really Want To Exit ? “, “Exit”, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (answer == System.Windows.Forms.DialogResult.No)
{
return;
}
else
{
Application.Exit();
}
}
}
private void button1_Click(object sender, EventArgs e)
{
About frmobj = new About();
frmobj.Show();
}
// this is used to browse your mp3 files …
private void BTBROWSE_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = “Mp3 [.mp3] files |*.mp3|Movie [.avi] files|*.avi|Video [3GP] files|*.3GP|WAV [.wav] files|*.wav|DAT [.DAT] files|*.dat “;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
path.Text = openFileDialog1.FileName;
Command = “close Mp3File”;
mciSendString(Command, null, 0, 0);
timer1.Enabled = false;
Command = “open ” + “\”" + openFileDialog1.FileName + “\”" + ” type MPEGVideo alias Mp3File”;
mciSendString(Command, null, 0, 0);
}
}
// this is used to play your mp3 files…
private void BTPLAY_Click(object sender, EventArgs e)
{
if (openFileDialog1.FileName == “”)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
openFileDialog1.Filter = “Mp3 [.mp3] files |*.mp3|Movie [.avi] files|*.avi|Video [3GP] files|*.3GP|WAV [.wav] files|*.wav|DAT [.DAT] files|*.dat “;
//openFileDialog1.Filter = “JPEG Files|*.jpg|GIF Files|*.gif”;
Command = “open ” + “\”" + openFileDialog1.FileName + “\”" + ” type MPEGVideo alias Mp3File”;
mciSendString(Command, null, 0, 0);
Command = “play Mp3File”;
mciSendString(Command, null, 0, 0);
timer1.Enabled = true;
this.MasterVolume = this.MasterVolume;
}
}
else
{
Command = “play Mp3File”;
mciSendString(Command, null, 0, 0);
timer1.Enabled = true;
}
}
// this is used to pause your mp3 file and it will play the file from the paused time…
private void BTPAUSE_Click(object sender, EventArgs e)
{
Command = “pause mp3file”;
mciSendString(Command, null, 0, 0);
}
// this is used to show the time of mp3 file …
private void timer1_Tick(object sender, EventArgs e)
{
Command = “Status Mp3File position”;
mciSendString(Command, sb, 128, 0);
sec = int.Parse(sb.ToString());
sec = sec / 1000;
min = sec / 60;
sec = sec % 60;
ltime.Text = min.ToString(” 00 “) + “~” + sec.ToString(” 00 “);
}
// this will change the text box readonly , anybody can’t change the text at runtime …
private void Form1_Load(object sender, EventArgs e)
{
path.ReadOnly = true;
MasterVolume = masterVolume.Value * 100;
}
private void picprevw_MouseMove(object sender, MouseEventArgs e)
{
picprevw.Width = 130;
picprevw.Height = 40;
picprevw.BackColor = Color.Red;
picprevw.ForeColor = Color.DarkTurquoise;
}
private void picprevw_MouseLeave(object sender, EventArgs e)
{
picprevw.Width = 136;
picprevw.Height = 23;
picprevw.BackColor = Color.Transparent;
picprevw.ForeColor = Color.Black;
}
private void picprevw_Click(object sender, EventArgs e)
{
Picture_Preview frmobj = new Picture_Preview();
frmobj.Show();
}
public int MasterVolume
{
get
{
return masterVolumn; //Guess could be used to return Volume level: I don’t need it
}
set
{
mciSendString(string.Concat(”setaudio MediaFile volume to “, value), null, 0, 0);
masterVolumn = value;
}
}
private void masterVolume_Scroll(object sender, EventArgs e)
{
MasterVolume = masterVolume.Value * 100;
}
}
}
Here is the interface of Multiplayer

For further help contact me:
Keep reading…
Thanks
Nikhil Kumar