Audio Player Class With C#

Introduction

I created a class using mciSendString functions to play audio files then compile it to dll file. To use my dll file, please add MediaControl.dll to your project reference then declare an instance as
following:

private MediaControl.AudioPlayer MyPlayer = new MediaControl.AudioPlayer();

img1.jpg

In the following table you can read about some commands of the player as examples.

Command

Explanation

Example

Open

Open music file. (*.mp3, *.ram, *.wav, ...)

MyPlayer.Open(FileName);

Play

Play music file.

MyPlayer.Play();

Pause

Stop the song temporary.

MyPlayer.Pause = true;

Close

Stop playing.

MyPlayer.Close();

Volume

Set and get volume.

MyPlayer.Volume = Value;

Position

Set and get position.

MyPlayer.position = Value;

Duration

Get the duration.

label1.Text = MyPlayer.Duration();

SetAudioOff

Set voice off.

MyPlayer.SetAudioOff();

SetAudioOn

Set voice on.

MyPlayer.SetAudioOn();

After extract the file MyPlayerC.zip You can find MediaControl.dll file in (..\..\MyClass) folder, You can read about commands: Play, Pause, Stop, ... etc. and read the code in my project for using my AudioPlayer class. You can test my project with the file ..\..\Music\M1.mp3 or any audio file and see how using MyPlayer.PositionChanged to make motion without new Timer.