Use the MCI command to create your own media player
Zhou yinhui, level 03 software College, University of Electronic Science and Technology
Reprinted please indicate the source
1. Description:
Online micArticleA lot of articles, but most of them are a big copy. Here we will talk about how to use it as a player in C.
2. how to send commands:
///
// send the MCI command
///
/// command to be sent
/// return string
// buffer size
// callback. Generally set to 0
//
[dllimport ("winmm. DLL ", entrypoint =" mcisendstring ", charset = charset. auto)]
Public static extern int mcisendstring (string command, string returnstring,
int returnlength, int hwndcallback );
the command parameter here is the command we want to send
in the future, we will use this mcisendstring function to send commands for Media Operations
3. What are commands?
It is simpler than SQL statements. For example, if our music file is Path = "C: \ myaudio", we need to send a command to open the file so that it can be played later, then our command is command = "open \" "+ path +" \ "" + "alias Song". Note that the path must be enclosed by quotation marks, this indicates that it is a parameter (similar to the command line parameter), alias is an alias, we will
"C: \ myplugin" gets an alias called song, so that we can operate on Song later.
4. The simplest option is to enable-> play-> disable
/// <Summary>
/// Open the specified music file
/// The alias is song.
/// </Summary>
/// <Param name = "path"> complete file path </param>
Public void open (string path)
{
If (! File. exists (PATH ))
{
MessageBox. Show ("the file does not exist \ n" + path );
Return;
}
Mciplayer. mcisendstring ("close all", "", 0, 0 );
Mciplayer. mcisendstring ("open \" "+ path +" \ "" + "alias song", "", 0, 0 );
}
/// <Summary>
/// Play the mciplayer. Open file from the beginning. Make sure that the file has been opened.
/// </Summary>
Public void play ()
{
Mciplayer. mcisendstring ("play song", "", 0, 0 );
}
/// <Summary>
/// Stop playing
/// </Summary>
Public void stop ()
{
Mciplayer. mcisendstring ("Stop song", "", 0, 0 );
Mciplayer. mcisendstring ("Close song", "", 0, 0 );
}
5. More
There are a lot of MCI commands, including video control, which can be said to be complex, but fortunately you can not use the filter in msdn, you can enter the MCI command strings in the index to query the relevant information.
This is a simple player that I made (supports videos)
If you need source code, you can email: yinhui_zhou@yahoo.com.cn