Click here to Skip to main content
Click here to Skip to main content

Media Player With MCI

, 15 Feb 2011
Rate this:
Please Sign up or sign in to vote.
A media player with winmm.DLL (MCI). Includes radio, search playlist, nd line up playlist (optional) features.

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. Smile | :)

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:

[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)

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)

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 Wink | ;)

License

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

About the Author

SercanOzdemir
Team Leader Eterne
Turkey Turkey
No Biography provided
Follow on   Twitter   Google+   LinkedIn

Comments and Discussions

 
Questionmy vote of 4 PinmemberMember 392526414-Feb-12 3:07 
AnswerRe: my vote of 4 PinmemberSercanOzdemir14-Feb-12 21:03 

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

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

| Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 15 Feb 2011
Article Copyright 2011 by SercanOzdemir
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid