Use the MCI command to create your own media player

Source: Internet
Author: User

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

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.