Click here to Skip to main content
15,881,413 members
Articles / Programming Languages / C#

Media Player With MCI

Rate me:
Please Sign up or sign in to vote.
4.23/5 (10 votes)
15 Feb 2011CPOL2 min read 40.7K   4.1K   17   7
A media player with winmm.DLL (MCI). Includes radio, search playlist, nd line up playlist (optional) features.

Image 1

Introduction

This article is about MCISENDSTRING and winmm.dll. I use them to play media files and this is a good sample about playing media files. I know you can find a lot of examples about MCI but not like this one. This sample project has a radio selection and you can edit it however you desire by adding radio URLs. I will improve its interface and will handle its bugs as and when I get time.

To find songs, use 'CTRL+F'. You can sort your playlist with 'CTRL+S' and play your order with 'S' or clean up your order with 'SHIFT+S'. In the 'Görsel Öğe' tab you can see the MP3 tags, media file length (-/+), your playlist's length (in minutes), and you can specify your interface by selecting the background and foreground colours. In the 'Seçenekler' tab, and you can choose how you want to listen to songs (random, repeat single song, repeat playlist, loop (at the end of the playlist)). And in this tab, you can save your list and in one click, you can get it all the time (see the listbox on the right). And of course, the radio section, I want you to explore it. :)

This solution helps you to learn MCISENDSTRING commands, and you should look at 'Player.cs'. Also, you can look in the 'Registry' region to learn the Regedit entries using C#, the 'Zaman' region to learn about MCI time commands like 'status media length', the 'MP3 ID3v1' region to learn about an MP3's ID3v1 information like 'Artist', 'Year', and the other regions to examine other functions in 'Player.cs'.

You can use any of my code parts in your projects. It will help you to learn about MCI , because almost all of code parts have explanations.

Using the code

Firs of all, we need the Player class to play media files because it has MCI commands in functions. The content is explained at the top. In the Mp3PLayer (Main Form) constructor, there are some similarities because almost all of the component functions are in Player.cs. The main similarity is Player muzik=new Player();. This is important. In the 'DragDrop' region, you can learn about drag drop (Desktop to WinForms, directory to WinForms, file to WinForms). Also, for interface changes like colour changes, look in the 'Skins' region.

Global variables and importing winmm.DLL:

C#
[DllImport("winmm.dll")] 
private static extern long mciSendString(string strKomut, 
        StringBuilder strDonenDeger, int mediaUzunluk, IntPtr hwndCallback);
//And I Used it in Functions
//It is a classic API using.

Time functions: The Open function is in 'Player.cs' is used to open media files to play with the MCI command strings.

SarkiUzunlukMiliSaniye(int sira)

C#
Open(lst.Items[sira].SubItems[1].Text);
komut = "status Sarki length";
mciSendString(komut, donendeger, donendeger.Capacity, IntPtr.Zero); //Media File LENGTH!
return Convert.ToInt32(donendeger.ToString());

Button press events: trcsarkiyer2 is a scrollbar to follow the media status and SarkiUzunlukMilisaniye is a 'status media file' function.

Play(int sira)

C#
Stop();
Open(lst.Items[sira].SubItems[1].Text); //Other Function Of MCI
trcsarkiyer2.Maximum = SarkiUzunlukMiliSaniye(sira); //ScrollBar For Position And Length
komut = "play Sarki";
mciSendString(komut, null, 0, IntPtr.Zero);
play = true;

History

This is my first article. This app might contain bugs. It is only intended as a learning tool. Happy coding ;)

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Team Leader
Turkey Turkey
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 1 Pin
FernandoUY20-Jun-12 5:25
professionalFernandoUY20-Jun-12 5:25 
GeneralRe: My vote of 1 Pin
SercanOzdemir20-Jun-12 9:53
SercanOzdemir20-Jun-12 9:53 
Questionmy vote of 4 Pin
Member 392526414-Feb-12 3:07
Member 392526414-Feb-12 3:07 
AnswerRe: my vote of 4 Pin
SercanOzdemir14-Feb-12 21:03
SercanOzdemir14-Feb-12 21:03 
GeneralMy vote of 5 Pin
Member 78700106-May-11 6:51
Member 78700106-May-11 6:51 
GeneralMy vote of 3 Pin
Bill SerGio, The Infomercial King15-Feb-11 4:21
Bill SerGio, The Infomercial King15-Feb-11 4:21 
Has a dependency not included in code Microsoft.Office.Core
App is very buggy--lots of crashes
GeneralRe: My vote of 3 Pin
SercanOzdemir3-Mar-11 1:40
SercanOzdemir3-Mar-11 1:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.